Class Properties

java.lang.Object
org.apache.commons.configuration2.event.BaseEventSource
org.apache.commons.configuration2.AbstractConfiguration
org.apache.commons.configuration2.BaseConfiguration
org.apache.commons.configuration2.PropertiesConfiguration
it.unimi.dsi.util.Properties
All Implemented Interfaces:
Serializable, Cloneable, org.apache.commons.configuration2.Configuration, org.apache.commons.configuration2.event.EventSource, org.apache.commons.configuration2.FileBasedConfiguration, org.apache.commons.configuration2.ImmutableConfiguration, org.apache.commons.configuration2.io.FileBased, org.apache.commons.configuration2.io.FileLocatorAware, org.apache.commons.configuration2.sync.SynchronizerSupport

public class Properties extends org.apache.commons.configuration2.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:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.commons.configuration2.PropertiesConfiguration

    org.apache.commons.configuration2.PropertiesConfiguration.DefaultIOFactory, org.apache.commons.configuration2.PropertiesConfiguration.IOFactory, org.apache.commons.configuration2.PropertiesConfiguration.JupIOFactory, org.apache.commons.configuration2.PropertiesConfiguration.JupPropertiesReader, org.apache.commons.configuration2.PropertiesConfiguration.JupPropertiesWriter, org.apache.commons.configuration2.PropertiesConfiguration.PropertiesReader, org.apache.commons.configuration2.PropertiesConfiguration.PropertiesWriter
  • Field Summary

    Fields inherited from class org.apache.commons.configuration2.PropertiesConfiguration

    DEFAULT_ENCODING, DEFAULT_INCLUDE_LISTENER, NOOP_INCLUDE_LISTENER
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
    Properties(InputStream inputStream)
     
    Properties(String filename)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAll(org.apache.commons.configuration2.Configuration configuration)
    Adds all properties from the given configuration.
    void
    addProperties(Enum<?> key, String[] s)
     
    void
     
    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, short s)
     
    void
    addProperty(Enum<?> key, Object arg)
     
    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
    Returns true if the provided object is equal to this set of properties.
     
     
     
     
    boolean
    getBoolean(Enum<?> key)
     
    boolean
    getBoolean(Enum<?> key, boolean arg)
     
    getBoolean(Enum<?> key, Boolean arg)
     
    byte
    getByte(Enum<?> key)
     
    byte
    getByte(Enum<?> key, byte arg)
     
    getByte(Enum<?> key, Byte arg)
     
    double
    getDouble(Enum<?> key)
     
    double
    getDouble(Enum<?> key, double arg)
     
    getDouble(Enum<?> key, Double arg)
     
    float
    getFloat(Enum<?> key)
     
    float
    getFloat(Enum<?> key, float arg)
     
    getFloat(Enum<?> key, Float arg)
     
    int
    getInt(Enum<?> key)
     
    int
    getInt(Enum<?> key, int arg)
     
    getInteger(Enum<?> key, Integer arg)
     
    getKeys(Enum<?> key)
     
    List<?>
    getList(Enum<?> key)
     
    getList(Enum<?> key, List<Object> arg)
     
    long
    getLong(Enum<?> key)
     
    long
    getLong(Enum<?> key, long arg)
     
    getLong(Enum<?> key, Long arg)
     
     
     
    getProperty(Enum<?> key)
     
    short
    getShort(Enum<?> key)
     
    short
    getShort(Enum<?> key, short arg)
     
    getShort(Enum<?> key, Short arg)
     
    getString(Enum<?> key)
     
    getString(Enum<?> key, String arg)
     
     
    int
     
    void
    load(File file)
    Loads a configuration from a specified file.
    void
    Loads a configuration from an input stream.
    void
    load(CharSequence filename)
    Loads a configuration from a specified file.
    void
    save(File file)
    Saves the configuration to the specified file.
    void
    Saves the configuration to an output stream.
    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, short s)
     
    void
    setProperty(Enum<?> key, Object arg)
     
    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)
     
    org.apache.commons.configuration2.Configuration
    subset(Enum<?> key)
     
     

    Methods inherited from class org.apache.commons.configuration2.PropertiesConfiguration

    clone, getFooter, getHeader, getInclude, getIncludeListener, getIncludeOptional, getIOFactory, getLayout, initFileLocator, isIncludesAllowed, read, setFooter, setHeader, setInclude, setIncludeListener, setIncludeOptional, setIncludesAllowed, setIOFactory, setLayout, unescapeJava, unescapeJava, write

    Methods inherited from class org.apache.commons.configuration2.BaseConfiguration

    addPropertyDirect, clearInternal, clearPropertyDirect, containsKeyInternal, getKeysInternal, getPropertyInternal, isEmptyInternal, sizeInternal

    Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration

    addErrorLogListener, addProperty, addPropertyInternal, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, containsKey, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeys, getKeysInternal, getKeysInternal, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setPropertyInternal, setSynchronizer, setThrowExceptionOnMissing, size, subset, unlock

    Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource

    addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.commons.configuration2.Configuration

    addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty, subset

    Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration

    containsKey, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getEnum, getEnum, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getKeys, getKeys, getList, getList, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, immutableSubset, isEmpty, size

    Methods inherited from interface org.apache.commons.configuration2.sync.SynchronizerSupport

    getSynchronizer, lock, setSynchronizer, unlock
  • Constructor Details

    • Properties

      public Properties()
    • Properties

      public Properties(String filename) throws org.apache.commons.configuration2.ex.ConfigurationException
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
    • Properties

      public Properties(File file) throws org.apache.commons.configuration2.ex.ConfigurationException
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
    • Properties

      public Properties(URL url) throws org.apache.commons.configuration2.ex.ConfigurationException
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
    • Properties

      public Properties(InputStream inputStream) throws org.apache.commons.configuration2.ex.ConfigurationException
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
  • Method Details

    • save

      public void save(CharSequence filename) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
      Saves the configuration to the specified file.
      Parameters:
      filename - a file name.
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
      IOException
    • save

      public void save(File file) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
      Saves the configuration to the specified file.
      Parameters:
      file - a file.
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
      IOException
    • save

      public void save(OutputStream os) throws org.apache.commons.configuration2.ex.ConfigurationException
      Saves the configuration to an output stream.
      Parameters:
      os - an output stream.
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
    • load

      public void load(CharSequence filename) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
      Loads a configuration from a specified file.
      Parameters:
      filename - a file name.
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
      IOException
    • load

      public void load(File file) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
      Loads a configuration from a specified file.
      Parameters:
      file - a file.
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
      IOException
    • load

      public void load(InputStream is) throws org.apache.commons.configuration2.ex.ConfigurationException
      Loads a configuration from an input stream.
      Parameters:
      is - an input stream.
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
    • addAll

      public void addAll(org.apache.commons.configuration2.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<Object> getList(Enum<?> key, List<Object> 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 org.apache.commons.configuration2.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 with 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.