Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7ff3fa4

Browse files
similar
1 parentcdaaf12 commit7ff3fa4

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

‎JSONArray.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ of this software and associated documentation files (the "Software"), to deal
7575
* </ul>
7676
*
7777
* @author JSON.org
78-
* @version 2014-04-18
78+
* @version 2014-04-21
7979
*/
8080
publicclassJSONArray {
8181

@@ -813,11 +813,42 @@ public JSONArray put(int index, Object value) throws JSONException {
813813
* was no value.
814814
*/
815815
publicObjectremove(intindex) {
816-
Objecto =this.opt(index);
817-
if (index >=0 &&index <this.length()) {
818-
this.myArrayList.remove(index);
816+
returnindex >=0 &&index <this.length()
817+
?this.myArrayList.remove(index)
818+
:null;
819+
}
820+
821+
/**
822+
* Determine if two JSONArrays are similar.
823+
* They must contain similar sequences.
824+
*
825+
* @param other The other JSONArray
826+
* @return true if they are equal
827+
*/
828+
publicbooleansimilar(Objectother) {
829+
if (!(otherinstanceofJSONArray)) {
830+
returnfalse;
831+
}
832+
intlen =this.length();
833+
if (len != ((JSONArray)other).length()) {
834+
returnfalse;
835+
}
836+
for (inti =0;i <len;i +=1) {
837+
ObjectvalueThis =this.get(i);
838+
ObjectvalueOther = ((JSONArray)other).get(i);
839+
if (valueThisinstanceofJSONObject) {
840+
if (!((JSONObject)valueThis).similar(valueOther)) {
841+
returnfalse;
842+
}
843+
}elseif (valueThisinstanceofJSONArray) {
844+
if (!((JSONArray)valueThis).similar(valueOther)) {
845+
returnfalse;
846+
}
847+
}elseif (!valueThis.equals(valueOther)) {
848+
returnfalse;
849+
}
819850
}
820-
returno;
851+
returntrue;
821852
}
822853

823854
/**

‎JSONObject.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ of this software and associated documentation files (the "Software"), to deal
9090
* </ul>
9191
*
9292
* @author JSON.org
93-
* @version2013-06-17
93+
* @version2014-04-21
9494
*/
9595
publicclassJSONObject {
9696
/**
@@ -1281,6 +1281,46 @@ public Object remove(String key) {
12811281
returnthis.map.remove(key);
12821282
}
12831283

1284+
/**
1285+
* Determine if two JSONObjects are similar.
1286+
* They must contain the same set of names which must be associated with
1287+
* similar values.
1288+
*
1289+
* @param other The other JSONObject
1290+
* @return true if they are equal
1291+
*/
1292+
publicbooleansimilar(Objectother) {
1293+
try {
1294+
if (!(otherinstanceofJSONObject)) {
1295+
returnfalse;
1296+
}
1297+
Setset =this.keySet();
1298+
if (!set.equals(((JSONObject)other).keySet())) {
1299+
returnfalse;
1300+
}
1301+
Iteratoriterator =set.iterator();
1302+
while (iterator.hasNext()) {
1303+
Stringname = (String)iterator.next();
1304+
ObjectvalueThis =this.get(name);
1305+
ObjectvalueOther = ((JSONObject)other).get(name);
1306+
if (valueThisinstanceofJSONObject) {
1307+
if (!((JSONObject)valueThis).similar(valueOther)) {
1308+
returnfalse;
1309+
}
1310+
}elseif (valueThisinstanceofJSONArray) {
1311+
if (!((JSONArray)valueThis).similar(valueOther)) {
1312+
returnfalse;
1313+
}
1314+
}elseif (!valueThis.equals(valueOther)) {
1315+
returnfalse;
1316+
}
1317+
}
1318+
returntrue;
1319+
}catch (Throwableexception) {
1320+
returnfalse;
1321+
}
1322+
}
1323+
12841324
/**
12851325
* Try to convert a string into a number, boolean, or null. If the string
12861326
* can't be converted, return the string.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp