org.apache.commons.configuration.tree

Class DefaultConfigurationKey.KeyIterator

public class DefaultConfigurationKey.KeyIterator extends Object implements Iterator, Cloneable

A specialized iterator class for tokenizing a configuration key. This class implements the normal iterator interface. In addition it provides some specific methods for configuration keys.
Field Summary
booleanattribute
Stores a flag if the actual property is an attribute.
Stringcurrent
Stores the current key name.
intendIndex
Stores the end index of the actual token.
booleanhasIndex
Stores a flag if the actual property has an index.
intindexValue
Stores the index of the actual property if there is one.
intstartIndex
Stores the start index of the actual token.
Method Summary
booleancheckAttribute(String key)
Helper method for checking if the passed key is an attribute.
booleancheckIndex(String key)
Helper method for checking if the passed key contains an index.
Objectclone()
Creates a clone of this object.
StringcurrentKey()
Returns the current key of the iteration (without skipping to the next element).
StringcurrentKey(boolean decorated)
Returns the current key of the iteration (without skipping to the next element).
intescapedPosition(String key, int pos)
Checks if a delimiter at the specified position is escaped.
intescapeOffset()
Determines the relative offset of an escaped delimiter in relation to a delimiter.
StringfindNextIndices()
Helper method for determining the next indices.
intgetIndex()
Returns the index value of the current key.
booleanhasIndex()
Returns a flag if the current key has an associated index.
booleanhasNext()
Checks if there is a next element.
booleanisAttribute()
Returns a flag if the current key is an attribute.
booleanisAttributeEmulatingMode()
Returns a flag whether attributes are marked the same way as normal property keys.
booleanisPropertyKey()
Returns a flag whether the current key refers to a property (i.e. is no special attribute key).
Objectnext()
Returns the next object in the iteration.
intnextDelimiterPos(String key, int pos, int endPos)
Searches the next unescaped delimiter from the given position.
StringnextKey()
Returns the next key part of this configuration key.
StringnextKey(boolean decorated)
Returns the next key part of this configuration key.
StringnextKeyPart()
Helper method for extracting the next key part.
voidremove()
Removes the current object in the iteration.

Field Detail

attribute

private boolean attribute
Stores a flag if the actual property is an attribute.

current

private String current
Stores the current key name.

endIndex

private int endIndex
Stores the end index of the actual token.

hasIndex

private boolean hasIndex
Stores a flag if the actual property has an index.

indexValue

private int indexValue
Stores the index of the actual property if there is one.

startIndex

private int startIndex
Stores the start index of the actual token.

Method Detail

checkAttribute

private boolean checkAttribute(String key)
Helper method for checking if the passed key is an attribute. If this is the case, the internal fields will be set.

Parameters: key the key to be checked

Returns: a flag if the key is an attribute

checkIndex

private boolean checkIndex(String key)
Helper method for checking if the passed key contains an index. If this is the case, internal fields will be set.

Parameters: key the key to be checked

Returns: a flag if an index is defined

clone

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

Returns: a clone of this object

currentKey

public String currentKey()
Returns the current key of the iteration (without skipping to the next element). This is the same key the previous next() call had returned. (Short form of currentKey(false).

Returns: the current key

currentKey

public String currentKey(boolean decorated)
Returns the current key of the iteration (without skipping to the next element). The boolean parameter indicates wheter a decorated key should be returned. This affects only attribute keys: if the parameter is false, the attribute markers are stripped from the key; if it is true, they remain.

Parameters: decorated a flag if the decorated key is to be returned

Returns: the current key

escapedPosition

private int escapedPosition(String key, int pos)
Checks if a delimiter at the specified position is escaped. If this is the case, the next valid search position will be returned. Otherwise the return value is -1.

Parameters: key the key to check pos the position where a delimiter was found

Returns: information about escaped delimiters

escapeOffset

private int escapeOffset()
Determines the relative offset of an escaped delimiter in relation to a delimiter. Depending on the used delimiter and escaped delimiter tokens the position where to search for an escaped delimiter is different. If, for instance, the dot character (".") is used as delimiter, and a doubled dot ("..") as escaped delimiter, the escaped delimiter starts at the same position as the delimiter. If the token "\." was used, it would start one character before the delimiter because the delimiter character "." is the second character in the escaped delimiter string. This relation will be determined by this method. For this to work the delimiter string must be contained in the escaped delimiter string.

Returns: the relative offset of the escaped delimiter in relation to a delimiter

findNextIndices

private String findNextIndices()
Helper method for determining the next indices.

Returns: the next key part

getIndex

public int getIndex()
Returns the index value of the current key. If the current key does not have an index, return value is -1. This method can be called after next().

Returns: the index value of the current key

hasIndex

public boolean hasIndex()
Returns a flag if the current key has an associated index. This method can be called after next().

Returns: a flag if the current key has an index

hasNext

public boolean hasNext()
Checks if there is a next element.

Returns: a flag if there is a next element

isAttribute

public boolean isAttribute()
Returns a flag if the current key is an attribute. This method can be called after next().

Returns: a flag if the current key is an attribute

isAttributeEmulatingMode

private boolean isAttributeEmulatingMode()
Returns a flag whether attributes are marked the same way as normal property keys. We call this the "attribute emulating mode". When navigating through node hierarchies it might be convenient to treat attributes the same way than other child nodes, so an expression engine supports to set the attribute markers to the same value than the property delimiter. If this is the case, some special checks have to be performed.

Returns: a flag if attributes and normal property keys are treated the same way

isPropertyKey

public boolean isPropertyKey()
Returns a flag whether the current key refers to a property (i.e. is no special attribute key). Usually this method will return the opposite of isAttribute(), but if the delimiters for normal properties and attributes are set to the same string, it is possible that both methods return true.

Returns: a flag if the current key is a property key

See Also: isAttribute

next

public Object next()
Returns the next object in the iteration.

Returns: the next object

nextDelimiterPos

private int nextDelimiterPos(String key, int pos, int endPos)
Searches the next unescaped delimiter from the given position.

Parameters: key the key pos the start position endPos the end position

Returns: the position of the next delimiter or -1 if there is none

nextKey

public String nextKey()
Returns the next key part of this configuration key. This is a short form of nextKey(false).

Returns: the next key part

nextKey

public String nextKey(boolean decorated)
Returns the next key part of this configuration key. The boolean parameter indicates wheter a decorated key should be returned. This affects only attribute keys: if the parameter is false, the attribute markers are stripped from the key; if it is true, they remain.

Parameters: decorated a flag if the decorated key is to be returned

Returns: the next key part

nextKeyPart

private String nextKeyPart()
Helper method for extracting the next key part. Takes escaping of delimiter characters into account.

Returns: the next key part

remove

public void remove()
Removes the current object in the iteration. This method is not supported by this iterator type, so an exception is thrown.