/** * Get an optional {@link Number} value associated with a key, or <code>null</code> * if there is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number ({@link BigDecimal}). This method * would be used in cases where type coercion of the number value is unwanted. * * @param key * A key string. * @return An object which is the value. */ public Number optNumber(String key) { return this.optNumber(key, null); }
/** * Get an optional {@link Number} value associated with a key, or <code>null</code> * if there is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number ({@link BigDecimal}). This method * would be used in cases where type coercion of the number value is unwanted. * * @param key * A key string. * @return An object which is the value. */ public Number optNumber(String key) { return this.optNumber(key, null); }
/** * Get an optional long value associated with a key, or the default if there * is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public long optLong(String key, long defaultValue) { final Number val = this.optNumber(key, null); if (val == null) { return defaultValue; } return val.longValue(); }
/** * Get an optional double associated with a key, or the defaultValue if * there is no such key or if its value is not a number. If the value is a * string, an attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public double optDouble(String key, double defaultValue) { Number val = this.optNumber(key); if (val == null) { return defaultValue; } final double doubleValue = val.doubleValue(); // if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { // return defaultValue; // } return doubleValue; }
/** * Get an optional int value associated with a key, or the default if there * is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public int optInt(String key, int defaultValue) { final Number val = this.optNumber(key, null); if (val == null) { return defaultValue; } return val.intValue(); }
/** * Get the optional double value associated with an index. The defaultValue * is returned if there is no value for the index, or if the value is not a * number and cannot be converted to a number. * * @param key * A key string. * @param defaultValue * The default value. * @return The value. */ public float optFloat(String key, float defaultValue) { Number val = this.optNumber(key); if (val == null) { return defaultValue; } final float floatValue = val.floatValue(); // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { // return defaultValue; // } return floatValue; }
/** * Get an optional {@link Number} value associated with a key, or <code>null</code> * if there is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number ({@link BigDecimal}). This method * would be used in cases where type coercion of the number value is unwanted. * * @param key * A key string. * @return An object which is the value. */ public Number optNumber(String key) { return this.optNumber(key, null); }
/** * Get an optional int value associated with a key, or the default if there * is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public int optInt(String key, int defaultValue) { final Number val = this.optNumber(key, null); if (val == null) { return defaultValue; } return val.intValue(); }
/** * Get an optional long value associated with a key, or the default if there * is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public long optLong(String key, long defaultValue) { final Number val = this.optNumber(key, null); if (val == null) { return defaultValue; } return val.longValue(); }
/** * Get an optional double associated with a key, or the defaultValue if * there is no such key or if its value is not a number. If the value is a * string, an attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public double optDouble(String key, double defaultValue) { Number val = this.optNumber(key); if (val == null) { return defaultValue; } final double doubleValue = val.doubleValue(); // if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { // return defaultValue; // } return doubleValue; }
/** * Get the optional double value associated with an index. The defaultValue * is returned if there is no value for the index, or if the value is not a * number and cannot be converted to a number. * * @param key * A key string. * @param defaultValue * The default value. * @return The value. */ public float optFloat(String key, float defaultValue) { Number val = this.optNumber(key); if (val == null) { return defaultValue; } final float floatValue = val.floatValue(); // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { // return defaultValue; // } return floatValue; }