Class TypedProperties

java.lang.Object
org.moeaframework.util.TypedProperties
All Implemented Interfaces:
Displayable, Formattable<Map.Entry<String,String>>

public class TypedProperties extends Object implements Formattable<Map.Entry<String,String>>
Stores a collection of key-value pairs similar to Properties but has support for reading and writing primitive types. Internally, this handles converting specific types to a string representation that can be saved and read from files. In addition to primitive types, arrays of those primitives are also supported using either the default "," separator or a user-configurable string. Leading and trailing whitespace is automatically trimmed from each entry. Be mindful that values saved in arrays should not include the separator character(s) - no escaping is performed! From version 3.0+, keys are case-insensitive.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The default separator for arrays.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new, empty instance of this class.
    Creates a new typed properties instance initialized with the content of the properties.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAll(Properties properties)
    Adds all properties from the specified properties object.
    void
    addAll(TypedProperties properties)
    Adds all properties from the specified properties object.
    Returns the contents of this object as a TabularData instance, which can be used to save, print, or format the data in various ways.
    void
    Clears all properties.
    void
    Clears the tracking information for properties that have been accessed.
    boolean
    Returns true if the specified key is contained in this properties object; false otherwise.
    Creates a new scope that allows making temporary changes to the properties.
    boolean
     
    Returns the properties that were accessed since the last call to clearAccessedProperties() or clear().
    boolean
    Returns the value of the property as a boolean, or throws an exception.
    boolean
    getBoolean(String key, boolean defaultValue)
    Returns the value of the property with the specified name as a boolean; or defaultValue if no property with the specified name exists.
    byte
    Returns the value of the property as a byte, or throws an exception.
    byte
    getByte(String key, byte defaultValue)
    Returns the value of the property with the specified name as a byte; or defaultValue if no property with the specified name exists.
    byte[]
    Returns the value of the property as a byte array, or throws an exception.
    byte[]
    getByteArray(String key, byte[] defaultValues)
    Returns the value of the property with the specified name as a byte array; or defaultValues if no property with the specified name exists.
    double
    Returns the value of the property as a double, or throws an exception.
    double
    getDouble(String key, double defaultValue)
    Returns the value of the property with the specified name as a double; or defaultValue if no property with the specified name exists.
    double[]
    Returns the value of the property as a double array, or throws an exception.
    double[]
    getDoubleArray(String key, double[] defaultValues)
    Returns the value of the property with the specified name as a double array; or defaultValues if no property with the specified name exists.
    <T extends Enum<?>>
    T
    getEnum(String key, Class<T> enumType)
    Returns the value of the property with the specified name as an Enum.
    <T extends Enum<?>>
    T
    getEnum(String key, Class<T> enumType, T defaultValue)
    Returns the value of the property with the specified name as an Enum; or defaultValue if no property with the specified name exists.
    static <T extends Enum<?>>
    T
    getEnumFromPartialString(Class<T> enumType, String value)
    Converts the value into the matching Enum constant using an OptionCompleter to allow partial string matching.
    static <T extends Enum<?>>
    T
    getEnumFromString(Class<T> enumType, String value)
    Converts the value into the matching Enum constant.
    float
    Returns the value of the property as a float, or throws an exception.
    float
    getFloat(String key, float defaultValue)
    Returns the value of the property with the specified name as a float; or defaultValue if no property with the specified name exists.
    float[]
    Returns the value of the property as a float array, or throws an exception.
    float[]
    getFloatArray(String key, float[] defaultValues)
    Returns the value of the property with the specified name as a float array; or defaultValues if no property with the specified name exists.
    int
    Returns the value of the property as a int, or throws an exception.
    int
    getInt(String key, int defaultValue)
    Returns the value of the property with the specified name as an int; or defaultValue if no property with the specified name exists.
    int[]
    Returns the value of the property as a int array, or throws an exception.
    int[]
    getIntArray(String key, int[] defaultValues)
    Returns the value of the property with the specified name as an int array; or defaultValues if no property with the specified name exists.
    long
    Returns the value of the property as a long, or throws an exception.
    long
    getLong(String key, long defaultValue)
    Returns the value of the property with the specified name as a long; or defaultValue if no property with the specified name exists.
    long[]
    Returns the value of the property as a long array, or throws an exception.
    long[]
    getLongArray(String key, long[] defaultValues)
    Returns the value of the property with the specified name as a long array; or defaultValues if no property with the specified name exists.
    short
    Returns the value of the property as a short, or throws an exception.
    short
    getShort(String key, short defaultValue)
    Returns the value of the property with the specified name as a short; or defaultValue if no property with the specified name exists.
    short[]
    Returns the value of the property as a short array, or throws an exception.
    short[]
    getShortArray(String key, short[] defaultValues)
    Returns the value of the property with the specified name as a short array; or defaultValues if no property with the specified name exists.
    Returns the value of the property as a string, or throws an exception.
    getString(String key, String defaultValue)
    Returns the value of the property with the specified name as a string; or defaultValue if no property with the specified name exists.
    Returns the value of the property as a String array, or throws an exception.
    getStringArray(String key, String[] defaultValues)
    Returns the value of the property with the specified name as a String array; or defaultValues if no property with the specified name exists.
    int
    Returns the value of the property as a int, or throws an exception.
    int
    getTruncatedInt(String key, int defaultValue)
    Returns the value of the property with the specified name as an int; or defaultValue if no property with the specified name exists.
    long
    Returns the value of the property as a long, or throws an exception.
    long
    getTruncatedLong(String key, long defaultValue)
    Returns the value of the property with the specified name as a long; or defaultValue if no property with the specified name exists.
    Returns the properties that were never accessed since the last call to clearAccessedProperties() or clear()
    int
     
    boolean
    Returns true if there are no properties set.
    Returns the set of keys contained in this properties object.
    void
    load(Reader reader)
    Loads the properties from a reader.
    Loads the contents of META-INF/build.properties and evaluates any string substitutions in the form ${token}.
    Creates and returns an empty properties object that is thread-safe.
    of()
    Convenience method to quickly construct an empty typed properties instance.
    of(String key, String value)
    Convenience method to quickly construct a typed properties instance with a single key-value pair.
    void
    Removes the property with the specified name.
    void
    setBoolean(String key, boolean value)
    Sets the value of the property to the given boolean.
    void
    setByte(String key, byte value)
    Sets the value of the property to the given byte.
    void
    setByteArray(String key, byte[] values)
    Sets the value of the property with the specified name as a byte array.
    void
    setDouble(String key, double value)
    Sets the value of the property to the given double.
    void
    setDoubleArray(String key, double[] values)
    Sets the value of the property with the specified name as a double array.
    <T extends Enum<?>>
    void
    setEnum(String key, T value)
    Sets the value of the property to the given enum value.
    void
    setFloat(String key, float value)
    Sets the value of the property to the given float.
    void
    setFloatArray(String key, float[] values)
    Sets the value of the property with the specified name as a float array.
    void
    setInt(String key, int value)
    Sets the value of the property to the given int.
    void
    setIntArray(String key, int[] values)
    Sets the value of the property with the specified name as a int array.
    void
    setLong(String key, long value)
    Sets the value of the property to the given long.
    void
    setLongArray(String key, long[] values)
    Sets the value of the property with the specified name as a long array.
    void
    setShort(String key, short value)
    Sets the value of the property to the given short.
    void
    setShortArray(String key, short[] values)
    Sets the value of the property with the specified name as a short array.
    void
    setString(String key, String value)
    Sets the value of the property to the given String.
    void
    setStringArray(String key, String[] values)
    Sets the value of the property with the specified name as a String array.
    int
    Returns the number of properties that are defined.
    void
    store(Writer writer)
    Writes the properties to a writer.
    void
    Similar to warnIfUnaccessedProperties(), except throws a ConfigurationException if any properties were not accessed.
    void
    Prints a warning if any properties were not accessed.
    withProperty(String key, String value)
    Deprecated.
    use of(String, String) instead

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.moeaframework.util.format.Displayable

    display

    Methods inherited from interface org.moeaframework.util.format.Formattable

    display, display, display, save, saveCSV
  • Field Details

  • Constructor Details

    • TypedProperties

      public TypedProperties()
      Creates a new, empty instance of this class.
    • TypedProperties

      public TypedProperties(Properties properties)
      Creates a new typed properties instance initialized with the content of the properties.
      Parameters:
      properties - the existing Properties object
  • Method Details

    • withProperty

      @Deprecated public static TypedProperties withProperty(String key, String value)
      Deprecated.
      use of(String, String) instead
      Convenience method to quickly construct a typed properties instance with a single key-value pair. This is particularly useful for parsing, for instance, command line arguments:
         TypedProperties.of("epsilon", commandLine.getOptionValue("epsilon")).getDoubleArray("epsilon");
       
      Parameters:
      key - the key
      value - the value assigned to the key
      Returns:
      a typed properties instance with the specified key-value pair
    • newThreadSafeInstance

      public static TypedProperties newThreadSafeInstance()
      Creates and returns an empty properties object that is thread-safe. This is useful when needing thread-safe access to a shared properties object.
      Returns:
      an empty, thread-safe properties object
    • of

      public static TypedProperties of()
      Convenience method to quickly construct an empty typed properties instance. The returned instance is mutable and can be modified by the caller.
      Returns:
      an empty typed properties instance
    • of

      public static TypedProperties of(String key, String value)
      Convenience method to quickly construct a typed properties instance with a single key-value pair. This is particularly useful for parsing, for instance, command line arguments:
         TypedProperties.of("epsilon", commandLine.getOptionValue("epsilon")).getDoubleArray("epsilon");
       

      The returned instance is mutable and can be modified by the caller.

      Parameters:
      key - the key
      value - the value assigned to the key
      Returns:
      a typed properties instance with the specified key-value pair
    • loadBuildProperties

      public static TypedProperties loadBuildProperties() throws IOException
      Loads the contents of META-INF/build.properties and evaluates any string substitutions in the form ${token}.
      Returns:
      the build properties
      Throws:
      IOException - if an error occurred loading the file
    • keySet

      public Set<String> keySet()
      Returns the set of keys contained in this properties object. The set is backed by this properties object, so changes to the set, such as removing a key, will also remove the corresponding property.
      Returns:
      the keys
    • contains

      public boolean contains(String key)
      Returns true if the specified key is contained in this properties object; false otherwise.
      Parameters:
      key - the property name
      Returns:
      true if the specified key is contained in this properties object; false otherwise
    • getString

      public String getString(String key, String defaultValue)
      Returns the value of the property with the specified name as a string; or defaultValue if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as a string; or defaultValue if no property with the specified name exists
    • getString

      public String getString(String key)
      Returns the value of the property as a string, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getDouble

      public double getDouble(String key, double defaultValue)
      Returns the value of the property with the specified name as a double; or defaultValue if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as a double; or defaultValue if no property with the specified name exists
      Throws:
      NumberFormatException - if the property value is not a parseable double
    • getDouble

      public double getDouble(String key)
      Returns the value of the property as a double, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getFloat

      public float getFloat(String key, float defaultValue)
      Returns the value of the property with the specified name as a float; or defaultValue if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as a float; or defaultValue if no property with the specified name exists
      Throws:
      NumberFormatException - if the property value is not a parseable float
    • getFloat

      public float getFloat(String key)
      Returns the value of the property as a float, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getLong

      public long getLong(String key, long defaultValue)
      Returns the value of the property with the specified name as a long; or defaultValue if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as a long; or defaultValue if no property with the specified name exists
      Throws:
      NumberFormatException - if the property value is not a parseable long
    • getLong

      public long getLong(String key)
      Returns the value of the property as a long, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getInt

      public int getInt(String key, int defaultValue)
      Returns the value of the property with the specified name as an int; or defaultValue if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as an int; or defaultValue if no property with the specified name exists
      Throws:
      NumberFormatException - if the property value is not a parseable integer
    • getInt

      public int getInt(String key)
      Returns the value of the property as a int, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getTruncatedInt

      public int getTruncatedInt(String key, int defaultValue)
      Returns the value of the property with the specified name as an int; or defaultValue if no property with the specified name exists. Any decimal places will be truncated.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as an int; or defaultValue if no property with the specified name exists
      Throws:
      NumberFormatException - if the property value is not a parseable integer
    • getTruncatedInt

      public int getTruncatedInt(String key)
      Returns the value of the property as a int, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists. Any decimal places will be truncated.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getTruncatedLong

      public long getTruncatedLong(String key, long defaultValue)
      Returns the value of the property with the specified name as a long; or defaultValue if no property with the specified name exists. Any decimal places will be truncated.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as a long; or defaultValue if no property with the specified name exists
      Throws:
      NumberFormatException - if the property value is not a parseable long
    • getTruncatedLong

      public long getTruncatedLong(String key)
      Returns the value of the property as a long, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists. Any decimal places will be truncated.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getShort

      public short getShort(String key, short defaultValue)
      Returns the value of the property with the specified name as a short; or defaultValue if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as a short; or defaultValue if no property with the specified name exists
      Throws:
      NumberFormatException - if the property value is not a parseable short
    • getShort

      public short getShort(String key)
      Returns the value of the property as a short, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getByte

      public byte getByte(String key, byte defaultValue)
      Returns the value of the property with the specified name as a byte; or defaultValue if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as a byte; or defaultValue if no property with the specified name exists
      Throws:
      NumberFormatException - if the property value is not a parseable byte
    • getByte

      public byte getByte(String key)
      Returns the value of the property as a byte, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Returns the value of the property with the specified name as a boolean; or defaultValue if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as a boolean; or defaultValue if no property with the specified name exists
    • getBoolean

      public boolean getBoolean(String key)
      Returns the value of the property as a boolean, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property
      Throws:
      PropertyNotFoundException - if the property was not found
    • getEnum

      public <T extends Enum<?>> T getEnum(String key, Class<T> enumType)
      Returns the value of the property with the specified name as an Enum. If no such property is set, returns the default Enum value.
      Type Parameters:
      T - the Enum type
      Parameters:
      key - the property name
      enumType - the Enum class
      Returns:
      the value of the property with the specified name as an Enum
    • getEnum

      public <T extends Enum<?>> T getEnum(String key, Class<T> enumType, T defaultValue)
      Returns the value of the property with the specified name as an Enum; or defaultValue if no property with the specified name exists.
      Type Parameters:
      T - the Enum type
      Parameters:
      key - the property name
      enumType - the Enum class
      defaultValue - the default value
      Returns:
      the value of the property with the specified name as an Enum
    • getEnumFromString

      public static <T extends Enum<?>> T getEnumFromString(Class<T> enumType, String value)
      Converts the value into the matching Enum constant. Unlike using Enum.valueOf(Class, String), this version is case-insensitive.
      Type Parameters:
      T - the Enum type
      Parameters:
      enumType - the Enum class
      value - the value as a string
      Returns:
      the Enum value
      Throws:
      IllegalArgumentException - if the value does not match any enumeration constant
    • getEnumFromPartialString

      public static <T extends Enum<?>> T getEnumFromPartialString(Class<T> enumType, String value)
      Converts the value into the matching Enum constant using an OptionCompleter to allow partial string matching.
      Type Parameters:
      T - the Enum type
      Parameters:
      enumType - the Enum class
      value - the value as a string
      Returns:
      the Enum value
      Throws:
      IllegalArgumentException - if the value does not match any enumeration constant
    • getStringArray

      public String[] getStringArray(String key, String[] defaultValues)
      Returns the value of the property with the specified name as a String array; or defaultValues if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValues - the default values
      Returns:
      the value of the property with the specified name as a String array; or defaultValues if no property with the specified name exists
    • getStringArray

      public String[] getStringArray(String key)
      Returns the value of the property as a String array, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property as an array
      Throws:
      PropertyNotFoundException - if the property was not found
    • getDoubleArray

      public double[] getDoubleArray(String key, double[] defaultValues)
      Returns the value of the property with the specified name as a double array; or defaultValues if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValues - the default values
      Returns:
      the value of the property with the specified name as a double array; or defaultValues if no property with the specified name exists
    • getDoubleArray

      public double[] getDoubleArray(String key)
      Returns the value of the property as a double array, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property as an array
      Throws:
      PropertyNotFoundException - if the property was not found
    • getFloatArray

      public float[] getFloatArray(String key, float[] defaultValues)
      Returns the value of the property with the specified name as a float array; or defaultValues if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValues - the default values
      Returns:
      the value of the property with the specified name as a float array; or defaultValues if no property with the specified name exists
    • getFloatArray

      public float[] getFloatArray(String key)
      Returns the value of the property as a float array, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property as an array
      Throws:
      PropertyNotFoundException - if the property was not found
    • getLongArray

      public long[] getLongArray(String key, long[] defaultValues)
      Returns the value of the property with the specified name as a long array; or defaultValues if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValues - the default values
      Returns:
      the value of the property with the specified name as a long array; or defaultValues if no property with the specified name exists
    • getLongArray

      public long[] getLongArray(String key)
      Returns the value of the property as a long array, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property as an array
      Throws:
      PropertyNotFoundException - if the property was not found
    • getIntArray

      public int[] getIntArray(String key, int[] defaultValues)
      Returns the value of the property with the specified name as an int array; or defaultValues if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValues - the default values
      Returns:
      the value of the property with the specified name as an int array; or defaultValues if no property with the specified name exists
    • getIntArray

      public int[] getIntArray(String key)
      Returns the value of the property as a int array, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property as an array
      Throws:
      PropertyNotFoundException - if the property was not found
    • getShortArray

      public short[] getShortArray(String key, short[] defaultValues)
      Returns the value of the property with the specified name as a short array; or defaultValues if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValues - the default values
      Returns:
      the value of the property with the specified name as a short array; or defaultValues if no property with the specified name exists
    • getShortArray

      public short[] getShortArray(String key)
      Returns the value of the property as a short array, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property as an array
      Throws:
      PropertyNotFoundException - if the property was not found
    • getByteArray

      public byte[] getByteArray(String key, byte[] defaultValues)
      Returns the value of the property with the specified name as a byte array; or defaultValues if no property with the specified name exists.
      Parameters:
      key - the property name
      defaultValues - the default values
      Returns:
      the value of the property with the specified name as a byte array; or defaultValues if no property with the specified name exists
    • getByteArray

      public byte[] getByteArray(String key)
      Returns the value of the property as a byte array, or throws an exception. One should either use the variant that takes a default value or check contains(String) to ensure the property exists.
      Parameters:
      key - the property name
      Returns:
      the value of the property as an array
      Throws:
      PropertyNotFoundException - if the property was not found
    • setString

      public void setString(String key, String value)
      Sets the value of the property to the given String.
      Parameters:
      key - the property name
      value - the property value
    • setFloat

      public void setFloat(String key, float value)
      Sets the value of the property to the given float.
      Parameters:
      key - the property name
      value - the property value
    • setDouble

      public void setDouble(String key, double value)
      Sets the value of the property to the given double.
      Parameters:
      key - the property name
      value - the property value
    • setByte

      public void setByte(String key, byte value)
      Sets the value of the property to the given byte.
      Parameters:
      key - the property name
      value - the property value
    • setShort

      public void setShort(String key, short value)
      Sets the value of the property to the given short.
      Parameters:
      key - the property name
      value - the property value
    • setInt

      public void setInt(String key, int value)
      Sets the value of the property to the given int.
      Parameters:
      key - the property name
      value - the property value
    • setLong

      public void setLong(String key, long value)
      Sets the value of the property to the given long.
      Parameters:
      key - the property name
      value - the property value
    • setBoolean

      public void setBoolean(String key, boolean value)
      Sets the value of the property to the given boolean.
      Parameters:
      key - the property name
      value - the property value
    • setEnum

      public <T extends Enum<?>> void setEnum(String key, T value)
      Sets the value of the property to the given enum value.
      Type Parameters:
      T - the type of the enum
      Parameters:
      key - the property name
      value - the property value
    • setStringArray

      public void setStringArray(String key, String[] values)
      Sets the value of the property with the specified name as a String array.
      Parameters:
      key - the property name
      values - the property value
    • setFloatArray

      public void setFloatArray(String key, float[] values)
      Sets the value of the property with the specified name as a float array.
      Parameters:
      key - the property name
      values - the property value
    • setDoubleArray

      public void setDoubleArray(String key, double[] values)
      Sets the value of the property with the specified name as a double array.
      Parameters:
      key - the property name
      values - the property value
    • setByteArray

      public void setByteArray(String key, byte[] values)
      Sets the value of the property with the specified name as a byte array.
      Parameters:
      key - the property name
      values - the property value
    • setShortArray

      public void setShortArray(String key, short[] values)
      Sets the value of the property with the specified name as a short array.
      Parameters:
      key - the property name
      values - the property value
    • setIntArray

      public void setIntArray(String key, int[] values)
      Sets the value of the property with the specified name as a int array.
      Parameters:
      key - the property name
      values - the property value
    • setLongArray

      public void setLongArray(String key, long[] values)
      Sets the value of the property with the specified name as a long array.
      Parameters:
      key - the property name
      values - the property value
    • clear

      public void clear()
      Clears all properties.
    • remove

      public void remove(String key)
      Removes the property with the specified name.
      Parameters:
      key - the property name
    • addAll

      public void addAll(Properties properties)
      Adds all properties from the specified properties object.
      Parameters:
      properties - the properties
    • addAll

      public void addAll(TypedProperties properties)
      Adds all properties from the specified properties object.
      Parameters:
      properties - the properties
    • size

      public int size()
      Returns the number of properties that are defined.
      Returns:
      the number of properties
    • isEmpty

      public boolean isEmpty()
      Returns true if there are no properties set.
      Returns:
      true if no properties are set; false otherwise
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • load

      public void load(Reader reader) throws IOException
      Loads the properties from a reader.
      Parameters:
      reader - the reader
      Throws:
      IOException - if an I/O error occurred
    • store

      public void store(Writer writer) throws IOException
      Writes the properties to a writer.
      Parameters:
      writer - the writer
      Throws:
      IOException - if an I/O error occurred
    • asTabularData

      public TabularData<Map.Entry<String,String>> asTabularData()
      Description copied from interface: Formattable
      Returns the contents of this object as a TabularData instance, which can be used to save, print, or format the data in various ways.
      Specified by:
      asTabularData in interface Formattable<Map.Entry<String,String>>
      Returns:
      the TabularData instance
    • clearAccessedProperties

      public void clearAccessedProperties()
      Clears the tracking information for properties that have been accessed.
    • getAccessedProperties

      public Set<String> getAccessedProperties()
      Returns the properties that were accessed since the last call to clearAccessedProperties() or clear().
      Returns:
      the accessed properties
    • getUnaccessedProperties

      public Set<String> getUnaccessedProperties()
      Returns the properties that were never accessed since the last call to clearAccessedProperties() or clear()
      Returns:
      the unaccessed or orphaned properties
    • warnIfUnaccessedProperties

      public void warnIfUnaccessedProperties()
      Prints a warning if any properties were not accessed. This only considers properties at the time this method is invoked, so a removed but unaccessed property would not cause a warning. For example:
           TypedProperties properties = new TypedProperties();
           ... write properties ...
           
           properties.clearAccessedProperties();
           ... read properties ...
           properties.warnIfUnaccessedProperties();
       
    • throwIfUnaccessedProperties

      public void throwIfUnaccessedProperties()
      Similar to warnIfUnaccessedProperties(), except throws a ConfigurationException if any properties were not accessed.
      Throws:
      ConfigurationException - if at least one property was not accessed
    • createScope

      public PropertyScope createScope()
      Creates a new scope that allows making temporary changes to the properties. When the scope is closed, the original properties are restored. Typically, you should create scopes within try-with-resources blocks so they are automatically closed.
      Returns:
      the scope