org.apache.commons.collections
クラス ExtendedProperties

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--org.apache.commons.collections.ExtendedProperties
すべての実装インタフェース:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class ExtendedProperties
extends java.util.Hashtable

This class extends normal Java properties by adding the possibility to use the same key many times concatenating the value strings instead of overwriting them.

The Extended Properties syntax is explained here:

Here is an example of a valid extended properties file:

      # lines starting with # are comments

      # This is the simplest property
      key = value

      # A long property may be separated on multiple lines
      longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
                  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

      # This is a property with many tokens
      tokens_on_a_line = first token, second token

      # This sequence generates exactly the same result
      tokens_on_multiple_lines = first token
      tokens_on_multiple_lines = second token

      # commas may be escaped in tokens
      commas.excaped = Hi\, what'up?
 

NOTE: this class has not been written for performance nor low memory usage. In fact, it's way slower than it could be and generates too much memory garbage. But since performance is not an issue during intialization (and there is not much time to improve it), I wrote it this way. If you don't like it, go ahead and tune it up!

バージョン:
$Id: ExtendedProperties.java,v 1.4 2001/05/13 21:46:22 geirm Exp $
作成者:
Stefano Mazzocchi, Jon S. Stevens, Dave Bryson, Jason van Zyl, Geir Magnusson Jr., Leon Messerschmidt, Kent Johnson, Daniel Rall, Ilkka Priha
関連項目:
直列化された形式

クラス java.util.Map から継承した内部クラス
java.util.Map.Entry
 
コンストラクタの概要
ExtendedProperties()
          Creates an empty extended properties object.
ExtendedProperties(java.lang.String file)
          Creates and loads the extended properties from the specified file.
ExtendedProperties(java.lang.String file, java.lang.String defaultFile)
          Creates and loads the extended properties from the specified file.
 
メソッドの概要
 void addProperty(java.lang.String key, java.lang.Object token)
          Add a property to the configuration.
 void clearProperty(java.lang.String key)
          Clear a property in the configuration.
 void combine(ExtendedProperties c)
          Combines an existing Hashtable with this Hashtable.
