Class DefaultConfigurationKey.KeyIterator
java.lang.Object
org.apache.commons.configuration2.tree.DefaultConfigurationKey.KeyIterator
- Enclosing class:
DefaultConfigurationKey
public class DefaultConfigurationKey.KeyIterator
extends Object
implements Iterator<Object>, 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
FieldsModifier and TypeFieldDescriptionprivate boolean
Stores a flag if the actual property is an attribute.private String
Stores the current key name.private int
Stores the end index of the actual token.private boolean
Stores a flag if the actual property has an index.private int
Stores the index of the actual property if there is one.private int
Stores the start index of the actual token. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
checkAttribute
(String key) Helper method for checking if the passed key is an attribute.private boolean
checkIndex
(String key) Helper method for checking if the passed key contains an index.clone()
Creates a clone of this object.Returns the current key of the iteration (without skipping to the next element).currentKey
(boolean decorated) Returns the current key of the iteration (without skipping to the next element).private int
escapedPosition
(String key, int pos) Checks if a delimiter at the specified position is escaped.private int
Determines the relative offset of an escaped delimiter in relation to a delimiter.private String
Helper method for determining the next indices.int
getIndex()
Gets the index value of the current key.boolean
hasIndex()
Returns a flag if the current key has an associated index.boolean
hasNext()
Checks if there is a next element.boolean
Returns a flag if the current key is an attribute.private boolean
Returns a flag whether attributes are marked the same way as normal property keys.boolean
Returns a flag whether the current key refers to a property (i.e.next()
Returns the next object in the iteration.private int
nextDelimiterPos
(String key, int pos, int endPos) Searches the next unescaped delimiter from the given position.nextKey()
Returns the next key part of this configuration key.nextKey
(boolean decorated) Returns the next key part of this configuration key.private String
Helper method for extracting the next key part.void
remove()
Removes the current object in the iteration.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
current
Stores the current key name. -
startIndex
private int startIndexStores the start index of the actual token. -
endIndex
private int endIndexStores the end index of the actual token. -
indexValue
private int indexValueStores the index of the actual property if there is one. -
hasIndex
private boolean hasIndexStores a flag if the actual property has an index. -
attribute
private boolean attributeStores a flag if the actual property is an attribute.
-
-
Constructor Details
-
KeyIterator
public KeyIterator()
-
-
Method Details
-
nextKey
Returns the next key part of this configuration key. This is a short form ofnextKey(false)
.- Returns:
- the next key part
-
nextKey
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
-
hasNext
public boolean hasNext()Checks if there is a next element. -
next
Returns the next object in the iteration. -
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. -
currentKey
Returns the current key of the iteration (without skipping to the next element). This is the same key the previousnext()
call had returned. (Short form ofcurrentKey(false)
.- Returns:
- the current key
-
currentKey
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
-
isAttribute
public boolean isAttribute()Returns a flag if the current key is an attribute. This method can be called afternext()
.- Returns:
- a flag if the current key is an attribute
-
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 ofisAttribute()
, 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:
-
getIndex
public int getIndex()Gets 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 afternext()
.- 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 afternext()
.- Returns:
- a flag if the current key has an index
-
clone
Creates a clone of this object. -
findNextIndices
Helper method for determining the next indices.- Returns:
- the next key part
-
nextKeyPart
Helper method for extracting the next key part. Takes escaping of delimiter characters into account.- Returns:
- the next key part
-
nextDelimiterPos
Searches the next unescaped delimiter from the given position.- Parameters:
key
- the keypos
- the start positionendPos
- the end position- Returns:
- the position of the next delimiter or -1 if there is none
-
escapedPosition
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 checkpos
- 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
-
checkAttribute
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
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
-
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
-