Skip to content

Commit 94a3955

Browse files
committed
refactor(json): drop unused isEmpty() and consolidate redundant fuzz tests
- Delete JSONObject.isEmpty() (no callers in main or test code) - Promote size() and keySet() to canonical position with proper Javadoc; both still required by HttpMethed test util and stay drop-in compatible - Fuzz test consolidation (165 -> 132 methods): * Merge §50 boolean->numeric coercion (5 single-getter tests -> 1) * Drop §52 boxed null-string redundancies (covered by §17/§18) * Trim §28 toJSONString unwrap suite (9 -> 4) * Trim equals tests (Array 8 -> 4, Object 10 -> 4); cover reflexivity, nested, empty and built-vs-parsed inside the SameContent canonical case * Replace .size()/.isEmpty() asserts with containsKey()/toJSONString() where the original assertion was redundant
1 parent 3406145 commit 94a3955

2 files changed

Lines changed: 71 additions & 329 deletions

File tree

common/src/main/java/org/tron/json/JSONObject.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.databind.node.ArrayNode;
66
import com.fasterxml.jackson.databind.node.ObjectNode;
77
import java.math.BigDecimal;
8+
import java.util.Iterator;
89
import java.util.LinkedHashSet;
910
import java.util.List;
1011
import java.util.Set;
@@ -50,6 +51,24 @@ public boolean containsKey(String key) {
5051
return node.has(key);
5152
}
5253

54+
/** Mirrors {@code Map.size()} from fastjson's JSONObject. */
55+
public int size() {
56+
return node.size();
57+
}
58+
59+
/**
60+
* Mirrors {@code Map.keySet()} from fastjson's JSONObject.
61+
* Returns a {@link LinkedHashSet} preserving insertion / parse order.
62+
*/
63+
public Set<String> keySet() {
64+
Set<String> keys = new LinkedHashSet<>(node.size());
65+
Iterator<String> names = node.fieldNames();
66+
while (names.hasNext()) {
67+
keys.add(names.next());
68+
}
69+
return keys;
70+
}
71+
5372
/**
5473
* Returns the string representation of the value for the given key.
5574
* For object/array nodes, returns the JSON text (matching Fastjson behaviour).
@@ -433,20 +452,6 @@ public Object remove(String key) {
433452
return convertNode(removed);
434453
}
435454

436-
public boolean isEmpty() {
437-
return node.isEmpty();
438-
}
439-
440-
public int size() {
441-
return node.size();
442-
}
443-
444-
public Set<String> keySet() {
445-
Set<String> keys = new LinkedHashSet<>();
446-
node.fieldNames().forEachRemaining(keys::add);
447-
return keys;
448-
}
449-
450455
/** Returns the underlying Jackson {@link ObjectNode}. */
451456
@JsonValue
452457
public ObjectNode unwrap() {

0 commit comments

Comments
 (0)