private void copyPropIfExists(Map<String, String> toProps, Configuration fromConf, String property) { String value = fromConf.get(property); if (value != null) { toProps.put(property, value); } }
private Map<String, String> getAuthHandlerConfigs(Configuration configuration) { String prefix = Constants.Security.AUTH_HANDLER_CONFIG_BASE; int prefixLen = prefix.length(); // since its a regex match, we want to look for the character '.', and not match any character String configRegex = "^" + prefix.replace(".", "\\."); Map<String, String> props = new HashMap<>(); for (Map.Entry<String, String> pair : configuration.getValByRegex(configRegex).entrySet()) { String key = pair.getKey(); // we get the value via the conf, because conf#getValByRegex does not do variable substitution String value = configuration.get(key); props.put(key.substring(prefixLen), value); } return props; }
/** * Return value matching this enumerated type. * @param name Property name * @throws NullPointerException if the configuration property does not exist * @throws IllegalArgumentException If mapping is illegal for the type * provided */ public <T extends Enum<T>> T getEnum(String name, Class<T> declaringClass) { final String val = get(name); Preconditions.checkNotNull(val); return Enum.valueOf(declaringClass, val); }
/** * Return value matching this enumerated type. * @param name Property name * @throws NullPointerException if the configuration property does not exist * @throws IllegalArgumentException If mapping is illegal for the type * provided */ public <T extends Enum<T>> T getEnum(String name, Class<T> declaringClass) { final String val = get(name); Preconditions.checkNotNull(val); return Enum.valueOf(declaringClass, val); }
/** * Return value matching this enumerated type. * @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 = get(name); return null == val ? defaultValue : Enum.valueOf(defaultValue.getDeclaringClass(), val); }
/** * Return value matching this enumerated type. * @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 = get(name); return null == val ? defaultValue : Enum.valueOf(defaultValue.getDeclaringClass(), val); }
/** * Get the value of the <code>name</code> property as a <code>Pattern</code>. * If no such property is specified, or if the specified value is not a valid * <code>Pattern</code>, then an exception is thrown. * * @param name property name * @throws NullPointerException if the configuration property does not exist * @throws PatternSyntaxException if the configured value is not a valid {@code Pattern} * @return property value as a compiled Pattern */ public Pattern getPattern(String name) { String valString = get(name); Preconditions.checkNotNull(valString); return Pattern.compile(valString); }
/** * Get the value of the <code>name</code> property as a <code>Pattern</code>. * If no such property is specified, or if the specified value is not a valid * <code>Pattern</code>, then an exception is thrown. * * @param name property name * @throws NullPointerException if the configuration property does not exist * @throws PatternSyntaxException if the configured value is not a valid {@code Pattern} * @return property value as a compiled Pattern */ public Pattern getPattern(String name) { String valString = get(name); Preconditions.checkNotNull(valString); return Pattern.compile(valString); }
/** * Parse the given attribute as a set of integer ranges. * @param name the attribute name * @param defaultValue the default value if it is not set * @return a new set of ranges from the configured value */ public IntegerRanges getRange(String name, String defaultValue) { return new IntegerRanges(get(name, defaultValue)); }
/** * Get the comma delimited values of the <code>name</code> property as * an array of <code>String</code>s. * If no such property is specified then <code>null</code> is returned. * * @param name property name. * @return property value as an array of <code>String</code>s, * or <code>null</code>. */ public String[] getStrings(String name) { String valueString = get(name); return StringUtils.getStrings(valueString); }
/** * Sets a property if it is currently unset. * @param name the property name * @param value the new value */ public synchronized void setIfUnset(String name, String value) { if (get(name) == null) { set(name, value); } }
/** * Parse the given attribute as a set of integer ranges. * @param name the attribute name * @param defaultValue the default value if it is not set * @return a new set of ranges from the configured value */ public IntegerRanges getRange(String name, String defaultValue) { return new IntegerRanges(get(name, defaultValue)); }
/** * Parse the given attribute as a set of integer ranges. * @param name the attribute name * @throws NullPointerException if the configuration property does not exist * @return a new set of ranges from the configured value */ public IntegerRanges getRange(String name) { String valueString = get(name); Preconditions.checkNotNull(valueString); return new IntegerRanges(valueString); }
/** * Parse the given attribute as a set of integer ranges. * @param name the attribute name * @throws NullPointerException if the configuration property does not exist * @return a new set of ranges from the configured value */ public IntegerRanges getRange(String name) { String valueString = get(name); Preconditions.checkNotNull(valueString); return new IntegerRanges(valueString); }
/** * Sets a property if it is currently unset. * @param name the property name * @param value the new value */ public synchronized void setIfUnset(String name, String value) { if (get(name) == null) { set(name, value); } }
/** * Get the comma delimited values of the <code>name</code> property as * an array of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then an empty array is returned. * * @param name property name. * @return property value as an array of trimmed <code>String</code>s, * or empty array. */ public String[] getTrimmedStrings(String name) { String valueString = get(name); return StringUtils.getTrimmedStrings(valueString); }
/** * Get the comma delimited values of the <code>name</code> property as * an array of <code>String</code>s. * If no such property is specified then <code>null</code> is returned. * * @param name property name. * @return property value as an array of <code>String</code>s, * or <code>null</code>. */ public String[] getStrings(String name) { String valueString = get(name); return StringUtils.getStrings(valueString); }
/** * Get the comma delimited values of the <code>name</code> property as * an array of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then an empty array is returned. * * @param name property name. * @return property value as an array of trimmed <code>String</code>s, * or empty array. */ public String[] getTrimmedStrings(String name) { String valueString = get(name); return StringUtils.getTrimmedStrings(valueString); }
/** * Get the comma delimited values of the <code>name</code> property as * a collection of <code>String</code>s. * If no such property is specified then empty collection is returned. * <p> * This is an optimized version of {@link #getStrings(String)} * * @param name property name. * @return property value as a collection of <code>String</code>s. */ public Collection<String> getStringCollection(String name) { String valueString = get(name); return StringUtils.getStringCollection(valueString); }
/** * Get the comma delimited values of the <code>name</code> property as * a collection of <code>String</code>s. * If no such property is specified then empty collection is returned. * <p> * This is an optimized version of {@link #getStrings(String)} * * @param name property name. * @return property value as a collection of <code>String</code>s. */ public Collection<String> getStringCollection(String name) { String valueString = get(name); return StringUtils.getStringCollection(valueString); }