protected <T extends Enum<T>> Set<T> getAll(final String property, final Set<T> defaultValue, final Class<T> enumType) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.getAll(property, defaultValue, enumType); } // Shorthand for specifying ALL or NONE for any option // that allows for multiple values of the enum if ("all".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value)) { log(property, value); return EnumSet.allOf(enumType); } else if ("none".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { log(property, value); return EnumSet.noneOf(enumType); } try { final String[] values = value.split(","); final EnumSet<T> set = EnumSet.noneOf(enumType); for (String s : values) { s = s.trim(); set.add(valueOf(enumType, s.toUpperCase())); } return logAll(property, set); } catch (final IllegalArgumentException e) { warn(property, value); return parent.getAll(property, defaultValue, enumType); } }
@SuppressWarnings("unchecked") public <T> T get(final String property, final T defaultValue) { if (defaultValue == null) { throw new NullPointerException("defaultValue"); } final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } try { final Class<?> type = defaultValue.getClass(); final Constructor<?> constructor = type.getConstructor(String.class); final T t = (T) constructor.newInstance(value); return log(property, t); } catch (final Exception e) { e.printStackTrace(); warn(property, value, e); return parent.get(property, defaultValue); } }
@SuppressWarnings("unchecked") public <T> T get(final String property, final T defaultValue) { if (defaultValue == null) { throw new NullPointerException("defaultValue"); } final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } try { final Class<?> type = defaultValue.getClass(); final Constructor<?> constructor = type.getConstructor(String.class); final T t = (T) constructor.newInstance(value); return log(property, t); } catch (final Exception e) { e.printStackTrace(); warn(property, value, e); return parent.get(property, defaultValue); } }
protected <T extends Enum<T>> Set<T> getAll(final String property, final Set<T> defaultValue, final Class<T> enumType) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.getAll(property, defaultValue, enumType); } // Shorthand for specifying ALL or NONE for any option // that allows for multiple values of the enum if ("all".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value)) { log(property, value); return EnumSet.allOf(enumType); } else if ("none".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { log(property, value); return EnumSet.noneOf(enumType); } try { final String[] values = value.split(","); final EnumSet<T> set = EnumSet.noneOf(enumType); for (String s : values) { s = s.trim(); set.add(valueOf(enumType, s.toUpperCase())); } return logAll(property, set); } catch (final IllegalArgumentException e) { warn(property, value); return parent.getAll(property, defaultValue, enumType); } }
public <T extends Enum<T>> T get(final String property, final T defaultValue) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } if (defaultValue == null) { throw new IllegalArgumentException("Must supply a default for property " + property); } final Class<T> enumType = (Class<T>) defaultValue.getClass(); try { return log(property, valueOf(enumType, value.toUpperCase())); } catch (final IllegalArgumentException e) { warn(property, value); return parent.get(property, defaultValue); } }
public Class<?> get(final String property, final Class<?> defaultValue) { final String className = properties.getProperty(property); if (className == null) { return parent.get(property, defaultValue); } final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { return log(property, classLoader.loadClass(className)); } catch (final Exception e) { getLogger().warning("Could not load " + property + " : " + className, e); return parent.get(property, defaultValue); } }
public String get(final String property, final String defaultValue) { final String value = properties.getProperty(property); return value != null ? log(property, value) : parent.get(property, defaultValue); }
public <T extends Enum<T>> T get(final String property, final T defaultValue) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } if (defaultValue == null) { throw new IllegalArgumentException("Must supply a default for property " + property); } final Class<T> enumType = (Class<T>) defaultValue.getClass(); try { return log(property, valueOf(enumType, value.toUpperCase())); } catch (final IllegalArgumentException e) { warn(property, value); return parent.get(property, defaultValue); } }
public long get(final String property, final long defaultValue) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } try { return log(property, Long.parseLong(value)); } catch (final NumberFormatException e) { warn(property, value, e); return parent.get(property, defaultValue); } }
public String get(final String property, final String defaultValue) { final String value = properties.getProperty(property); return value != null ? log(property, value) : parent.get(property, defaultValue); }
public boolean get(final String property, final boolean defaultValue) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } try { return log(property, Boolean.parseBoolean(value)); } catch (final NumberFormatException e) { warn(property, value, e); return parent.get(property, defaultValue); } }
public int get(final String property, final int defaultValue) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } try { return log(property, Integer.parseInt(value)); } catch (final NumberFormatException e) { warn(property, value, e); return parent.get(property, defaultValue); } }
public Class<?> get(final String property, final Class<?> defaultValue) { final String className = properties.getProperty(property); if (className == null) { return parent.get(property, defaultValue); } final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { return log(property, classLoader.loadClass(className)); } catch (final Exception e) { getLogger().warning("Could not load " + property + " : " + className, e); return parent.get(property, defaultValue); } }
public int get(final String property, final int defaultValue) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } try { return log(property, Integer.parseInt(value)); } catch (final NumberFormatException e) { warn(property, value, e); return parent.get(property, defaultValue); } }
public long get(final String property, final long defaultValue) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } try { return log(property, Long.parseLong(value)); } catch (final NumberFormatException e) { warn(property, value, e); return parent.get(property, defaultValue); } }
public boolean get(final String property, final boolean defaultValue) { final String value = properties.getProperty(property); if (value == null || value.equals("")) { return parent.get(property, defaultValue); } try { return log(property, Boolean.parseBoolean(value)); } catch (final NumberFormatException e) { warn(property, value, e); return parent.get(property, defaultValue); } }