MOEA Framework 2.12
API Specification

org.moeaframework.util
Class TypedProperties

java.lang.Object
  extended by org.moeaframework.util.TypedProperties

public class TypedProperties
extends Object

Wrapper for Properties providing getters for reading specific primitive types. For primitive arrays, either the default "," separator or a custom separator is used for splitting the string into individual components; the formatting of this separator is defined in String.split(java.lang.String, int). In addition, whitespace surrounding each array entry is trimmed.


Field Summary
static String DEFAULT_SEPARATOR
          The default separator for arrays.
 
Constructor Summary
TypedProperties()
          Decorates an empty Properties object to provide type-safe access using the default "," separator for arrays.
TypedProperties(Properties properties)
          Decorates a Properties object to provide type-safe access using the default "," separator for arrays.
TypedProperties(Properties properties, String separator)
          Decorates a Properties object using the specified separator for arrays.
 
Method Summary
 void addAll(Properties properties)
          Adds all properties from the specified properties object.
 void addAll(TypedProperties properties)
          Adds all properties from the specified properties object.
 void clear()
          Clears all properties.
 boolean contains(String key)
          Returns true if the specified key is contained in this properties object; false otherwise.
 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 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[] 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 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[] 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.
 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[] 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 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[] 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 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[] 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.
 Properties getProperties()
          Returns the internal Properties object storing the actual key/value pairs.
 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[] 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.
 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.
 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.
 void remove(String key)
          Removes the property with the specified name.
 void setBoolean(String key, boolean value)
          Sets the value of the property with the specified name as a boolean.
 void setByte(String key, byte value)
          Sets the value of the property with the specified name as a 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 with the specified name as a double.
 void setDoubleArray(String key, double[] values)
          Sets the value of the property with the specified name as a double array.
 void setFloat(String key, float value)
          Sets the value of the property with the specified name as a 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 with the specified name as an 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 with the specified name as a 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 with the specified name as a 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 with the specified name as a String.
 void setStringArray(String key, String[] values)
          Sets the value of the property with the specified name as a String array.
static TypedProperties withProperty(String key, String value)
          Convenience method to quickly construct a typed properties instance with a single key-value pair.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SEPARATOR

public static final String DEFAULT_SEPARATOR
The default separator for arrays.

See Also:
Constant Field Values
Constructor Detail

TypedProperties

public TypedProperties()
Decorates an empty Properties object to provide type-safe access using the default "," separator for arrays.


TypedProperties

public TypedProperties(Properties properties)
Decorates a Properties object to provide type-safe access using the default "," separator for arrays.

Parameters:
properties - the existing Properties object

TypedProperties

public TypedProperties(Properties properties,
                       String separator)
Decorates a Properties object using the specified separator for arrays.

Parameters:
properties - the existing Properties object
separator - the separator for arrays
Method Detail

withProperty

public static TypedProperties withProperty(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.withProperty("epsilon", commandLine.getOptionValue("epsilon")).getDoubleArray("epsilon", null);

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

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

getProperties

public Properties getProperties()
Returns the internal Properties object storing the actual key/value pairs.

Returns:
the internal Properties object storing the actual key/value pairs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

setString

public void setString(String key,
                      String value)
Sets the value of the property with the specified name as a String.

Parameters:
key - the property name
value - the property value

setFloat

public void setFloat(String key,
                     float value)
Sets the value of the property with the specified name as a float.

Parameters:
key - the property name
value - the property value

setDouble

public void setDouble(String key,
                      double value)
Sets the value of the property with the specified name as a double.

Parameters:
key - the property name
value - the property value

setByte

public void setByte(String key,
                    byte value)
Sets the value of the property with the specified name as a byte.

Parameters:
key - the property name
value - the property value

setShort

public void setShort(String key,
                     short value)
Sets the value of the property with the specified name as a short.

Parameters:
key - the property name
value - the property value

setInt

public void setInt(String key,
                   int value)
Sets the value of the property with the specified name as an int.

Parameters:
key - the property name
value - the property value

setLong

public void setLong(String key,
                    long value)
Sets the value of the property with the specified name as a long.

Parameters:
key - the property name
value - the property value

setBoolean

public void setBoolean(String key,
                       boolean value)
Sets the value of the property with the specified name as a boolean.

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

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!