diff options
author | Narayan Kamath <narayan@google.com> | 2013-12-16 12:50:52 +0000 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2014-01-22 10:54:24 +0000 |
commit | 690809fda4e0822f279f64c35d8775d76212179f (patch) | |
tree | 2ff45d3b4be186a1a7d755e1acab5b9cb117f878 /json | |
parent | 820b07350c07dd54c4d32e5ad979524707416a67 (diff) | |
download | libcore-690809fda4e0822f279f64c35d8775d76212179f.zip libcore-690809fda4e0822f279f64c35d8775d76212179f.tar.gz libcore-690809fda4e0822f279f64c35d8775d76212179f.tar.bz2 |
Add missing JSONObject#keySet API.
Also, add type arguments to the old Iterator API.
Note that this is source incompatible with wrongly generified
code (example: "Iterator<Object> keys = jsonObject.keys();") but
is compatible with old code that didn't use any type arguments.
Users compiling against the new SDK might see compile breakages.
bug: https://code.google.com/p/android/issues/detail?id=63191
Change-Id: Idf2ef1889dccb4309c843ab073f67af648b09436
Diffstat (limited to 'json')
-rw-r--r-- | json/src/main/java/org/json/JSONObject.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/json/src/main/java/org/json/JSONObject.java b/json/src/main/java/org/json/JSONObject.java index da34219..9ea91a6 100644 --- a/json/src/main/java/org/json/JSONObject.java +++ b/json/src/main/java/org/json/JSONObject.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; // Note: this class was written without inspecting the non-free org.json sourcecode. @@ -650,12 +651,25 @@ public class JSONObject { * modified after the iterator is returned, the iterator's behavior is * undefined. The order of the keys is undefined. */ - /* Return a raw type for API compatibility */ - public Iterator keys() { + public Iterator<String> keys() { return nameValuePairs.keySet().iterator(); } /** + * Returns the set of {@code String} names in this object. The returned set + * is a view of the keys in this object. {@link Set#remove(Object)} will remove + * the corresponding mapping from this object and set iterator behaviour + * is undefined if this object is modified after it is returned. + * + * See {@link #keys()}. + * + * @hide. + */ + public Set<String> keySet() { + return nameValuePairs.keySet(); + } + + /** * Returns an array containing the string names in this object. This method * returns null if this object contains no mappings. */ |