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
(Class<E> clazz, int index)
| 235 | * to an enum. |
| 236 | */ |
| 237 | public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONException { |
| 238 | E val = optEnum(clazz, index); |
| 239 | if (val == null) { |
| 240 | // JSONException should really take a throwable argument. |
| 241 | // If it did, I would re-implement this with the Enum.valueOf |
| 242 | // method and place any thrown exception in the JSONException |
| 243 | throw new JSONException("JSONObject[" + JSONObject.quote(Integer.toString(index)) + "] is not an enum of type " + JSONObject.quote(clazz.getSimpleName()) + "."); |
| 244 | } |
| 245 | return val; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Get the BigDecimal value associated with an index. |