Changeset 23191 in osm for applications/editors/josm/plugins/livegps/src/org
- Timestamp:
- 2010-09-15T18:56:19+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/livegps/src/org/json
- Files:
-
- 5 edited
-
JSONArray.java (modified) (5 diffs)
-
JSONException.java (modified) (1 diff)
-
JSONObject.java (modified) (15 diffs)
-
JSONString.java (modified) (1 diff)
-
JSONTokener.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/org/json/JSONArray.java
r21622 r23191 74 74 * <li>Values can be separated by <code>;</code> <small>(semicolon)</small> as 75 75 * well as by <code>,</code> <small>(comma)</small>.</li> 76 * <li>Numbers may have the 76 * <li>Numbers may have the 77 77 * <code>0x-</code> <small>(hex)</small> prefix.</li> 78 78 * </ul> … … 164 164 */ 165 165 public JSONArray(Collection collection) { 166 this.myArrayList = new ArrayList();167 if (collection != null) {168 Iterator iter = collection.iterator();169 while (iter.hasNext()) {170 Object o = iter.next();171 this.myArrayList.add(JSONObject.wrap(o)); 172 }173 }174 } 175 176 166 this.myArrayList = new ArrayList(); 167 if (collection != null) { 168 Iterator iter = collection.iterator(); 169 while (iter.hasNext()) { 170 Object o = iter.next(); 171 this.myArrayList.add(JSONObject.wrap(o)); 172 } 173 } 174 } 175 176 177 177 /** 178 178 * Construct a JSONArray from an array … … 192 192 } 193 193 194 194 195 195 /** 196 196 * Get the object value associated with an index. … … 765 765 return this; 766 766 } 767 768 767 768 769 769 /** 770 770 * Remove an index and close the hole. … … 774 774 */ 775 775 public Object remove(int index) { 776 Object o = opt(index);776 Object o = opt(index); 777 777 this.myArrayList.remove(index); 778 778 return o; -
applications/editors/josm/plugins/livegps/src/org/json/JSONException.java
r21622 r23191 8 8 public class JSONException extends Exception { 9 9 /** 10 *11 */12 private static final long serialVersionUID = 0;13 private Throwable cause;10 * 11 */ 12 private static final long serialVersionUID = 0; 13 private Throwable cause; 14 14 15 15 /** -
applications/editors/josm/plugins/livegps/src/org/json/JSONObject.java
r21622 r23191 155 155 * @param jo A JSONObject. 156 156 * @param names An array of strings. 157 * @throws JSONException 157 * @throws JSONException 158 158 * @exception JSONException If a value is a non-finite number or if a name is duplicated. 159 159 */ … … 161 161 this(); 162 162 for (int i = 0; i < names.length; i += 1) { 163 try {164 putOnce(names[i], jo.opt(names[i]));165 } catch (Exception ignore) {166 }163 try { 164 putOnce(names[i], jo.opt(names[i])); 165 } catch (Exception ignore) { 166 } 167 167 } 168 168 } … … 235 235 * @param map A map object that can be used to initialize the contents of 236 236 * the JSONObject. 237 * @throws JSONException 237 * @throws JSONException 238 238 */ 239 239 public JSONObject(Map map) { … … 455 455 456 456 /** 457 * Get the int value associated with a key. 457 * Get the int value associated with a key. 458 458 * 459 459 * @param key A key string. … … 512 512 513 513 /** 514 * Get the long value associated with a key. 514 * Get the long value associated with a key. 515 515 * 516 516 * @param key A key string. … … 596 596 return this.map.containsKey(key); 597 597 } 598 599 598 599 600 600 /** 601 601 * Increment a property of a JSONObject. If there is no such property, … … 608 608 */ 609 609 public JSONObject increment(String key) throws JSONException { 610 Object value = opt(key);611 if (value == null) {612 put(key, 1);613 } else {614 if (value instanceof Integer) {615 put(key, ((Integer)value).intValue() + 1);616 } else if (value instanceof Long) {617 put(key, ((Long)value).longValue() + 1);618 } else if (value instanceof Double) {619 put(key, ((Double)value).doubleValue() + 1);620 } else if (value instanceof Float) {621 put(key, ((Float)value).floatValue() + 1);622 } else {623 throw new JSONException("Unable to increment [" + key + "].");624 }625 }626 return this;610 Object value = opt(key); 611 if (value == null) { 612 put(key, 1); 613 } else { 614 if (value instanceof Integer) { 615 put(key, ((Integer)value).intValue() + 1); 616 } else if (value instanceof Long) { 617 put(key, ((Long)value).longValue() + 1); 618 } else if (value instanceof Double) { 619 put(key, ((Double)value).doubleValue() + 1); 620 } else if (value instanceof Float) { 621 put(key, ((Float)value).floatValue() + 1); 622 } else { 623 throw new JSONException("Unable to increment [" + key + "]."); 624 } 625 } 626 return this; 627 627 } 628 628 … … 903 903 Class klass = bean.getClass(); 904 904 905 // If klass is a System class then set includeSuperClass to false. 905 // If klass is a System class then set includeSuperClass to false. 906 906 907 907 boolean includeSuperClass = klass.getClassLoader() != null; … … 916 916 String key = ""; 917 917 if (name.startsWith("get")) { 918 if (name.equals("getClass") ||919 name.equals("getDeclaringClass")) {920 key = "";921 } else {922 key = name.substring(3);923 }918 if (name.equals("getClass") || 919 name.equals("getDeclaringClass")) { 920 key = ""; 921 } else { 922 key = name.substring(3); 923 } 924 924 } else if (name.startsWith("is")) { 925 925 key = name.substring(2); … … 1199 1199 1200 1200 /* 1201 * If it might be a number, try converting it. 1202 * We support the non-standard 0x- convention. 1201 * If it might be a number, try converting it. 1202 * We support the non-standard 0x- convention. 1203 1203 * If a number cannot be produced, then the value will just 1204 1204 * be a string. Note that the 0x-, plus, and implied string … … 1217 1217 } 1218 1218 try { 1219 if (s.indexOf('.') > -1 || 1220 s.indexOf('e') > -1 || s.indexOf('E') > -1) {1219 if (s.indexOf('.') > -1 || 1220 s.indexOf('e') > -1 || s.indexOf('E') > -1) { 1221 1221 return Double.valueOf(s); 1222 1222 } else { … … 1495 1495 1496 1496 /** 1497 * Wrap an object, if necessary. If the object is null, return the NULL 1498 * object. If it is an array or collection, wrap it in a JSONArray. If 1499 * it is a map, wrap it in a JSONObject. If it is a standard property 1500 * (Double, String, et al) then it is already wrapped. Otherwise, if it 1501 * comes from one of the java packages, turn it into a string. And if 1497 * Wrap an object, if necessary. If the object is null, return the NULL 1498 * object. If it is an array or collection, wrap it in a JSONArray. If 1499 * it is a map, wrap it in a JSONObject. If it is a standard property 1500 * (Double, String, et al) then it is already wrapped. Otherwise, if it 1501 * comes from one of the java packages, turn it into a string. And if 1502 1502 * it doesn't, try to wrap it in a JSONObject. If the wrapping fails, 1503 1503 * then null is returned. … … 1511 1511 return NULL; 1512 1512 } 1513 if (object instanceof JSONObject || object instanceof JSONArray || 1514 NULL.equals(object) || object instanceof JSONString ||1515 object instanceof Byte || object instanceof Character ||1513 if (object instanceof JSONObject || object instanceof JSONArray || 1514 NULL.equals(object) || object instanceof JSONString || 1515 object instanceof Byte || object instanceof Character || 1516 1516 object instanceof Short || object instanceof Integer || 1517 object instanceof Long || object instanceof Boolean || 1517 object instanceof Long || object instanceof Boolean || 1518 1518 object instanceof Float || object instanceof Double || 1519 1519 object instanceof String) { 1520 1520 return object; 1521 1521 } 1522 1522 1523 1523 if (object instanceof Collection) { 1524 1524 return new JSONArray((Collection)object); … … 1533 1533 String objectPackageName = ( objectPackage != null ? objectPackage.getName() : "" ); 1534 1534 if (objectPackageName.startsWith("java.") || 1535 objectPackageName.startsWith("javax.") ||1536 object.getClass().getClassLoader() == null) {1535 objectPackageName.startsWith("javax.") || 1536 object.getClass().getClassLoader() == null) { 1537 1537 return object.toString(); 1538 1538 } … … 1543 1543 } 1544 1544 1545 1545 1546 1546 /** 1547 1547 * Write the contents of the JSONObject as JSON text to a writer. -
applications/editors/josm/plugins/livegps/src/org/json/JSONString.java
r21622 r23191 9 9 */ 10 10 public interface JSONString { 11 /**12 * The <code>toJSONString</code> method allows a class to produce its own JSON13 * serialization.14 *15 * @return A strictly syntactically correct JSON text.16 */17 public String toJSONString();11 /** 12 * The <code>toJSONString</code> method allows a class to produce its own JSON 13 * serialization. 14 * 15 * @return A strictly syntactically correct JSON text. 16 */ 17 public String toJSONString(); 18 18 } -
applications/editors/josm/plugins/livegps/src/org/json/JSONTokener.java
r21622 r23191 39 39 public class JSONTokener { 40 40 41 private int character;42 private boolean eof;43 private int index;44 private int line;45 private char previous;46 private Reader reader;41 private int character; 42 private boolean eof; 43 private int index; 44 private int line; 45 private char previous; 46 private Reader reader; 47 47 private boolean usePrevious; 48 48 … … 54 54 */ 55 55 public JSONTokener(Reader reader) { 56 this.reader = reader.markSupported() ? 57 reader : new BufferedReader(reader);56 this.reader = reader.markSupported() ? 57 reader : new BufferedReader(reader); 58 58 this.eof = false; 59 59 this.usePrevious = false; … … 109 109 return -1; 110 110 } 111 111 112 112 public boolean end() { 113 return eof && !usePrevious;113 return eof && !usePrevious; 114 114 } 115 115 … … 124 124 if (end()) { 125 125 return false; 126 } 126 } 127 127 back(); 128 128 return true; … … 138 138 int c; 139 139 if (this.usePrevious) { 140 this.usePrevious = false;140 this.usePrevious = false; 141 141 c = this.previous; 142 142 } else { 143 try {144 c = this.reader.read();145 } catch (IOException exception) {146 throw new JSONException(exception);147 }148 149 if (c <= 0) { // End of stream150 this.eof = true;151 c = 0;152 }153 } 154 this.index += 1;155 if (this.previous == '\r') {156 this.line += 1;157 this.character = c == '\n' ? 0 : 1;158 } else if (c == '\n') {159 this.line += 1;160 this.character = 0;161 } else {162 this.character += 1;163 }164 this.previous = (char) c;143 try { 144 c = this.reader.read(); 145 } catch (IOException exception) { 146 throw new JSONException(exception); 147 } 148 149 if (c <= 0) { // End of stream 150 this.eof = true; 151 c = 0; 152 } 153 } 154 this.index += 1; 155 if (this.previous == '\r') { 156 this.line += 1; 157 this.character = c == '\n' ? 0 : 1; 158 } else if (c == '\n') { 159 this.line += 1; 160 this.character = 0; 161 } else { 162 this.character += 1; 163 } 164 this.previous = (char) c; 165 165 return this.previous; 166 166 } … … 204 204 buffer[pos] = next(); 205 205 if (end()) { 206 throw syntaxError("Substring bounds error"); 206 throw syntaxError("Substring bounds error"); 207 207 } 208 208 pos += 1; … … 273 273 case '\\': 274 274 case '/': 275 sb.append(c);276 break;275 sb.append(c); 276 break; 277 277 default: 278 278 throw syntaxError("Illegal escape."); … … 412 412 return c; 413 413 } 414 414 415 415 416 416 /**
Note:
See TracChangeset
for help on using the changeset viewer.
