org.apache.commons.configuration
public class ConfigurationKey extends Object implements Serializable
A simple class that supports creation of and iteration on complex configuration keys.
For key creation the class works similar to a StringBuffer: There are
several appendXXXX()
methods with which single parts
of a key can be constructed. All these methods return a reference to the
actual object so they can be written in a chain. When using this methods
the exact syntax for keys need not be known.
This class also defines a specialized iterator for configuration keys. With such an iterator a key can be tokenized into its single parts. For each part it can be checked whether it has an associated index.
Version: $Id: ConfigurationKey.java 439648 2006-09-02 20:42:10Z oheger $
Nested Class Summary | |
---|---|
class | ConfigurationKey.KeyIterator
A specialized iterator class for tokenizing a configuration key.
|
Field Summary | |
---|---|
static String | ATTRIBUTE_END Constant for an attribute end marker. |
static String | ATTRIBUTE_START Constant for an attribute start marker. |
static String | ESCAPED_DELIMITER Constant for an escaped delimiter. |
static char | INDEX_END Constant for an index end marker. |
static char | INDEX_START Constant for an index start marker. |
static int | INITIAL_SIZE Constant for the initial StringBuffer size. |
StringBuffer | keyBuffer Holds a buffer with the so far created key. |
static char | PROPERTY_DELIMITER Constant for a property delimiter. |
static long | serialVersionUID
The serial version ID. |
Constructor Summary | |
---|---|
ConfigurationKey()
Creates a new, empty instance of ConfigurationKey . | |
ConfigurationKey(String key)
Creates a new instance of ConfigurationKey and
initializes it with the given key.
|
Method Summary | |
---|---|
ConfigurationKey | append(String property)
Appends the name of a property to this key. |
ConfigurationKey | appendAttribute(String attr)
Appends an attribute to this configuration key.
|
ConfigurationKey | appendIndex(int index)
Appends an index to this configuration key.
|
static String | attributeName(String key)
Extracts the name of the attribute from the given attribute key.
|
ConfigurationKey | commonKey(ConfigurationKey other)
Returns a configuration key object that is initialized with the part
of the key that is common to this key and the passed in key.
|
static String | constructAttributeKey(String key)
Decorates the given key so that it represents an attribute. |
ConfigurationKey | differenceKey(ConfigurationKey other)
Returns the "difference key" to a given key. |
boolean | equals(Object c)
Checks if two ConfigurationKey objects are equal. |
boolean | hasDelimiter()
Helper method that checks if the actual buffer ends with a property
delimiter.
|
int | hashCode()
Returns the hash code for this object.
|
boolean | isAttributeKey()
Checks if this key is an attribute key.
|
static boolean | isAttributeKey(String key)
Checks if the passed in key is an attribute key. |
ConfigurationKey.KeyIterator | iterator()
Returns an iterator for iterating over the single components of
this configuration key.
|
int | length()
Returns the actual length of this configuration key.
|
static boolean | partsEqual(ConfigurationKey.KeyIterator it1, ConfigurationKey.KeyIterator it2)
Helper method for comparing two key parts.
|
static String | removeAttributeMarkers(String key)
Helper method for removing attribute markers from a key.
|
void | removeTrailingDelimiter()
Removes a trailing delimiter if there is any. |
void | setLength(int len)
Sets the new length of this configuration key. |
String | toString()
Returns a string representation of this object. |
ConfigurationKey
.ConfigurationKey
and
initializes it with the given key.
Parameters: key the key as a string
Parameters: property the name of the property to be added
Returns: a reference to this object
Parameters: attr the name of the attribute to be appended
Returns: a reference to this object
Parameters: index the index to be appended
Returns: a reference to this object
Parameters: key the attribute key
Returns: the name of the corresponding attribute
Parameters: other the other key
Returns: a key object with the common key part
Parameters: key the key to be decorated
Returns: the decorated attribute key
other = key.commonKey(other) + key.differenceKey(other)
for an arbitrary configuration key key
.
Parameters: other the key for which the difference is to be calculated
Returns: the difference key
ConfigurationKey
objects are equal. The
method can be called with strings or other objects, too.
Parameters: c the object to compare
Returns: a flag if both objects are equal
Returns: a flag if there is a trailing delimiter
Returns: the hash code
Returns: a flag if this key is an attribute key
Parameters: key the key (part) to be checked
Returns: a flag if this key is an attribute key
Returns: an iterator for this key
Returns: the length of this key
Parameters: it1 the iterator with the first part it2 the iterator with the second part
Returns: a flag if both parts are equal
Parameters: key the key
Returns: the key with removed attribute markers
append()
methods. The semantic is the same as
the setLength()
method of StringBuffer
.
Parameters: len the new length of the key
Returns: a string for this object