org.pf.util
Class OrderedProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by org.pf.util.OrderedProperties
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>
Direct Known Subclasses:
PropertiesFileContent

public class OrderedProperties
extends java.util.Properties

Represents a properties collection with empty lines and comments. The order will be preserved. DO NOT USE THE NORMAL METHODS INHERITED FROM java.util.Hashtable except those that are explicitly overridden in this class!

Version:
1.0
Author:
Manfred Duchrow
See Also:
Serialized Form

Constructor Summary
OrderedProperties()
          Initialize the new instance with default values.
OrderedProperties(int initialCapacity)
          Initialize the new instance with an initial capacity.
 
Method Summary
 void clear()
          Removes all properties
 boolean deleteProperty(java.lang.String name)
          Deletes the property with the specified name.
 java.util.Set entrySet()
          Returns all entries in the order they have been added
 java.lang.String getProperty(java.lang.String name)
          Returns the value of the property with the given name or null if it is not found.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Searches for the property with the specified key in this property list.
 java.lang.String[] getPropertyNames()
          Returns an array containing the properties names in the order they have been added or read from a stream.
 java.util.Enumeration keys()
          Returns all keys of this properties list in the order they have been added.
 java.util.Set keySet()
          Returns all keys of this properties list in the order they have been added.
 void list(java.io.PrintStream out)
          NOT SUPPORTED METHOD!
 void list(java.io.PrintWriter out)
          NOT SUPPORTED METHOD!
 void load(java.io.InputStream inStream)
          NOT SUPPORTED METHOD!
 java.util.Enumeration propertyNames()
          Returns an enumeration of the properties names in the order they have been added or read from a stream.
 java.lang.Object remove(java.lang.Object key)
          Removes the key (and its corresponding value) from this hashtable.
 void save(java.io.OutputStream out, java.lang.String header)
          NOT SUPPORTED METHOD!
 java.lang.Object setProperty(java.lang.String name, java.lang.String value)
          Modifies the value or adds the property specified by the given name.
 int size()
          Returns how many elements are contained.
 void store(java.io.OutputStream out, java.lang.String header)
          NOT SUPPORTED METHOD!
 
Methods inherited from class java.util.Properties
loadFromXML, storeToXML, storeToXML
 
Methods inherited from class java.util.Hashtable
clone, contains, containsKey, containsValue, elements, equals, get, hashCode, isEmpty, put, putAll, toString, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderedProperties

public OrderedProperties()
Initialize the new instance with default values.


OrderedProperties

public OrderedProperties(int initialCapacity)
Initialize the new instance with an initial capacity.

Method Detail

getPropertyNames

public java.lang.String[] getPropertyNames()
Returns an array containing the properties names in the order they have been added or read from a stream.


size

public int size()
Returns how many elements are contained.

Specified by:
size in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
size in class java.util.Hashtable<java.lang.Object,java.lang.Object>

getProperty

public java.lang.String getProperty(java.lang.String name)
Returns the value of the property with the given name or null if it is not found.

Overrides:
getProperty in class java.util.Properties
Parameters:
name - The name of the property to look for

setProperty

public java.lang.Object setProperty(java.lang.String name,
                                    java.lang.String value)
Modifies the value or adds the property specified by the given name. Returns true the previous value if the property was found and modified or null if the property was added.

Overrides:
setProperty in class java.util.Properties
Parameters:
name - The name of the property to set
value - The new value to be set

deleteProperty

public boolean deleteProperty(java.lang.String name)
Deletes the property with the specified name. Returns true if the property was deleted, otherwise false.

Parameters:
name - The name of the property to delete

remove

public java.lang.Object remove(java.lang.Object key)
Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not found.

Specified by:
remove in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
remove in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
the value to which the key had been mapped, or null if the key did not have a mapping.

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.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 method returns the default value argument.

Overrides:
getProperty in class java.util.Properties

list

public void list(java.io.PrintStream out)
NOT SUPPORTED METHOD!

Overrides:
list in class java.util.Properties
Throws:
java.lang.UnsupportedOperationException

list

public void list(java.io.PrintWriter out)
NOT SUPPORTED METHOD!

Overrides:
list in class java.util.Properties
Throws:
java.lang.UnsupportedOperationException

load

public void load(java.io.InputStream inStream)
          throws java.io.IOException
NOT SUPPORTED METHOD!

Overrides:
load in class java.util.Properties
Throws:
java.lang.UnsupportedOperationException
java.io.IOException

propertyNames

public java.util.Enumeration propertyNames()
Returns an enumeration of the properties names in the order they have been added or read from a stream.

Be aware that the returned enumeration is NOT backed by this OrderedProperties object!

Overrides:
propertyNames in class java.util.Properties

save

public void save(java.io.OutputStream out,
                 java.lang.String header)
NOT SUPPORTED METHOD!

Overrides:
save in class java.util.Properties
Throws:
java.lang.UnsupportedOperationException

store

public void store(java.io.OutputStream out,
                  java.lang.String header)
           throws java.io.IOException
NOT SUPPORTED METHOD!

Overrides:
store in class java.util.Properties
Throws:
java.lang.UnsupportedOperationException
java.io.IOException

clear

public void clear()
Removes all properties

Specified by:
clear in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
clear in class java.util.Hashtable<java.lang.Object,java.lang.Object>

keys

public java.util.Enumeration keys()
Returns all keys of this properties list in the order they have been added.

Overrides:
keys in class java.util.Hashtable<java.lang.Object,java.lang.Object>

keySet

public java.util.Set keySet()
Returns all keys of this properties list in the order they have been added.

Specified by:
keySet in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
keySet in class java.util.Hashtable<java.lang.Object,java.lang.Object>

entrySet

public java.util.Set entrySet()
Returns all entries in the order they have been added

Specified by:
entrySet in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
entrySet in class java.util.Hashtable<java.lang.Object,java.lang.Object>