Class TypedProperties

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>
Direct Known Subclasses:
NamedArguments, PositionalArguments, UnmodifiableTypedProperties

public class TypedProperties extends AbstractTypedProperties
Extension of the java.util.Properties class to handle the conversion of string values to other types.
Author:
Laurent Cohen
See Also:
  • Constructor Details

    • TypedProperties

      public TypedProperties()
      Default constructor.
    • TypedProperties

      public TypedProperties(Map<?,?> map)
      Initialize this object with a set of existing properties. This will copy into the present object all map entries such that both key and value are strings.
      Parameters:
      map - the properties to be copied. No reference to this parameter is kept in this TypedProperties object.
  • Method Details

    • getString

      public String getString(String key)
      Get the string value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      Returns:
      the value of the property as a string, or null if it is not found.
    • getString

      public String getString(String key, String defValue)
      Get the string value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      defValue - a default value to return if the property is not found.
      Returns:
      the value of the property as a string, or the default value if it is not found.
    • setString

      public TypedProperties setString(String key, String value)
      Set a property with the specified String value.
      Parameters:
      key - the name of the property to set.
      value - the value to set on the property.
      Returns:
      this TypedProperties object.
    • getInt

      public int getInt(String key)
      Get the integer value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      Returns:
      the value of the property as an int, or zero if it is not found.
    • getInt

      public int getInt(String key, int defValue)
      Get the integer value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      defValue - a default value to return if the property is not found.
      Returns:
      the value of the property as an int, or the default value if it is not found.
    • setInt

      public TypedProperties setInt(String key, int value)
      Set a property with the specified int value.
      Parameters:
      key - the name of the property to set.
      value - the value to set on the property.
      Returns:
      this TypedProperties object.
    • getLong

      public long getLong(String key)
      Get the long integer value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      Returns:
      the value of the property as a long, or zero if it is not found.
    • getLong

      public long getLong(String key, long defValue)
      Get the long integer value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      defValue - a default value to return if the property is not found.
      Returns:
      the value of the property as a long, or the default value if it is not found.
    • setLong

      public TypedProperties setLong(String key, long value)
      Set a property with the specified long value.
      Parameters:
      key - the name of the property to set.
      value - the value to set on the property.
      Returns:
      this TypedProperties object.
    • getFloat

      public float getFloat(String key)
      Get the single precision value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      Returns:
      the value of the property as a float, or zero if it is not found.
    • getFloat

      public float getFloat(String key, float defValue)
      Get the single precision value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      defValue - a default value to return if the property is not found.
      Returns:
      the value of the property as a float, or the default value if it is not found.
    • setFloat

      public TypedProperties setFloat(String key, float value)
      Set a property with the specified float value.
      Parameters:
      key - the name of the property to set.
      value - the value to set on the property.
      Returns:
      this TypedProperties object.
    • getDouble

      public double getDouble(String key)
      Get the double precision value of a property with a specified name. If the key is not found a default value of 0d is returned.
      Parameters:
      key - the name of the property to look for.
      Returns:
      the value of the property as a double, or zero if it is not found.
    • getDouble

      public double getDouble(String key, double defValue)
      Get the double precision value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      defValue - a default value to return if the property is not found.
      Returns:
      the value of the property as a double, or the default value if it is not found.
    • setDouble

      public TypedProperties setDouble(String key, double value)
      Set a property with the specified double value.
      Parameters:
      key - the name of the property to set.
      value - the value to set on the property.
      Returns:
      this TypedProperties object.
    • getBoolean

      public boolean getBoolean(String key)
      Get the boolean value of a property with a specified name. If the key is not found a default value of false is returned.
      Parameters:
      key - the name of the property to look for.
      Returns:
      the value of the property as a boolean, or false if it is not found.
    • getBoolean

      public boolean getBoolean(String key, boolean defValue)
      Get the boolean value of a property with a specified name.
      Parameters:
      key - the name of the property to look for.
      defValue - a default value to return if the property is not found.
      Returns:
      the value of the property as a boolean, or the default value if it is not found.
    • setBoolean

      public TypedProperties setBoolean(String key, boolean value)
      Set a property with the specified boolean value.
      Parameters:
      key - the name of the property to set.
      value - the value to set on the property.
      Returns:
      this TypedProperties object.
    • getChar

      public char getChar(String key)
      Get the char value of a property with a specified name. If the key is not found a default value of ' ' is returned.
      Parameters:
      key - the name of the property to look for.
      Returns:
      the value of the property as a char, or the default value ' ' (space character) if it is not found.
    • getChar

      public char getChar(String key, char defValue)
      Get the char value of a property with a specified name. If the value has more than one character, the first one will be used.
      Parameters:
      key - the name of the property to look for.
      defValue - a default value to return if the property is not found.
      Returns:
      the value of the property as a char, or the default value if it is not found.
    • setChar

      public TypedProperties setChar(String key, char value)
      Set a property with the specified char value.
      Parameters:
      key - the name of the property to set.
      value - the value to set on the property.
      Returns:
      this TypedProperties object.
    • getFile

      public File getFile(String key)
      Get the value of the specified property as a File.
      Parameters:
      key - the name of the property to look up.
      Returns:
      an abstract file path based on the value of the property, or null if the property is not defined.
    • getFile

      public File getFile(String key, File defValue)
      Get the value of the specified property as a File.
      Parameters:
      key - the name of the property to look up.
      defValue - the value to return if the property is not found.
      Returns:
      an abstract file path based on the value of the property, or the default value if the property is not defined.
    • setFile

      public TypedProperties setFile(String key, File value)
      Set the value of the specified property as a File.
      Parameters:
      key - the name of the property to look up.
      value - the file whose path to set as the property value.
      Returns:
      this TypedProperties object.
    • getStringArray

      public String[] getStringArray(String key, String delimiter)
      Get the value of the specified property as an array of strings.
      Parameters:
      key - the name of the property to look up.
      delimiter - the delimiter used to split the value into an array of strings. It MUST be a litteral string, i.e. not a regex.
      Returns:
      an abstract file path based on the value of the property, or null if the property is not defined.
      Since:
      5.2
    • getStringArray

      public String[] getStringArray(String key, String delimiter, String[] defValue)
      Get the value of the specified property as an array of strings.
      Parameters:
      key - the name of the property to look up.
      delimiter - the delimiter used to split the value into an array of strings. It MUST be a litteral string, i.e. not a regex.
      defValue - the value to return if the property is not found.
      Returns:
      an abstract file path based on the value of the property, or the default value if the property is not defined.
      Since:
      5.2
    • setStringArray

      public TypedProperties setStringArray(String key, String delimiter, String... value)
      Set the value of the specified property as an array of strings.
      Parameters:
      key - the name of the property to look up.
      delimiter - the delimiter that will be inserted between any two adjacent strings. It MUST be a litteral string, i.e. not a regex.
      value - an array of strings.
      Returns:
      this TypedProperties object.
      Since:
      5.2
    • getProperties

      public TypedProperties getProperties(String key)
      Get the value of a property with the specified name as a set of a properties.
      Parameters:
      key - the name of the property to look for. Its value is the path to another properties file. Relative paths are evaluated against the current application directory.
      Returns:
      the value of the property as another set of properties, or null if it is not found.
    • getProperties

      public TypedProperties getProperties(String key, TypedProperties def)
      Get the value of a property with the specified name as a set of properties.
      Parameters:
      key - the name of the property to look for. Its value is the path to another properties file. Relative paths are evaluated against the current application directory.
      def - a default value to return if the property is not found.
      Returns:
      the value of the property as another set of properties, or the default value if it is not found.
    • getInetAddress

      public InetAddress getInetAddress(String key)
      Get the value of a property with the specified name as an InetAddress.
      Parameters:
      key - the name of the property to retrieve.
      Returns:
      the property as an InetAddress instance, or null if the property is not defined or the host doesn't exist.
    • getInetAddress

      public InetAddress getInetAddress(String key, InetAddress def)
      Get the value of a property with the specified name as an InetAddress.
      Parameters:
      key - the name of the property to retrieve.
      def - the default value to use if the property is not defined.
      Returns:
      the property as an InetAddress instance, or the specified default value if the property is not defined.
    • filter

      public TypedProperties filter(TypedProperties.Filter filter)
      Extract the properties that pass the specified filter.
      Parameters:
      filter - the filter to use, if null then all properties are returned.
      Returns:
      a new TypedProperties object containing only the properties matching the filter.
    • set

      public <T> TypedProperties set(JPPFProperty<T> property, T value)
      Set the value of a predefined property.
      Type Parameters:
      T - the type of the property.
      Parameters:
      property - the property whose value to set.
      value - the value to set.
      Returns:
      the value of the property according to its type.
      Since:
      5.2
    • set

      public <T> TypedProperties set(JPPFProperty<T> property, T value, String... parameters)
      Set the value of a predefined parametrized property.
      Type Parameters:
      T - the type of the property.
      Parameters:
      property - the property whose value to set.
      value - the value to set.
      parameters - the values to replace the property's parameters with.
      Returns:
      the value of the property according to its type.
      Since:
      6.0
    • get

      public <T> T get(JPPFProperty<T> property)
      Get the value of a predefined property.
      Type Parameters:
      T - the type of the property.
      Parameters:
      property - the property whose value to retrieve.
      Returns:
      the value of the property according to its type.
      Since:
      5.2
    • get

      public <T> T get(JPPFProperty<T> property, String... parameters)
      Get the value of a predefined parametrized property.
      Type Parameters:
      T - the type of the property.
      Parameters:
      property - the property whose value to retrieve.
      parameters - the values to replace the property's parameters with.
      Returns:
      the value of the property according to its type.
      Since:
      6.0
    • remove

      public <T> T remove(JPPFProperty<T> property)
      Remove the specified predefined property.
      Type Parameters:
      T - the type of the property.
      Parameters:
      property - the property whose value to retrieve.
      Returns:
      the old value of the property, or null if it wasn't defined.
      Since:
      5.2
    • containsProperty

      public boolean containsProperty(JPPFProperty<?> property)
      Determine whether this set of properties contains the specified property. The lookkup is performed on the property's name first, then on its aliases if the name is not found.
      Parameters:
      property - the property to look for.
      Returns:
      true if the property or one of its aliases is found, false otherwise.
      Since:
      5.2
    • remove

      public <T> T remove(JPPFProperty<T> property, String... parameters)
      Deprecated.
      Remove the specified predefined parametrized property.
      Type Parameters:
      T - the type of the property.
      Parameters:
      property - the property whose value to retrieve.
      parameters - the values to replace the property's parameters with.
      Returns:
      the old value of the property, or null if it wasn't defined.
      Since:
      6.0
    • removeProperty

      public <T> T removeProperty(JPPFProperty<T> property, String... parameters)
      Remove the specified predefined parametrized property.
      Type Parameters:
      T - the type of the property.
      Parameters:
      property - the property whose value to retrieve.
      parameters - the values to replace the property's parameters with.
      Returns:
      the old value of the property, or null if it wasn't defined.
      Since:
      6.1
    • store

      public void store(Writer writer, String comments) throws IOException
      Overrides:
      store in class Properties
      Throws:
      IOException