it.unimi.dsi.util
Class Properties

java.lang.Object
  extended by org.apache.commons.configuration.event.EventSource
      extended by org.apache.commons.configuration.AbstractConfiguration
          extended by org.apache.commons.configuration.BaseConfiguration
              extended by org.apache.commons.configuration.AbstractFileConfiguration
                  extended by org.apache.commons.configuration.PropertiesConfiguration
                      extended by it.unimi.dsi.util.Properties
All Implemented Interfaces:
Serializable, Cloneable, Configuration, FileConfiguration

public class Properties
extends PropertiesConfiguration
implements Serializable

An extension of PropertiesConfiguration providing setters for primitive types, a simpler way to save preferences and transparent handling of Enum lowercased keys.

All accessors defined in PropertiesConfiguration have a polymorphic counterpart taking an Enum instead of a string: Enum.name() and String.toLowerCase() are applied before delegating to the corresponding string-based method. (This apparently wierd choice is due to the need to accommodate the upper-case standard for Enum elements and the lower-case standard for property keys.)

Additionally, instances of this class can be serialised.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.commons.configuration.PropertiesConfiguration
PropertiesConfiguration.PropertiesReader, PropertiesConfiguration.PropertiesWriter
 
Field Summary
 
Fields inherited from class org.apache.commons.configuration.AbstractFileConfiguration
autoSave, basePath, EVENT_RELOAD, fileName, strategy
 
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN
 
Constructor Summary
Properties()
           
Properties(File file)
           
Properties(String filename)
           
Properties(URL url)
           
 
Method Summary
 void addAll(Configuration configuration)
          Adds all properties from the given configuration.
 void addProperties(Enum<?> key, String[] s)
           
 void addProperties(String key, String[] s)
           
 void addProperty(Enum<?> key, boolean b)
           
 void addProperty(Enum<?> key, byte b)
           
 void addProperty(Enum<?> key, char c)
           
 void addProperty(Enum<?> key, double d)
           
 void addProperty(Enum<?> key, float f)
           
 void addProperty(Enum<?> key, int i)
           
 void addProperty(Enum<?> key, long l)
           
 void addProperty(Enum<?> key, Object arg)
           
 void addProperty(Enum<?> key, short s)
           
 void addProperty(String key, boolean b)
           
 void addProperty(String key, byte b)
           
 void addProperty(String key, char c)
           
 void addProperty(String key, double d)
           
 void addProperty(String key, float f)
           
 void addProperty(String key, int i)
           
 void addProperty(String key, long l)
           
 void addProperty(String key, short s)
           
 boolean containsKey(Enum<?> key)
           
 boolean equals(Object o)
          Returns true if the provided object is equal to this set of properties.
 BigDecimal getBigDecimal(Enum<?> key)
           
 BigDecimal getBigDecimal(Enum<?> key, BigDecimal arg)
           
 BigInteger getBigInteger(Enum<?> key)
           
 BigInteger getBigInteger(Enum<?> key, BigInteger arg)
           
 boolean getBoolean(Enum<?> key)
           
 boolean getBoolean(Enum<?> key, boolean arg)
           
 Boolean getBoolean(Enum<?> key, Boolean arg)
           
 byte getByte(Enum<?> key)
           
 byte getByte(Enum<?> key, byte arg)
           
 Byte getByte(Enum<?> key, Byte arg)
           
 double getDouble(Enum<?> key)
           
 double getDouble(Enum<?> key, double arg)
           
 Double getDouble(Enum<?> key, Double arg)
           
 float getFloat(Enum<?> key)
           
 float getFloat(Enum<?> key, float arg)
           
 Float getFloat(Enum<?> key, Float arg)
           
 int getInt(Enum<?> key)
           
 int getInt(Enum<?> key, int arg)
           
 Integer getInteger(Enum<?> key, Integer arg)
           
 Iterator<?> getKeys(Enum<?> key)
           
 List<?> getList(Enum<?> key)
           
 List<?> getList(Enum<?> key, List<?> arg)
           
 long getLong(Enum<?> key)
           
 long getLong(Enum<?> key, long arg)
           
 Long getLong(Enum<?> key, Long arg)
           
 Properties getProperties(Enum<?> key)
           
 Properties getProperties(Enum<?> key, Properties arg)
           
 Object getProperty(Enum<?> key)
           
 short getShort(Enum<?> key)
           
 short getShort(Enum<?> key, short arg)
           
 Short getShort(Enum<?> key, Short arg)
           
 String getString(Enum<?> key)
           
 String getString(Enum<?> key, String arg)
           
 String[] getStringArray(Enum<?> key)
           
 int hashCode()
           
 void save(CharSequence filename)
          Saves the configuration to the specified file.
 void setProperty(Enum<?> key, boolean b)
           
 void setProperty(Enum<?> key, byte b)
           
 void setProperty(Enum<?> key, char b)
           
 void setProperty(Enum<?> key, double d)
           
 void setProperty(Enum<?> key, float f)
           
 void setProperty(Enum<?> key, int i)
           
 void setProperty(Enum<?> key, long l)
           
 void setProperty(Enum<?> key, Object arg)
           
 void setProperty(Enum<?> key, short s)
           
 void setProperty(String key, boolean b)
           
 void setProperty(String key, byte b)
           
 void setProperty(String key, char b)
           
 void setProperty(String key, double d)
           
 void setProperty(String key, float f)
           
 void setProperty(String key, int i)
           
 void setProperty(String key, long l)
           
 void setProperty(String key, short s)
           
 Configuration subset(Enum<?> key)
           
 String toString()
           
 
