/** * @param key the desired parameter's key * @param alternate The alternate Locale * @return a Locale for the specified key or the specified * alternate if no matching parameter is found */ public Locale getLocale(String key, Locale alternate) { Locale l = getLocale(key); return (l != null) ? l : alternate; }
/** * Does the actual configuration. This is protected, so * subclasses may share the same ValueParser and call configure * at any time, while preventing templates from doing so when * configure(Map) is locked. */ protected void configure(ValueParser values) { Locale locale = values.getLocale(ToolContext.LOCALE_KEY); if (locale != null) { setLocale(locale); } }
/** * @param key the key for the desired parameter * @return an array of Number objects associated with the given key, * or <code>null</code> if Numbers are not associated with it. */ public Number[] getNumbers(String key) { Object[] array = getValues(key); if (array == null || Number.class.isAssignableFrom(array.getClass().getComponentType())) { return (Number[])array; } Number[] ret = new Number[array.length]; for (int i = 0; i < array.length; ++i) { ret[i] = ConversionUtils.toNumber(array[i], getFormat(), getLocale()); } return ret; }
/** * @param key the desired parameter's key * @return a {@link Integer} for the specified key or * <code>null</code> if no matching parameter is found */ public Integer getInteger(String key) { Object value = getValue(key); if (value == null) { return null; } Number number = ConversionUtils.toNumber(value, getFormat(), getLocale()); return number == null ? null : number.intValue(); }
/** * @param key the desired parameter's key * @return a {@link Double} for the specified key or * <code>null</code> if no matching parameter is found */ public Double getDouble(String key) { Object value = getValue(key); if (value == null) { return null; } Number number = ConversionUtils.toNumber(value, getFormat(), getLocale()); return number == null ? null : number.doubleValue(); }
/** * @param key the desired parameter's key * @return a {@link Number} for the specified key or * <code>null</code> if no matching parameter is found */ public Number getNumber(String key) { return ConversionUtils.toNumber(getValue(key), getFormat(), getLocale()); }
/** * @param key the key for the desired parameter * @return an array of int values associated with the given key, * or <code>null</code> if numbers are not associated with it. */ public int[] getInts(String key) { Object[] array = getValues(key); if (array == null) { return null; } int[] ret = new int[array.length]; for (int i = 0; i < array.length; ++i) { ret[i] = ConversionUtils.toNumber(array[i], getFormat(), getLocale()).intValue(); } return ret; }
/** * @param key the key for the desired parameter * @return an array of double values associated with the given key, * or <code>null</code> if numbers are not associated with it. */ public double[] getDoubles(String key) { Object[] array = getValues(key); if (array == null) { return null; } double[] ret = new double[array.length]; for (int i = 0; i < array.length; ++i) { ret[i] = ConversionUtils.toNumber(array[i], getFormat(), getLocale()).doubleValue(); } return ret; }