org.jaffa.util
Class ListProperties

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byjava.util.Properties
              extended byorg.jaffa.util.ListProperties
All Implemented Interfaces:
Cloneable, Map, Serializable

public class ListProperties
extends Properties

This class combines the utility of the Properties class with a List. Features are: 1) Maintains the order of properties when loading them from an InputStream and when the properties are added manually. 2) Provides a sort capability for the properties 3) Provides a 'comments' attribute for each property 4) Stores the properties in an OutputStream, maintaining the order of the properties and the comments NOTE: Even though this class extends HashTable (since Properties extends HashTable), this implementation is not synchronized !!

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
ListProperties()
          Creates an empty property list with no default values.
ListProperties(Properties defaults)
          Creates an empty property list with the specified defaults.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 Object clone()
          Returns a clone of this object.
 boolean containsKey(Object key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(Object value)
          Returns true if this map maps one or more keys to the specified value.
 Enumeration elements()
          Returns an enumeration of the values in this hashtable.
 Set entrySet()
          Returns a set view of the mappings contained in this map.
 boolean equals(Object o)
          Compares the specified object with this map for equality.
 Object get(Object key)
          Returns the value to which this map maps the specified key.
 String getComments(String key)
          Returns the comments for the property.
 String getProperty(String key)
          Searches for the property with the specified key in this property list.
 String getProperty(String key, String defaultValue)
          Searches for the property with the specified key in this property list.
 int hashCode()
          Returns the hash code value for this map.
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 Enumeration keys()
          Returns an enumeration of the keys in this hashtable.
 Set keySet()
          Returns a set view of the keys contained in this map.
 void list(PrintStream out)
          Prints this property list out to the specified output stream.
 void list(PrintWriter out)
          Prints this property list out to the specified output stream.
 void load(InputStream inStream)
          Reads a property list (key and element pairs) from the input stream.
 Enumeration propertyNames()
          Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.
 Object put(Object key, Object value)
          Adds an object to the Map.
 void putAll(Map t)
          Copies all of the mappings from the specified map to this map.
 Object remove(Object key)
          Removes the mapping for this key from this map if it is present.
 void setComments(String key, String comments)
          Sets the comments for the property.
 Object setProperty(String key, String value)
          Adds a new property, or updates if it already exists.
 Object setProperty(String key, String value, String comments)
          Adds a new property, or updates if it already exists.
 int size()
          Returns the number of key-value mappings in this map.
 void sort()
          This sorts the Properties based on the keys.
 void store(OutputStream out, String header)
          Writes this property list (key and element pairs) in this Properties table to the output stream.
 String toString()
          Returns debug info.
 Collection values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class java.util.Properties
save
 
Methods inherited from class java.util.Hashtable
contains, rehash
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListProperties

public ListProperties()
Creates an empty property list with no default values.


ListProperties

public ListProperties(Properties defaults)
Creates an empty property list with the specified defaults.

Parameters:
defaults - The defaults.
Method Detail

sort

public void sort()
This sorts the Properties based on the keys.


getComments

public String getComments(String key)
Returns the comments for the property.

Parameters:
key - The key used for adding the property.
Returns:
the comments for the property.

setComments

public void setComments(String key,
                        String comments)
Sets the comments for the property. Nothing will be done, in case there is no existing property for the input key.

Parameters:
key - The key used for adding the property.
comments - The comments for the property.

setProperty

public Object setProperty(String key,
                          String value,
                          String comments)
Adds a new property, or updates if it already exists.

Parameters:
key - The key for the property.
value - The value for the property.
comments - The comment for the property.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

toString

public String toString()
Returns debug info.

Returns:
debug info.

load

public void load(InputStream inStream)
          throws IOException
Reads a property list (key and element pairs) from the input stream.

Parameters:
inStream - the input stream
Throws:
IOException - if an error occurred when reading from the input stream.

setProperty

public Object setProperty(String key,
                          String value)
Adds a new property, or updates if it already exists.

Parameters:
key - The key for the property.
value - The value for the property.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

getProperty

public String getProperty(String key)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.

Parameters:
key - the property key.
Returns:
the value in this property list with the specified key value.

getProperty

public String getProperty(String key,
                          String defaultValue)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.

Parameters:
key - the property key.
defaultValue - a default value.
Returns:
the value in this property list with the specified key value.

propertyNames

public Enumeration propertyNames()
Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Returns:
an enumeration of all the keys in this property list, including the keys in the default property list.

store

public void store(OutputStream out,
                  String header)
           throws IOException
Writes this property list (key and element pairs) in this Properties table to the output stream. Properties from the defaults table of this Properties table (if any) are not written out by this method. After the entries have been written, the output stream is flushed. The output stream remains open after this method returns.

Parameters:
out - an output stream.
header - a description of the property list.
Throws:
IOException - if writing this property list to the specified output stream throws an IOException.

list

public void list(PrintStream out)
Prints this property list out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

list

public void list(PrintWriter out)
Prints this property list out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

put

public Object put(Object key,
                  Object value)
Adds an object to the Map. If the map previously contained a mapping for this key, the old value is replaced by the specified value. An IllegalArgumentException is thrown if either of the key and value are not Strings.

Parameters:
key - The key used for adding the object.
value - The object to be added.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.

remove

public Object remove(Object key)
Removes the mapping for this key from this map if it is present. The default mappings are not touched.

Parameters:
key - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

keySet

public Set keySet()
Returns a set view of the keys contained in this map. The keys from the default mappings are not part of the Set.

Returns:
a set view of the keys contained in this map.

clear

public void clear()
Removes all mappings from this map. The default mappings are not touched.


values

public Collection values()
Returns a collection view of the values contained in this map. The values from the default mappings are not part of the Collection.

Returns:
a collection view of the values contained in this map.

hashCode

public int hashCode()
Returns the hash code value for this map. The hashCode will not take into account the comments, if any. The default mappings do not affect the return value.

Returns:
the hash code value for this map.

containsKey

public boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key. The default mappings are not searched for the key.

Parameters:
key - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.

size

public int size()
Returns the number of key-value mappings in this map. The default mappings are not included in the result.

Returns:
the number of key-value mappings in this map.

entrySet

public Set entrySet()
Returns a set view of the mappings contained in this map. The entries from the default mappings are not part of the Set.

Returns:
a set view of the mappings contained in this map.

containsValue

public boolean containsValue(Object value)
Returns true if this map maps one or more keys to the specified value. The default mappings are not searched for the value.

Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.

putAll

public void putAll(Map t)
Copies all of the mappings from the specified map to this map. This will invoke the put() method for each entry from the specified map. An IllegalArgumentException is thrown if either of the key and value are not Strings.

Parameters:
t - Mappings to be stored in this map.

equals

public boolean equals(Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a ListProperties and the two Properties represent the same mappings. The comments are not compared. The default mappings are not compared.

Parameters:
o - object to be compared for equality with this map.
Returns:
true if the specified object is equal to this map.

isEmpty

public boolean isEmpty()
Returns true if this map contains no key-value mappings. The default mappings have no effect on the return value.

Returns:
true if this map contains no key-value mappings.

get

public Object get(Object key)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases. The default mappings are not searched for the key.

Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.

elements

public Enumeration elements()
Returns an enumeration of the values in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially. The values from the default mappings are not part of the Enumeration.

Returns:
an enumeration of the values in this hashtable.

keys

public Enumeration keys()
Returns an enumeration of the keys in this hashtable. The keys from the default mappings are not part of the Enumeration.

Returns:
an enumeration of the keys in this hashtable.

clone

public Object clone()
Returns a clone of this object.

Returns:
a clone of the Map.


Copyright © 2002-2004 JAFFA Project.