@Deprecated public static boolean isValidIndex(Object key) { return (-1 < keyToIndex(key)); }
/** * Insert a value at index (if ref can be converted to one) even if the * array has to be extended (padded by null values). * * @param ref * an object to be converted to an array index * @param value * the value to be inserted * @see #put(int, Object) * @return this object after insertion has been attempted */ @Override public EwJsonArray put(Object ref, Object value) throws JSONException { return this.put(EwJson.keyToIndex(ref), value); }
/** * Insert a value at index (if ref can be converted to one) even if the * array has to be extended (padded by null values). If index is less than * zero or value is null, nothing is done. * * @param ref * an object to be converted to an array index * @param value * a non-null value to be inserted * @see #put(int, Object) * @return this object after insertion has been attempted */ @Override public EwJsonArray putOpt(Object ref, Object value) { return this.putOpt(EwJson.keyToIndex(ref), value); }
/** * Insert a value at index (if ref can be converted to one) even if the * array has to be extended (padded by null values). If the index already * has a value, a {@link JSONException} is thrown. If index is less than * zero or value is null, nothing is done. * * @param ref * an object to be converted to an array index * @param value * a non-null, non-duplicate value to be inserted * @see #put(int, Object) * @see #put(Object, Object) * @return this object after insertion has been attempted */ @Override public EwJsonArray putOnce(Object ref, Object value) throws JSONException { return this.putOnce(EwJson.keyToIndex(ref), value); }
/*** * Calls {@link #opt(Object)} to parse any array keys. */ @Override public Object get(Object ref) throws JSONException { Object object; try { int keyToIndex = EwJson.keyToIndex(ref); if (keyToIndex == -1) return null; return super.get(keyToIndex); } catch (JSONException je) { if ((object = this.opt(ref)) == null) throw je; } return object; }
@Deprecated private static Object getElement(Object object, Object ref) { final Object json = tryParseJson(object, true); if (json == null || ref == null) return null; if (json instanceof JSONArray) return ((JSONArray) json).opt(keyToIndex(ref)); if (json instanceof JSONObject) return ((JSONObject) json).opt(ref.toString()); return null; }
@Override public Object opt(Object ref, Object defaultValue) { // Try it the way the parent would do it first final Object object = super.opt(EwJson.keyToIndex(ref)); // If that fails, try parsing ref as a composite key if (object == null && ref instanceof String) try { if (EwJson.isComplexKey(ref)) return EwJson.derefComplexKey(this, (String) ref); } catch (JSONException e) { } return (object == null) ? defaultValue : object; }
final int index = keyToIndex(key);
return ((JSONArray) object).opt(keyToIndex(key));
return into; final int index = EwJson.keyToIndex(ref); final int putDex = (index >= 0) ? index : into.length();