public final class OrderedProperties
extends java.lang.Object
implements java.io.Serializable
Properties class. It fixes the design flaw of using
inheritance over composition, while keeping up the same APIs as the original class. Keys and values are
guaranteed to be of type String.
This class is not synchronized, contrary to the original implementation.
As additional functionality, this class keeps its properties in a well-defined order. By default, the order
is the one in which the individual properties have been added, either through explicit API calls or through
reading them top-to-bottom from a properties file.
Also, an optional flag can be set to omit the comment that contains the current date when storing the
properties to a properties file.
Currently, this class does not support the concept of default properties, contrary to the original implementation.
Note that this implementation is not synchronized. If multiple threads access ordered
properties concurrently, and at least one of the threads modifies the ordered properties structurally, it
must be synchronized externally. This is typically accomplished by synchronizing on some object
that naturally encapsulates the properties.
Note that the actual (and quite complex) logic of parsing and storing properties from and to a stream
is delegated to the Properties class from the JDK.Properties,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
OrderedProperties.OrderedPropertiesBuilder
Builder for
OrderedProperties instances. |
| Constructor and Description |
|---|
OrderedProperties()
Creates a new instance that will keep the properties in the order they have been added.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsProperty(java.lang.String key)
Returns true if there is a property with the specified key.
|
static OrderedProperties |
copyOf(OrderedProperties source)
Creates a new instance that will have both the same property entries and
the same behavior as the given source.
|
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> |
entrySet()
See
Hashtable.entrySet(). |
boolean |
equals(java.lang.Object other) |
java.lang.String |
getProperty(java.lang.String key)
See
Properties.getProperty(String). |
java.lang.String |
getProperty(java.lang.String key,
java.lang.String defaultValue)
See
Properties.getProperty(String, String). |
int |
hashCode() |
boolean |
isEmpty()
See
Hashtable.isEmpty(). |
void |
list(java.io.PrintStream stream)
See
Properties.list(PrintStream). |
void |
list(java.io.PrintWriter writer)
See
Properties.list(PrintWriter). |
void |
load(java.io.InputStream stream)
See
Properties.load(InputStream). |
void |
load(java.io.Reader reader)
See
Properties.load(Reader). |
void |
loadFromXML(java.io.InputStream stream)
See
Properties.loadFromXML(InputStream). |
java.util.Enumeration<java.lang.String> |
propertyNames()
See
Properties.propertyNames(). |
java.lang.String |
removeProperty(java.lang.String key)
Removes the property with the specified key, if it is present.
|
java.lang.String |
setProperty(java.lang.String key,
java.lang.String value)
See
Properties.setProperty(String, String). |
int |
size()
See
Hashtable.size(). |
void |
store(java.io.OutputStream stream,
java.lang.String comments)
See
Properties.store(OutputStream, String). |
void |
store(java.io.Writer writer,
java.lang.String comments)
See
Properties.store(Writer, String). |
void |
storeToXML(java.io.OutputStream stream,
java.lang.String comment)
See
Properties.storeToXML(OutputStream, String). |
void |
storeToXML(java.io.OutputStream stream,
java.lang.String comment,
java.lang.String encoding)
See
Properties.storeToXML(OutputStream, String, String). |
java.util.Set<java.lang.String> |
stringPropertyNames()
See
Properties.stringPropertyNames(). |
java.util.Properties |
toJdkProperties()
Convert this instance to a
Properties instance. |
java.lang.String |
toString()
See
Hashtable.toString(). |
public OrderedProperties()
Properties class.public java.lang.String getProperty(java.lang.String key)
Properties.getProperty(String).public java.lang.String getProperty(java.lang.String key,
java.lang.String defaultValue)
Properties.getProperty(String, String).public java.lang.String setProperty(java.lang.String key,
java.lang.String value)
Properties.setProperty(String, String).public java.lang.String removeProperty(java.lang.String key)
key - the key of the property to removepublic boolean containsProperty(java.lang.String key)
key - the key whose presence is to be testedpublic int size()
Hashtable.size().public boolean isEmpty()
Hashtable.isEmpty().public java.util.Enumeration<java.lang.String> propertyNames()
Properties.propertyNames().public java.util.Set<java.lang.String> stringPropertyNames()
Properties.stringPropertyNames().public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
Hashtable.entrySet().public void load(java.io.InputStream stream)
throws java.io.IOException
Properties.load(InputStream).java.io.IOExceptionpublic void load(java.io.Reader reader)
throws java.io.IOException
Properties.load(Reader).java.io.IOExceptionpublic void loadFromXML(java.io.InputStream stream)
throws java.io.IOException,
java.util.InvalidPropertiesFormatException
Properties.loadFromXML(InputStream).java.io.IOExceptionjava.util.InvalidPropertiesFormatExceptionpublic void store(java.io.OutputStream stream,
java.lang.String comments)
throws java.io.IOException
Properties.store(OutputStream, String).java.io.IOExceptionpublic void store(java.io.Writer writer,
java.lang.String comments)
throws java.io.IOException
Properties.store(Writer, String).java.io.IOExceptionpublic void storeToXML(java.io.OutputStream stream,
java.lang.String comment)
throws java.io.IOException
Properties.storeToXML(OutputStream, String).java.io.IOExceptionpublic void storeToXML(java.io.OutputStream stream,
java.lang.String comment,
java.lang.String encoding)
throws java.io.IOException
Properties.storeToXML(OutputStream, String, String).java.io.IOExceptionpublic void list(java.io.PrintStream stream)
Properties.list(PrintStream).public void list(java.io.PrintWriter writer)
Properties.list(PrintWriter).public java.util.Properties toJdkProperties()
Properties instance.Properties instancepublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
Hashtable.toString().toString in class java.lang.Objectpublic static OrderedProperties copyOf(OrderedProperties source)
source - the source to copy from