Expose JsonObject size.
This commit is contained in:
parent
ebad966efd
commit
c16be41e77
@ -132,6 +132,15 @@ public final class JsonObject extends JsonElement {
|
|||||||
return members.entrySet();
|
return members.entrySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of key/value pairs in the object.
|
||||||
|
*
|
||||||
|
* @return the number of key/value pairs in the object.
|
||||||
|
*/
|
||||||
|
public int size() {
|
||||||
|
return members.size();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to check if a member with the specified name is present in this object.
|
* Convenience method to check if a member with the specified name is present in this object.
|
||||||
*
|
*
|
||||||
|
@ -158,6 +158,20 @@ public class JsonObjectTest extends TestCase {
|
|||||||
assertFalse(b.equals(a));
|
assertFalse(b.equals(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSize() {
|
||||||
|
JsonObject o = new JsonObject();
|
||||||
|
assertEquals(0, o.size());
|
||||||
|
|
||||||
|
o.add("Hello", new JsonPrimitive(1));
|
||||||
|
assertEquals(1, o.size());
|
||||||
|
|
||||||
|
o.add("Hi", new JsonPrimitive(1));
|
||||||
|
assertEquals(2, o.size());
|
||||||
|
|
||||||
|
o.remove("Hello");
|
||||||
|
assertEquals(1, o.size());
|
||||||
|
}
|
||||||
|
|
||||||
public void testDeepCopy() {
|
public void testDeepCopy() {
|
||||||
JsonObject original = new JsonObject();
|
JsonObject original = new JsonObject();
|
||||||
JsonArray firstEntry = new JsonArray();
|
JsonArray firstEntry = new JsonArray();
|
||||||
|
Loading…
Reference in New Issue
Block a user