/** * Get the optional boolean value associated with an index. * It returns the defaultValue if there is no value at that index or if * it is not a Boolean or the String "true" or "false" (case insensitive). * * @param index The index must be between 0 and length() - 1. * @param defaultValue A boolean default. * @return The truth. */ public boolean optBoolean(int index, boolean defaultValue) { try { return getBoolean(index); } catch (Exception e) { return defaultValue; } }
/** * Get the optional boolean value associated with an index. * It returns the defaultValue if there is no value at that index or if * it is not a Boolean or the String "true" or "false" (case insensitive). * * @param index The index must be between 0 and length() - 1. * @param defaultValue A boolean default. * @return The truth. */ public boolean optBoolean(int index, boolean defaultValue) { try { return getBoolean(index); } catch (Exception e) { return defaultValue; } }
@Override public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index) { Boolean val; try { val = jo.getBoolean(index); } catch (JSONException ex) { throw new IllegalArgumentException("The key " + field + " does not have a valid bool value.", ex); } gpo.setFieldGeneric(field, val); }
return ja.getBoolean(index); } catch (JSONException ex) { throw new IllegalArgumentException("The index " + index + " does not have a valid bool value.", ex);
private boolean sameScalar(ScalarValue want, JSONArray parent, int index) throws Exception { trace("comparing array scalar element " + index); String regexp = want.getRegexp(); if (want instanceof StringValue) { return sameString(((StringValue) want).getValue(), regexp, parent.getString(index)); } if (want instanceof LongValue) { return sameString(longToString(((LongValue) want).getValue()), regexp, longToString(parent.getLong(index))); } if (want instanceof IntValue) { return sameString(intToString(((IntValue) want).getValue()), regexp, intToString(parent.getInt(index))); } if (want instanceof DoubleValue) { return sameString(doubleToString(((DoubleValue) want).getValue()), regexp, doubleToString(parent.getDouble(index))); } if (want instanceof BooleanValue) { return sameString(booleanToString(((BooleanValue) want).getValue()), regexp, booleanToString(parent.getBoolean(index))); } throw new AssertionError(want + " is not a valid scalar type. Valid types are string, long, int, double, boolean"); }