/** * Get the enum value associated with a key. * * @param clazz * The type of enum to retrieve. * @param index * The index must be between 0 and length() - 1. * @return The enum value at the index location or null if not found */ public <E extends Enum<E>> E optEnum(Class<E> clazz, int index) { return this.optEnum(clazz, index, null); }
/** * Get the enum value associated with an index. * * @param clazz * The type of enum to retrieve. * @param index * The index must be between 0 and length() - 1. * @return The enum value at the index location * @throws JSONException * if the key is not found or if the value cannot be converted * to an enum. */ public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONException { E val = optEnum(clazz, index); if(val==null) { // JSONException should really take a throwable argument. // If it did, I would re-implement this with the Enum.valueOf // method and place any thrown exception in the JSONException throw new JSONException("JSONArray[" + index + "] is not an enum of type " + JSONObject.quote(clazz.getSimpleName()) + "."); } return val; }
/** * Get the enum value associated with a key. * * @param <E> * Enum Type * @param clazz * The type of enum to retrieve. * @param index * The index must be between 0 and length() - 1. * @return The enum value at the index location or null if not found */ public <E extends Enum<E>> E optEnum(Class<E> clazz, int index) { return this.optEnum(clazz, index, null); }
/** * Get the enum value associated with an index. * * @param <E> * Enum Type * @param clazz * The type of enum to retrieve. * @param index * The index must be between 0 and length() - 1. * @return The enum value at the index location * @throws JSONException * if the key is not found or if the value cannot be converted * to an enum. */ public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONException { E val = optEnum(clazz, index); if(val==null) { // JSONException should really take a throwable argument. // If it did, I would re-implement this with the Enum.valueOf // method and place any thrown exception in the JSONException throw new JSONException("JSONArray[" + index + "] is not an enum of type " + JSONObject.quote(clazz.getSimpleName()) + "."); } return val; }
/** * Get the enum value associated with a key. * * @param clazz * The type of enum to retrieve. * @param index * The index must be between 0 and length() - 1. * @return The enum value at the index location or null if not found */ public <E extends Enum<E>> E optEnum(Class<E> clazz, int index) { return this.optEnum(clazz, index, null); }
/** * Get the enum value associated with a key. * * @param <E> * Enum Type * @param clazz * The type of enum to retrieve. * @param index * The index must be between 0 and length() - 1. * @return The enum value at the index location or null if not found */ public <E extends Enum<E>> E optEnum(Class<E> clazz, int index) { return this.optEnum(clazz, index, null); }
/** * Get the enum value associated with an index. * * @param <E> * Enum Type * @param clazz * The type of enum to retrieve. * @param index * The index must be between 0 and length() - 1. * @return The enum value at the index location * @throws JSONException * if the key is not found or if the value cannot be converted * to an enum. */ public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONException { E val = optEnum(clazz, index); if(val==null) { // JSONException should really take a throwable argument. // If it did, I would re-implement this with the Enum.valueOf // method and place any thrown exception in the JSONException throw new JSONException("JSONArray[" + index + "] is not an enum of type " + JSONObject.quote(clazz.getSimpleName()) + "."); } return val; }
/** * Get the enum value associated with an index. * * @param clazz * The type of enum to retrieve. * @param index * The index must be between 0 and length() - 1. * @return The enum value at the index location * @throws JSONException * if the key is not found or if the value cannot be converted * to an enum. */ public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONException { E val = optEnum(clazz, index); if(val==null) { // JSONException should really take a throwable argument. // If it did, I would re-implement this with the Enum.valueOf // method and place any thrown exception in the JSONException throw new JSONException("JSONObject[" + JSONObject.quote(Integer.toString(index)) + "] is not an enum of type " + JSONObject.quote(clazz.getSimpleName()) + "."); } return val; }