Class OrderedProperties
java.lang.Object
com.jsql.view.swing.dialog.translate.OrderedProperties
This class provides an alternative to the JDK's
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.- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionCreates a new instance that will keep the properties in the order they have been added. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsProperty
(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.entrySet()
boolean
getProperty
(String key) getProperty
(String key, String defaultValue) int
hashCode()
boolean
isEmpty()
SeeProperties.isEmpty()
.void
list
(PrintStream stream) void
list
(PrintWriter writer) void
load
(InputStream stream) void
void
loadFromXML
(InputStream stream) removeProperty
(String key) Removes the property with the specified key, if it is present.setProperty
(String key, String value) int
size()
SeeProperties.size()
.void
store
(OutputStream stream, String comments) void
void
storeToXML
(OutputStream stream, String comment) void
storeToXML
(OutputStream stream, String comment, String encoding) Convert this instance to aProperties
instance.toString()
-
Constructor Details
-
OrderedProperties
public OrderedProperties()Creates a new instance that will keep the properties in the order they have been added. Other than the ordering of the keys, this instance behaves like an instance of theProperties
class.
-
-
Method Details
-
getProperty
-
getProperty
-
setProperty
-
removeProperty
Removes the property with the specified key, if it is present. Returns the value of the property, or null if there was no property with the specified key.- Parameters:
key
- the key of the property to remove- Returns:
- the previous value of the property, or null if there was no property with the specified key
-
containsProperty
Returns true if there is a property with the specified key.- Parameters:
key
- the key whose presence is to be tested
-
size
public int size()SeeProperties.size()
. -
isEmpty
public boolean isEmpty()SeeProperties.isEmpty()
. -
propertyNames
-
stringPropertyNames
-
entrySet
-
load
- Throws:
IOException
-
load
- Throws:
IOException
-
loadFromXML
- Throws:
IOException
-
store
- Throws:
IOException
-
store
- Throws:
IOException
-
storeToXML
- Throws:
IOException
-
storeToXML
- Throws:
IOException
-
list
-
list
-
toJdkProperties
Convert this instance to aProperties
instance.- Returns:
- the
Properties
instance
-
equals
-
hashCode
public int hashCode() -
toString
-
copyOf
Creates a new instance that will have both the same property entries and the same behavior as the given source. Note that the source instance and the copy instance will share the same comparator instance if a custom ordering had been configured on the source.- Parameters:
source
- the source to copy from- Returns:
- the copy
-