|
| 1 | +/* |
| 2 | + Copyright 1995-2013 Esri |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +
|
| 16 | + For additional information, contact: |
| 17 | + Environmental Systems Research Institute, Inc. |
| 18 | + Attn: Contracts Dept |
| 19 | + 380 New York Street |
| 20 | + Redlands, California, USA 92373 |
| 21 | +
|
| 22 | + email: contracts@esri.com |
| 23 | + */ |
| 24 | +package com.esri.core.geometry; |
| 25 | + |
| 26 | +import java.util.ArrayList; |
| 27 | +import org.codehaus.jackson.JsonParser; |
| 28 | +import org.codehaus.jackson.JsonToken; |
| 29 | +import org.json.JSONArray; |
| 30 | +import org.json.JSONObject; |
| 31 | + |
| 32 | +final class JSONObjectEnumerator { |
| 33 | + |
| 34 | + private JSONObject m_jsonObject; |
| 35 | + private boolean m_bStarted; |
| 36 | + private int m_currentIndex; |
| 37 | + private String[] m_keys; |
| 38 | + |
| 39 | + JSONObjectEnumerator(JSONObject jsonObject) { |
| 40 | + m_bStarted = false; |
| 41 | + m_currentIndex = -1; |
| 42 | + m_jsonObject = jsonObject; |
| 43 | + } |
| 44 | + |
| 45 | + String getCurrentKey() { |
| 46 | + if (!m_bStarted) { |
| 47 | + throw new GeometryException("invalid call"); |
| 48 | + } |
| 49 | + |
| 50 | + if (m_currentIndex == m_jsonObject.length()) { |
| 51 | + throw new GeometryException("invalid call"); |
| 52 | + } |
| 53 | + |
| 54 | + return m_keys[m_currentIndex]; |
| 55 | + } |
| 56 | + |
| 57 | + Object getCurrentObject() { |
| 58 | + if (!m_bStarted) { |
| 59 | + throw new GeometryException("invalid call"); |
| 60 | + } |
| 61 | + |
| 62 | + if (m_currentIndex == m_jsonObject.length()) { |
| 63 | + throw new GeometryException("invalid call"); |
| 64 | + } |
| 65 | + |
| 66 | + return m_jsonObject.opt(m_keys[m_currentIndex]); |
| 67 | + } |
| 68 | + |
| 69 | + 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++; |
| 76 | + } |
| 77 | + |
| 78 | + return m_currentIndex != m_jsonObject.length(); |
| 79 | + } |
| 80 | +} |
0 commit comments