static ExtendedProperties convertProperties(java.util.Properties p)
          Convert a standard properties class into a configuration class.
 void display()
          Display the configuration for debugging purposes.
 boolean getBoolean(java.lang.String key)
          Get a boolean associated with the given configuration key.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Get a boolean associated with the given configuration key.
 java.lang.Boolean getBoolean(java.lang.String key, java.lang.Boolean defaultValue)
          Get a boolean associated with the given configuration key.
 byte getByte(java.lang.String key)
          Get a byte associated with the given configuration key.
 byte getByte(java.lang.String key, byte defaultValue)
          Get a byte associated with the given configuration key.
 java.lang.Byte getByte(java.lang.String key, java.lang.Byte defaultValue)
          Get a byte associated with the given configuration key.
 double getDouble(java.lang.String key)
          Get a double associated with the given configuration key.
 double getDouble(java.lang.String key, double defaultValue)
          Get a double associated with the given configuration key.
 java.lang.Double getDouble(java.lang.String key, java.lang.Double defaultValue)
          Get a double associated with the given configuration key.
 float getFloat(java.lang.String key)
          Get a float associated with the given configuration key.
 float getFloat(java.lang.String key, float defaultValue)
          Get a float associated with the given configuration key.
 java.lang.Float getFloat(java.lang.String key, java.lang.Float defaultValue)
          Get a float associated with the given configuration key.
 java.lang.String getInclude()
          Gets the property value for including other properties files.
 int getInt(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as an integer.
 int getInt(java.lang.String name, int def)
          The purpose of this method is to get the configuration resource with the given name as an integer, or a default value.
 int getInteger(java.lang.String key)
          Get a int associated with the given configuration key.
 int getInteger(java.lang.String key, int defaultValue)
          Get a int associated with the given configuration key.
 java.lang.Integer getInteger(java.lang.String key, java.lang.Integer defaultValue)
          Get a int associated with the given configuration key.
 java.util.Iterator getKeys()
          Get the list of the keys contained in the configuration repository.
 java.util.Iterator getKeys(java.lang.String prefix)
          Get the list of the keys contained in the configuration repository that match the specified prefix.
 long getLong(java.lang.String key)
          Get a long associated with the given configuration key.
 long getLong(java.lang.String key, long defaultValue)
          Get a long associated with the given configuration key.
 java.lang.Long getLong(java.lang.String key, java.lang.Long defaultValue)
          Get a long associated with the given configuration key.
 java.util.Properties getProperties(java.lang.String key)
          Get a list of properties associated with the given configuration key.
 java.util.Properties getProperties(java.lang.String key, java.util.Properties defaults)
          Get a list of properties associated with the given configuration key.
 java.lang.Object getProperty(java.lang.String key)
          Gets a property from the configuration.
 short getShort(java.lang.String key)
          Get a short associated with the given configuration key.
 short getShort(java.lang.String key, short defaultValue)
          Get a short associated with the given configuration key.
 java.lang.Short getShort(java.lang.String key, java.lang.Short defaultValue)
          Get a short associated with the given configuration key.
 java.lang.String getString(java.lang.String key)
          Get a string associated with the given configuration key.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Get a string associated with the given configuration key.
 java.lang.String[] getStringArray(java.lang.String key)
          Get an array of strings associated with the given configuration key.
 java.util.Vector getVector(java.lang.String key)
          Get a Vector of strings associated with the given configuration key.
 java.util.Vector getVector(java.lang.String key, java.util.Vector defaultValue)
          Get a Vector of strings associated with the given configuration key.
 boolean isInitialized()
          Indicate to client code whether property resources have been initialized or not.
 void load(java.io.InputStream input)
          Load the properties from the given input stream.
 void load(java.io.InputStream input, java.lang.String enc)
          Load the properties from the given input stream and using the specified encoding.
 void save(java.io.OutputStream output, java.lang.String Header)
          Save the properties to the given outputstream.
 void setInclude(java.lang.String inc)
          Sets the property value for including other properties files.
 void setProperty(java.lang.String key, java.lang.Object value)
          Set a property, this will replace any previously set values.
 ExtendedProperties subset(java.lang.String prefix)
          Create an ExtendedProperties object that is a subset of this one.
 java.lang.String testBoolean(java.lang.String value)
          Test whether the string represent by value maps to a boolean value or not.
 
クラス java.util.Hashtable から継承したメソッド
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, remove, size, toString, values
 
クラス java.lang.Object から継承したメソッド
getClass, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

ExtendedProperties

public ExtendedProperties()
Creates an empty extended properties object.

ExtendedProperties

public ExtendedProperties(java.lang.String file)
                   throws java.io.IOException
Creates and loads the extended properties from the specified file.
パラメータ:
file - A String.
例外:
IOException. -  

ExtendedProperties

public ExtendedProperties(java.lang.String file,
                          java.lang.String defaultFile)
                   throws java.io.IOException
Creates and loads the extended properties from the specified file.
パラメータ:
file - A String.
例外:
IOException. -  
メソッドの詳細

addProperty

public void addProperty(java.lang.String key,
                        java.lang.Object token)
Add a property to the configuration. If it already exists then the value stated here will be added to the configuration entry. For example, if resource.loader = file is already present in the configuration and you addProperty("resource.loader", "classpath") Then you will end up with a Vector like the following: ["file", "classpath"]
パラメータ:
String - key
String - value

clearProperty

public void clearProperty(java.lang.String key)
Clear a property in the configuration.
パラメータ:
String - key to remove along with corresponding value.

combine

public void combine(ExtendedProperties c)
Combines an existing Hashtable with this Hashtable. Warning: It will overwrite previous entries without warning.
パラメータ:
ExtendedProperties -  

convertProperties

public static ExtendedProperties convertProperties(java.util.Properties p)
Convert a standard properties class into a configuration class.
パラメータ:
p - properties object to convert into a ExtendedProperties object.
戻り値:
ExtendedProperties configuration created from the properties object.

display

public void display()
Display the configuration for debugging purposes.

getBoolean

public boolean getBoolean(java.lang.String key)
Get a boolean associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated boolean.
例外:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Boolean.

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Get a boolean associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated boolean.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Boolean.

getBoolean

public java.lang.Boolean getBoolean(java.lang.String key,
                                    java.lang.Boolean defaultValue)
Get a boolean associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated boolean if key is found and has valid format, default value otherwise.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Boolean.

getByte

public byte getByte(java.lang.String key)
Get a byte associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated byte.
例外:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Byte.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getByte

public byte getByte(java.lang.String key,
                    byte defaultValue)
Get a byte associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated byte.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Byte.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getByte

public java.lang.Byte getByte(java.lang.String key,
                              java.lang.Byte defaultValue)
Get a byte associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated byte if key is found and has valid format, default value otherwise.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Byte.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

public double getDouble(java.lang.String key)
Get a double associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated double.
例外:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Double.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
Get a double associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated double.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Double.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

public java.lang.Double getDouble(java.lang.String key,
                                  java.lang.Double defaultValue)
Get a double associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated double if key is found and has valid format, default value otherwise.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Double.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

public float getFloat(java.lang.String key)
Get a float associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated float.
例外:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Float.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

public float getFloat(java.lang.String key,
                      float defaultValue)
Get a float associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated float.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Float.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

public java.lang.Float getFloat(java.lang.String key,
                                java.lang.Float defaultValue)
Get a float associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated float if key is found and has valid format, default value otherwise.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Float.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInclude

public java.lang.String getInclude()
Gets the property value for including other properties files. By default it is "include".
戻り値:
A String.

getInt

public int getInt(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as an integer.
パラメータ:
name - The resource name.
戻り値:
The value of the resource as an integer.

getInt

public int getInt(java.lang.String name,
                  int def)
The purpose of this method is to get the configuration resource with the given name as an integer, or a default value.
パラメータ:
name - The resource name
def - The default value of the resource.
戻り値:
The value of the resource as an integer.

getInteger

public int getInteger(java.lang.String key)
Get a int associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated int.
例外:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Integer.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInteger

public int getInteger(java.lang.String key,
                      int defaultValue)
Get a int associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated int.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Integer.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInteger

public java.lang.Integer getInteger(java.lang.String key,
                                    java.lang.Integer defaultValue)
Get a int associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated int if key is found and has valid format, default value otherwise.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Integer.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getKeys

public java.util.Iterator getKeys()
Get the list of the keys contained in the configuration repository.
戻り値:
An Iterator.

getKeys

public java.util.Iterator getKeys(java.lang.String prefix)
Get the list of the keys contained in the configuration repository that match the specified prefix.
パラメータ:
prefix - The prefix to test against.
戻り値:
An Iterator of keys that match the prefix.

getLong

public long getLong(java.lang.String key)
Get a long associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated long.
例外:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Long.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
Get a long associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated long.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Long.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getLong

public java.lang.Long getLong(java.lang.String key,
                              java.lang.Long defaultValue)
Get a long associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated long if key is found and has valid format, default value otherwise.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Long.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getProperties

public java.util.Properties getProperties(java.lang.String key)
Get a list of properties associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated properties if key is found.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String/Vector.
java.lang.IllegalArgumentException - if one of the tokens is malformed (does not contain an equals sign).

getProperties

public java.util.Properties getProperties(java.lang.String key,
                                          java.util.Properties defaults)
Get a list of properties associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated properties if key is found.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String/Vector.
java.lang.IllegalArgumentException - if one of the tokens is malformed (does not contain an equals sign).

getProperty

public java.lang.Object getProperty(java.lang.String key)
Gets a property from the configuration.
パラメータ:
key - property to retrieve
戻り値:
value as object. Will return user value if exists, if not then default value if exists, otherwise null

getShort

public short getShort(java.lang.String key)
Get a short associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated short.
例外:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Short.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getShort

public short getShort(java.lang.String key,
                      short defaultValue)
Get a short associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated short.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Short.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getShort

public java.lang.Short getShort(java.lang.String key,
                                java.lang.Short defaultValue)
Get a short associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated short if key is found and has valid format, default value otherwise.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Short.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getString

public java.lang.String getString(java.lang.String key)
Get a string associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated string.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String.

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Get a string associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated string if key is found, default value otherwise.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String.

getStringArray

public java.lang.String[] getStringArray(java.lang.String key)
Get an array of strings associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated string array if key is found.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String/Vector.

getVector

public java.util.Vector getVector(java.lang.String key)
Get a Vector of strings associated with the given configuration key.
パラメータ:
key - The configuration key.
戻り値:
The associated Vector.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Vector.

getVector

public java.util.Vector getVector(java.lang.String key,
                                  java.util.Vector defaultValue)
Get a Vector of strings associated with the given configuration key.
パラメータ:
key - The configuration key.
defaultValue - The default value.
戻り値:
The associated Vector.
例外:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a Vector.

isInitialized

public boolean isInitialized()
Indicate to client code whether property resources have been initialized or not.

load

public void load(java.io.InputStream input)
          throws java.io.IOException
Load the properties from the given input stream.
パラメータ:
input - An InputStream.
例外:
IOException. -  

load

public void load(java.io.InputStream input,
                 java.lang.String enc)
          throws java.io.IOException
Load the properties from the given input stream and using the specified encoding.
パラメータ:
input - An InputStream.
enc - An encoding.
例外:
IOException. -  

save

public void save(java.io.OutputStream output,
                 java.lang.String Header)
          throws java.io.IOException
Save the properties to the given outputstream.
パラメータ:
output - An OutputStream.
header - A String.
例外:
IOException. -  

setInclude

public void setInclude(java.lang.String inc)
Sets the property value for including other properties files. By default it is "include".
パラメータ:
inc - A String.

setProperty

public void setProperty(java.lang.String key,
                        java.lang.Object value)
Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key,value).
パラメータ:
String - key
String - value

subset

public ExtendedProperties subset(java.lang.String prefix)
Create an ExtendedProperties object that is a subset of this one. Take into account duplicate keys by using the setProperty() in ExtendedProperties.
パラメータ:
String - prefix

testBoolean

public java.lang.String testBoolean(java.lang.String value)
Test whether the string represent by value maps to a boolean value or not. We will allow true, on, and yes for a true boolean value, and false, off, and no for false boolean values. Case of value to test for boolean status is ignored.
パラメータ:
String - The value to test for boolean state.
戻り値:
true or false if the supplied text maps to a boolean value, or null otherwise.


Copyright © 2001 Apache Software Foundation. Documenation generated November 5 2001.