Class TypedProperties

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,​java.lang.Object>
    Direct Known Subclasses:
    TypedProperties

    public class TypedProperties
    extends java.util.Properties
    Type-aware properties. Extends the JDK Properties class to provide accessors that convert values to certain types, using default values if a conversion is not possible.
    Since:
    4.0
    Author:
    Manik Surtani
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class java.util.Properties

        defaults
    • Constructor Summary

      Constructors 
      Constructor Description
      TypedProperties()
      Default constructor that returns an empty instance
      TypedProperties​(java.util.Properties p)
      Copy constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean getBooleanProperty​(java.lang.String key, boolean defaultValue)  
      boolean getBooleanProperty​(java.lang.String key, boolean defaultValue, boolean doStringReplace)  
      <T extends java.lang.Enum<T>>
      T
      getEnumProperty​(java.lang.String key, java.lang.Class<T> enumClass, T defaultValue)  
      <T extends java.lang.Enum<T>>
      T
      getEnumProperty​(java.lang.String key, java.lang.Class<T> enumClass, T defaultValue, boolean doStringReplace)  
      int getIntProperty​(java.lang.String key, int defaultValue)  
      int getIntProperty​(java.lang.String key, int defaultValue, boolean doStringReplace)  
      long getLongProperty​(java.lang.String key, long defaultValue)  
      long getLongProperty​(java.lang.String key, long defaultValue, boolean doStringReplace)  
      java.lang.String getProperty​(java.lang.String key, java.lang.String defaultValue, boolean doStringReplace)
      Get the property associated with the key, optionally applying string property replacement as defined in StringPropertyReplacer.replaceProperties(java.lang.String) to the result.
      TypedProperties putIfAbsent​(java.lang.String key, java.lang.String value)
      Put a value if the associated key is not present
      TypedProperties setProperty​(java.lang.String key, boolean value)  
      TypedProperties setProperty​(java.lang.String key, int value)  
      TypedProperties setProperty​(java.lang.String key, long value)  
      TypedProperties setProperty​(java.lang.String key, java.lang.String value)  
      static TypedProperties toTypedProperties​(java.util.Properties p)
      Factory method that converts a JDK Properties instance to an instance of TypedProperties, if needed.
      • Methods inherited from class java.util.Properties

        clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TypedProperties

        public TypedProperties​(java.util.Properties p)
        Copy constructor
        Parameters:
        p - properties instance to from. If null, then it is treated as an empty Properties instance.
      • TypedProperties

        public TypedProperties()
        Default constructor that returns an empty instance
    • Method Detail

      • toTypedProperties

        public static TypedProperties toTypedProperties​(java.util.Properties p)
        Factory method that converts a JDK Properties instance to an instance of TypedProperties, if needed.
        Parameters:
        p - properties to convert.
        Returns:
        A TypedProperties object. Returns an empty TypedProperties instance if p is null.
      • getIntProperty

        public int getIntProperty​(java.lang.String key,
                                  int defaultValue)
      • getIntProperty

        public int getIntProperty​(java.lang.String key,
                                  int defaultValue,
                                  boolean doStringReplace)
      • getLongProperty

        public long getLongProperty​(java.lang.String key,
                                    long defaultValue)
      • getLongProperty

        public long getLongProperty​(java.lang.String key,
                                    long defaultValue,
                                    boolean doStringReplace)
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.String key,
                                          boolean defaultValue)
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.String key,
                                          boolean defaultValue,
                                          boolean doStringReplace)
      • getEnumProperty

        public <T extends java.lang.Enum<T>> T getEnumProperty​(java.lang.String key,
                                                               java.lang.Class<T> enumClass,
                                                               T defaultValue)
      • getEnumProperty

        public <T extends java.lang.Enum<T>> T getEnumProperty​(java.lang.String key,
                                                               java.lang.Class<T> enumClass,
                                                               T defaultValue,
                                                               boolean doStringReplace)
      • getProperty

        public java.lang.String getProperty​(java.lang.String key,
                                            java.lang.String defaultValue,
                                            boolean doStringReplace)
        Get the property associated with the key, optionally applying string property replacement as defined in StringPropertyReplacer.replaceProperties(java.lang.String) to the result.
        Parameters:
        key - the hashtable key.
        defaultValue - a default value.
        doStringReplace - boolean indicating whether to apply string property replacement
        Returns:
        the value in this property list with the specified key valu after optionally being inspected for String property replacement
      • putIfAbsent

        public TypedProperties putIfAbsent​(java.lang.String key,
                                           java.lang.String value)
        Put a value if the associated key is not present
        Parameters:
        key - new key
        value - new value
        Returns:
        this TypedProperties instance for method chaining
      • setProperty

        public TypedProperties setProperty​(java.lang.String key,
                                           java.lang.String value)
        Overrides:
        setProperty in class java.util.Properties
      • setProperty

        public TypedProperties setProperty​(java.lang.String key,
                                           int value)
      • setProperty

        public TypedProperties setProperty​(java.lang.String key,
                                           long value)
      • setProperty

        public TypedProperties setProperty​(java.lang.String key,
                                           boolean value)