Methods inherited from class org.apache.commons.configuration.PropertiesConfiguration
clone, createLayout, getEncoding, getHeader, getInclude, getIncludesAllowed, getLayout, load, save, setBasePath, setHeader, setInclude, setIncludesAllowed, setLayout, unescapeJava
 
Methods inherited from class org.apache.commons.configuration.AbstractFileConfiguration
addProperty, clearProperty, containsKey, enterNoReload, exitNoReload, fireEvent, getBasePath, getFile, getFileName, getKeys, getPath, getProperty, getReloadingStrategy, getURL, isAutoSave, isEmpty, load, load, load, load, load, load, possiblySave, reload, save, save, save, save, save, save, setAutoSave, setEncoding, setFile, setFileName, setPath, setProperty, setReloadingStrategy, setURL
 
Methods inherited from class org.apache.commons.configuration.BaseConfiguration
addPropertyDirect, clear, clearPropertyDirect
 
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration
addErrorLogListener, append, copy, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getList, getList, getListDelimiter, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, getSubstitutor, interpolate, interpolate, interpolatedConfiguration, interpolateHelper, isDelimiterParsingDisabled, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setLogger, setThrowExceptionOnMissing, subset
 
Methods inherited from class org.apache.commons.configuration.event.EventSource
addConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, createErrorEvent, createEvent, fireError, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEvents
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.configuration.Configuration
clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, subset
 

Constructor Detail

Properties

public Properties()

Properties

public Properties(String filename)
           throws ConfigurationException
Throws:
ConfigurationException

Properties

public Properties(File file)
           throws ConfigurationException
Throws:
ConfigurationException

Properties

public Properties(URL url)
           throws ConfigurationException
Throws:
ConfigurationException
Method Detail

save

public void save(CharSequence filename)
          throws ConfigurationException,
                 IOException
Saves the configuration to the specified file.

Parameters:
filename - a file name.
Throws:
ConfigurationException
IOException

addAll

public void addAll(Configuration configuration)
Adds all properties from the given configuration.

Properties from the new configuration will clear properties from the first one.

Parameters:
configuration - a configuration.

addProperties

public void addProperties(String key,
                          String[] s)

addProperty

public void addProperty(String key,
                        boolean b)

setProperty

public void setProperty(String key,
                        boolean b)

addProperty

public void addProperty(String key,
                        byte b)

setProperty

public void setProperty(String key,
                        byte b)

addProperty

public void addProperty(String key,
                        short s)

setProperty

public void setProperty(String key,
                        short s)

addProperty

public void addProperty(String key,
                        char c)

setProperty

public void setProperty(String key,
                        char b)

addProperty

public void addProperty(String key,
                        int i)

setProperty

public void setProperty(String key,
                        int i)

addProperty

public void addProperty(String key,
                        long l)

setProperty

public void setProperty(String key,
                        long l)

addProperty

public void addProperty(String key,
                        float f)

setProperty

public void setProperty(String key,
                        float f)

