Skip to content

Commit 3858559

Browse files
authored
Merge pull request #125 from Esri/stolstov/jsonenum_fix
don't use JSONObject.getNames for Android
2 parents 6e4340a + 0b58f1d commit 3858559

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/main/java/com/esri/core/geometry/JSONObjectEnumerator.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,58 +23,58 @@
2323
*/
2424
package com.esri.core.geometry;
2525

26-
import java.util.ArrayList;
27-
import org.codehaus.jackson.JsonParser;
28-
import org.codehaus.jackson.JsonToken;
29-
import org.json.JSONArray;
3026
import org.json.JSONObject;
3127

28+
import java.util.Iterator;
29+
3230
final class JSONObjectEnumerator {
3331

3432
private JSONObject m_jsonObject;
35-
private boolean m_bStarted;
36-
private int m_currentIndex;
37-
private String[] m_keys;
33+
private int m_troolean;
34+
private Iterator<?> m_keys_iter;
35+
private String m_current_key;
3836

3937
JSONObjectEnumerator(JSONObject jsonObject) {
40-
m_bStarted = false;
41-
m_currentIndex = -1;
38+
m_troolean = 0;
4239
m_jsonObject = jsonObject;
4340
}
4441

4542
String getCurrentKey() {
46-
if (!m_bStarted) {
47-
throw new GeometryException("invalid call");
48-
}
49-
50-
if (m_currentIndex == m_jsonObject.length()) {
43+
if (m_troolean != 1) {
5144
throw new GeometryException("invalid call");
5245
}
5346

54-
return m_keys[m_currentIndex];
47+
return m_current_key;
5548
}
5649

5750
Object getCurrentObject() {
58-
if (!m_bStarted) {
51+
if (m_troolean != 1) {
5952
throw new GeometryException("invalid call");
6053
}
6154

62-
if (m_currentIndex == m_jsonObject.length()) {
63-
throw new GeometryException("invalid call");
64-
}
65-
66-
return m_jsonObject.opt(m_keys[m_currentIndex]);
55+
return m_jsonObject.opt(m_current_key);
6756
}
6857

6958
boolean next() {
70-
if (!m_bStarted) {
71-
m_currentIndex = 0;
72-
m_keys = JSONObject.getNames(m_jsonObject);
73-
m_bStarted = true;
74-
} else if (m_currentIndex != m_jsonObject.length()) {
75-
m_currentIndex++;
59+
if (m_troolean == 0) {
60+
if (m_jsonObject.length() > 0) {
61+
m_keys_iter = m_jsonObject.keys();
62+
m_troolean = 1;//started
63+
}
64+
else {
65+
m_troolean = -1;//stopped
66+
}
67+
}
68+
69+
if (m_troolean == 1) {//still exploring
70+
if (m_keys_iter.hasNext()) {
71+
m_current_key = (String)m_keys_iter.next();
72+
}
73+
else {
74+
m_troolean = -1; //done
75+
}
7676
}
7777

78-
return m_currentIndex != m_jsonObject.length();
78+
return m_troolean == 1;
7979
}
8080
}

0 commit comments

Comments
 (0)