Add keySet method and test (#942)
This commit is contained in:
parent
5f73666404
commit
4976e420fc
@ -132,6 +132,15 @@ public final class JsonObject extends JsonElement {
|
||||
return members.entrySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of members key values.
|
||||
*
|
||||
* @return a set of member keys as Strings
|
||||
*/
|
||||
public Set<String> keySet() {
|
||||
return members.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of key/value pairs in the object.
|
||||
*
|
||||
|
@ -183,4 +183,19 @@ public class JsonObjectTest extends TestCase {
|
||||
assertEquals(1, original.get("key").getAsJsonArray().size());
|
||||
assertEquals(0, copy.get("key").getAsJsonArray().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* From issue 941
|
||||
*/
|
||||
public void testKeySet() {
|
||||
JsonObject a = new JsonObject();
|
||||
|
||||
a.add("foo", new JsonArray());
|
||||
a.add("bar", new JsonObject());
|
||||
|
||||
assertEquals(2, a.size());
|
||||
assertEquals(2, a.keySet().size());
|
||||
assertTrue(a.keySet().contains("foo"));
|
||||
assertTrue(a.keySet().contains("bar"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user