addProperty

public void addProperty(String key,
                        double d)

setProperty

public void setProperty(String key,
                        double d)

addProperties

public void addProperties(Enum<?> key,
                          String[] s)

addProperty

public void addProperty(Enum<?> key,
                        boolean b)

setProperty

public void setProperty(Enum<?> key,
                        boolean b)

addProperty

public void addProperty(Enum<?> key,
                        byte b)

setProperty

public void setProperty(Enum<?> key,
                        byte b)

addProperty

public void addProperty(Enum<?> key,
                        short s)

setProperty

public void setProperty(Enum<?> key,
                        short s)

addProperty

public void addProperty(Enum<?> key,
                        char c)

setProperty

public void setProperty(Enum<?> key,
                        char b)

addProperty

public void addProperty(Enum<?> key,
                        int i)

setProperty

public void setProperty(Enum<?> key,
                        int i)

addProperty

public void addProperty(Enum<?> key,
                        long l)

setProperty

public void setProperty(Enum<?> key,
                        long l)

addProperty

public void addProperty(Enum<?> key,
                        float f)

setProperty

public void setProperty(Enum<?> key,
                        float f)

addProperty

public void addProperty(Enum<?> key,
                        double d)

setProperty

public void setProperty(Enum<?> key,
                        double d)

containsKey

public boolean containsKey(Enum<?> key)

getProperty

public Object getProperty(Enum<?> key)

addProperty

public void addProperty(Enum<?> key,
                        Object arg)

getBigDecimal

public BigDecimal getBigDecimal(Enum<?> key,
                                BigDecimal arg)

getBigDecimal

public BigDecimal getBigDecimal(Enum<?> key)

getBigInteger

public BigInteger getBigInteger(Enum<?> key,
                                BigInteger arg)

getBigInteger

public BigInteger getBigInteger(Enum<?> key)

getBoolean

public boolean getBoolean(Enum<?> key,
                          boolean arg)

getBoolean

public Boolean getBoolean(Enum<?> key,
                          Boolean arg)

getBoolean

public boolean getBoolean(Enum<?> key)

getByte

public byte getByte(Enum<?> key,
                    byte arg)

getByte

public Byte getByte(Enum<?> key,
                    Byte arg)

getByte

public byte getByte(Enum<?> key)

getDouble

public double getDouble(Enum<?> key,
                        double arg)

getDouble

public Double getDouble(Enum<?> key,
                        Double arg)

getDouble

public double getDouble(Enum<?> key)

getFloat

public float getFloat(Enum<?> key,
                      float arg)

getFloat

public Float getFloat(Enum<?> key,
                      Float arg)

getFloat

public float getFloat(Enum<?> key)

getInt

public int getInt(Enum<?> key,
                  int arg)

getInt

public int getInt(Enum<?> key)

getInteger

public Integer getInteger(Enum<?> key,
                          Integer arg)

getKeys

public Iterator<?> getKeys(Enum<?> key)

getList

public List<?> getList(Enum<?> key,
                       List<?> arg)

getList

public List<?> getList(Enum<?> key)

getLong

public long getLong(Enum<?> key,
                    long arg)

getLong

public Long getLong(Enum<?> key,
                    Long arg)

getLong

public long getLong(Enum<?> key)

getProperties

public Properties getProperties(Enum<?> key,
                                Properties arg)

getProperties

public Properties getProperties(Enum<?> key)

getShort

public short getShort(Enum<?> key,
                      short arg)

getShort

public Short getShort(Enum<?> key,
                      Short arg)

getShort

public short getShort(Enum<?> key)

getString

public String getString(Enum<?> key,
                        String arg)

getString

public String getString(Enum<?> key)

getStringArray

public String[] getStringArray(Enum<?> key)

setProperty

public void setProperty(Enum<?> key,
                        Object arg)

subset

public Configuration subset(Enum<?> key)

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Returns true if the provided object is equal to this set of properties.

Equality between set of properties happens when the keys are the same, and the list of strings associated to each key is the same. Note that the order in which different keys appear in a property file is irrelevant, but the order between properties with the same key is significant.

Due to the strictness of the check (e.g., no number conversion is performed) this method is mainly useful when writing tests.

Overrides:
equals in class Object
Returns:
true if the argument is equal to this set of properties.