/** * Get the value of the <code>name</code> property as a trimmed <code>String</code>, * <code>defaultValue</code> if no such property exists. * See @{Configuration#getTrimmed} for more details. * * @param name the property name. * @param defaultValue the property default value. * @return the value of the <code>name</code> or defaultValue * if it is not set. */ public String getTrimmed(String name, String defaultValue) { String ret = getTrimmed(name); return ret == null ? defaultValue : ret; }
/** * Get the value of the <code>name</code> property as a trimmed <code>String</code>, * <code>defaultValue</code> if no such property exists. * See @{Configuration#getTrimmed} for more details. * * @param name the property name. * @param defaultValue the property default value. * @return the value of the <code>name</code> or defaultValue * if it is not set. */ public String getTrimmed(String name, String defaultValue) { String ret = getTrimmed(name); return ret == null ? defaultValue : ret; }
@Override public String getTrimmed(String name, String defaultValue) { return encapsulated.getTrimmed(name, defaultValue); }
@Override public String getTrimmed(String name) { return encapsulated.getTrimmed(name); }
public static String getTrimmedVar(Configuration conf, ConfVars var) { assert (var.valClass == String.class) : var.varname; if (var.altName != null) { return conf.getTrimmed(var.varname, conf.getTrimmed(var.altName, var.defaultStrVal)); } return conf.getTrimmed(var.varname, var.defaultStrVal); }
@Override public String getTrimmed(String name) { return conf.getTrimmed(name); }
@Override public String getTrimmed(String name, String defaultValue) { return conf.getTrimmed(name, defaultValue); }
/** * Get the value of the <code>name</code> property as a <code>float</code>. * If no such property exists, the provided default value is returned, * or if the specified value is not a valid <code>float</code>, * then an error is thrown. * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>float</code>, * or <code>defaultValue</code>. */ public float getFloat(String name, float defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return Float.parseFloat(valueString); }
/** * Get the value of the <code>name</code> property as a <code>float</code>. * If no such property exists, the provided default value is returned, * or if the specified value is not a valid <code>float</code>, * then an error is thrown. * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>float</code>, * or <code>defaultValue</code>. */ public float getFloat(String name, float defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return Float.parseFloat(valueString); }
/** * Get the value of the <code>name</code> property as a <code>double</code>. * If no such property exists, the provided default value is returned, * or if the specified value is not a valid <code>double</code>, * then an error is thrown. * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>double</code>, * or <code>defaultValue</code>. */ public double getDouble(String name, double defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return Double.parseDouble(valueString); }
/** * Get the value of the <code>name</code> property as a <code>double</code>. * If no such property exists, the provided default value is returned, * or if the specified value is not a valid <code>double</code>, * then an error is thrown. * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>double</code>, * or <code>defaultValue</code>. */ public double getDouble(String name, double defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return Double.parseDouble(valueString); }
/** * Return value matching this enumerated type. * Note that the returned value is trimmed by this method. * @param name Property name * @param defaultValue Value returned if no mapping exists * @throws IllegalArgumentException If mapping is illegal for the type * provided */ public <T extends Enum<T>> T getEnum(String name, T defaultValue) { final String val = getTrimmed(name); return null == val ? defaultValue : Enum.valueOf(defaultValue.getDeclaringClass(), val); }
/** * Return value matching this enumerated type. * Note that the returned value is trimmed by this method. * @param name Property name * @param defaultValue Value returned if no mapping exists * @throws IllegalArgumentException If mapping is illegal for the type * provided */ public <T extends Enum<T>> T getEnum(String name, T defaultValue) { final String val = getTrimmed(name); return null == val ? defaultValue : Enum.valueOf(defaultValue.getDeclaringClass(), val); }
/** * Get the socket address for <code>name</code> property as a * <code>InetSocketAddress</code>. * @param name property name. * @param defaultAddress the default value * @param defaultPort the default port * @return InetSocketAddress */ public InetSocketAddress getSocketAddr( String name, String defaultAddress, int defaultPort) { final String address = getTrimmed(name, defaultAddress); return NetUtils.createSocketAddr(address, defaultPort, name); }
/** * Get the socket address for <code>name</code> property as a * <code>InetSocketAddress</code>. * @param name property name. * @param defaultAddress the default value * @param defaultPort the default port * @return InetSocketAddress */ public InetSocketAddress getSocketAddr( String name, String defaultAddress, int defaultPort) { final String address = getTrimmed(name, defaultAddress); return NetUtils.createSocketAddr(address, defaultPort, name); }
/** * Get the value of the <code>name</code> property as a <code>Class</code>. * If no such property is specified, then <code>defaultValue</code> is * returned. * * @param name the class name. * @param defaultValue default value. * @return property value as a <code>Class</code>, * or <code>defaultValue</code>. */ public Class<?> getClass(String name, Class<?> defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; try { return getClassByName(valueString); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
/** * Get the value of the <code>name</code> property as a <code>long</code> or * human readable format. If no such property exists, the provided default * value is returned, or if the specified value is not a valid * <code>long</code> or human readable format, then an error is thrown. You * can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), * t(tera), p(peta), e(exa) * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>long</code>, * or <code>defaultValue</code>. */ public long getLongBytes(String name, long defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return StringUtils.TraditionalBinaryPrefix.string2long(valueString); }
/** * Get the value of the <code>name</code> property as a <code>Class</code>. * If no such property is specified, then <code>defaultValue</code> is * returned. * * @param name the class name. * @param defaultValue default value. * @return property value as a <code>Class</code>, * or <code>defaultValue</code>. */ public Class<?> getClass(String name, Class<?> defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; try { return getClassByName(valueString); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
/** * Get the value of the <code>name</code> property as a <code>boolean</code>. * If no such property is specified, or if the specified value is not a valid * <code>boolean</code>, then <code>defaultValue</code> is returned. * * @param name property name. * @param defaultValue default value. * @return property value as a <code>boolean</code>, * or <code>defaultValue</code>. */ public boolean getBoolean(String name, boolean defaultValue) { String valueString = getTrimmed(name); if (null == valueString || valueString.isEmpty()) { return defaultValue; } if (StringUtils.equalsIgnoreCase("true", valueString)) return true; else if (StringUtils.equalsIgnoreCase("false", valueString)) return false; else return defaultValue; }
/** * Get the value of the <code>name</code> property as a <code>boolean</code>. * If no such property is specified, or if the specified value is not a valid * <code>boolean</code>, then <code>defaultValue</code> is returned. * * @param name property name. * @param defaultValue default value. * @return property value as a <code>boolean</code>, * or <code>defaultValue</code>. */ public boolean getBoolean(String name, boolean defaultValue) { String valueString = getTrimmed(name); if (null == valueString || valueString.isEmpty()) { return defaultValue; } if (StringUtils.equalsIgnoreCase("true", valueString)) return true; else if (StringUtils.equalsIgnoreCase("false", valueString)) return false; else return defaultValue; }