Merge pull request #872 from google/jw/object-size
Expose JsonObject size.
This commit is contained in:
commit
5f63fcec98
@ -132,6 +132,15 @@ public final class JsonObject extends JsonElement {
|
||||
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.
|
||||
*
|
||||
|
@ -158,6 +158,20 @@ public class JsonObjectTest extends TestCase {
|
||||
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() {
|
||||
JsonObject original = new JsonObject();
|
||||
JsonArray firstEntry = new JsonArray();
|
||||
|
Loading…
Reference in New Issue
Block a user