ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Inner Classes | Public Methods | Protected Fields | Protected Methods | List of all members
StringTree< T >.Walker Class Reference
Collaboration diagram for StringTree< T >.Walker:
[legend]

Class Description


This public, inner class implements an iterator that does not apply to the concept of standard Java iterators. The rational for this is the fact that the class provides mechanics to sorting the child nodes, which requires allocation of quite more resources than a usual container iterator. Therefore objects of this type are not supposed to be passed around and copied on the fly. Instead, instances should rather created once and then re-used in subsequent iterations.

Sorting of child nodes can be done using a built-in comparison function which works on the child names (path names) and allows to choose ascending and descending order and to ignore letter case, respectively be sensitive about it. Besides this, a custom comparison function for child name based sorting can be established as well as a custom function used to sort by attributes of the custom template type T. See methods sortByPathname and sortByValue for details on sorting.

Objects of this type can initialized, respectively reset to distinct start nodes by providing objects of type

to overloaded methods setStart. Then the iteration is performed with method next and its end is detected with method isValid. During iteration, method Skip stops the iteration of the current node and continues with its next sibling.

Recursiveness of iteration is controlled with method setRecursionDepth.

Finally, the generation of a string representing the actual path to the current iteration node relative to the start node can be activated. See pathGeneration for information about this feature.

For more information on iterators see description of outer class StringTree.

Inner Classes

class  NameAndNode
 
class  RecursionData
 
class  Sorter
 

Public Methods

 Walker ()
 
int depth ()
 
Cursor getCursor ()
 
AString getPath (AString target)
 
AString getPath (AString target, CurrentData targetData)
 
AString getPathToNode ()
 
StringTree< T > getStringTree ()
 
void invalidate ()
 
boolean isInvalid ()
 
boolean isValid ()
 
String name ()
 
boolean next ()
 
void pathGeneration (Switch generatePath)
 
void setRecursionDepth (int _recursionDepth)
 
void setStart ()
 
void setStart (Cursor cursor)
 
void setStart (Walker other)
 
void setValue (T value)
 
int size ()
 
void skip ()
 
void sortByPathname (Comparator< String > pathSorter)
 
void sortByPathname (SortOrder order)
 
void sortByPathname (SortOrder order, Case sensitivity)
 
void sortByValue (Comparator< T > valueSorter)
 
value ()
 

Protected Fields

AString actPath = new AString()
 
int recursionDepth = Integer.MAX_VALUE
 
Sorter sorter = new Sorter()
 
ArrayList< RecursionDatastack = new ArrayList<RecursionData>()
 
int stackSize = 0
 

Protected Methods

Node actNode ()
 
void setStart (StringTree< T >.Node newNode)
 

Constructor & Destructor Documentation

◆ Walker()

Walker ( )

Constructor

Member Function Documentation

◆ actNode()

Node actNode ( )
protected

Internal method to identify the actual node.

Returns
Pointer to the node object that we currently represent.

◆ depth()

int depth ( )

Returns the depth of the current iteration. This is value is available to the algorithm which means this method executes in constant time.

To get the absolute depth of the current node, use a combination of method getCursor and Cursor.depth.

Returns
The distance of the current node and the node of the start of the iteration.

◆ getCursor()

Cursor getCursor ( )

Creates a cursor referencing the same node that this walker references.

Returns
A cursor object referencing the current node.

◆ getPath() [1/2]

AString getPath ( AString  target)

Overloaded version providing default value CurrentData.CLEAR for paramter targetData.

Parameters
targetThe target to append the path to.
Returns
The given string to allow concatenated operations

◆ getPath() [2/2]

AString getPath ( AString  target,
CurrentData  targetData 
)

Writes the results of getPathToNode and name, separated by a separator char.

Note that this method can be used only if path generation was activated prior to the current iteration. Activation is performed with method pathGeneration.

Parameters
targetThe target to append the path to.
targetDataDenotes whether target should be cleared prior to appending the path. Defaults to CurrentData.Clear.
Returns
The given string to allow concatenated operations

◆ getPathToNode()

AString getPathToNode ( )

Retrieves the current path of walking as a string representation. The path returned is relative to the start node and does not contain a leading separator character. Also, it does not contain the name of the current node, which can be received with method name.

Note that this method can be used only if path generation was activated prior to the current iteration. Activation is performed with method pathGeneration.

Note, that the AString returned must not be modified by the receiver.

Returns
The path of the current node.

◆ getStringTree()

StringTree<T> getStringTree ( )

Return the StringTree we are working on.

Returns
The StringTree object.

◆ invalidate()

void invalidate ( )

Invalidates this object. After invoking this method, this walker can not be used further, until setStart is invoked. After the invocation, method isValid will return false.

◆ isInvalid()

boolean isInvalid ( )

Returns the opposite of isValid.

Returns
true if this is an invalid cursor that must not be used, false otherwise.

◆ isValid()

boolean isValid ( )

Determines if this is a valid walker. Walkers may become invalid after invocations of method next at the end of the iteration and become valid with the invocation of one of the overloaded methods setStart (when invoked with valid objects).

Returns
true if this is a valid cursor. If invalid, false is returned and the cursor must not be used.

◆ name()

String name ( )

Returns the name of the node that this walker currently represents. The name of the node corresponds to the path segment or child name that was used to create it.

Note
Unlike method Cursor.searchName which needs some effort to search the name of a node represented by a cursor, this method performs in constant time, as the current child name is made available during iteration.
Returns
The name of the represented node.

◆ next()

boolean next ( )

Goes to the next node.

Returns
The result of isValid after the 'walk'.

◆ pathGeneration()

void pathGeneration ( Switch  generatePath)

With this method, the generation of the actual path string is activated. The given character is used as separation character. The current path can be received using method getPath.
The method must be invoked prior to start walking with method next, otherwise undefined behavior might occur while 'walking'.

Parameters
generatePathDenotes whether the path should be generated or not.

◆ setRecursionDepth()

void setRecursionDepth ( int  _recursionDepth)

Sets the requested recursion dept. A value of 0 or negative sets unlimited recursion depth.
Please note the explanation of recursion depth parameter in section Recursive Iteration of the parent class description.

Parameters
_recursionDepthSets the new recursion dept. Use 0 for unlimited recursion.

◆ setStart() [1/4]

void setStart ( )

Resets this walker to work with the root node of its outer StringTree.

◆ setStart() [2/4]

void setStart ( Cursor  cursor)

Resets this walker to represent the node that the given cursor object represents.

Parameters
cursorThe cursor to copy the represented node from.

◆ setStart() [3/4]

void setStart ( StringTree< T >.Node  newNode)
protected

Resets this walker to represent to the given node.

Parameters
newNodeThe new node to start from

◆ setStart() [4/4]

void setStart ( Walker  other)

Resets this walker to represent the same node that the given other walker object represents.

Parameters
otherThe walker to copy the represented node from.

◆ setValue()

void setValue ( value)

Sets the given value to the actual node object.

Parameters
valueThe value to set.

◆ size()

int size ( )

Returns the number of direct children of the currently represented node.

Returns
The number of children of the represented node.

◆ skip()

void skip ( )

Skips remaining children of the current node and continues with its next sibling.

◆ sortByPathname() [1/3]

void sortByPathname ( Comparator< String >  pathSorter)

Sets the sorting of children by their path name, using the given delegate.

Overloaded methods, which allow different sorting mechanics exist. This method should be invoked prior to the invocation of one of the setStart methods which start the iteration. Invocation during iteration is allowed, but only nodes that have not been visited yet will be affected by the new sorting.

Parameters
pathSorterA custom comparison method used for sorting the children of the nodes.

◆ sortByPathname() [2/3]

void sortByPathname ( SortOrder  order)

Overloaded version providing default value Case.IGNORE for parameter sensitivity.

Parameters
orderThe sort order. Defaults to SortOrder.Ascending.

◆ sortByPathname() [3/3]

void sortByPathname ( SortOrder  order,
Case  sensitivity 
)

Sets the sorting of children by their path name, using the built-in comparison method, which in turn uses C# method String.Compare.

Overloaded methods, which allow different sorting mechanics exist. This method should be invoked prior to the invocation of one of the setStart methods which start the iteration. Invocation during iteration is allowed, but only nodes that have not been visited yet will be affected by the new sorting.

Parameters
orderThe sort order.
sensitivityDenotes whether sorting is case sensitive or not. Defaults to Case.IGNORE.

◆ sortByValue()

void sortByValue ( Comparator< T >  valueSorter)

Sets the sorting of children by their template value, using the given delegate.

Overloaded methods, which allow different sorting mechanics exist. This method should be invoked prior to the invocation of one of the setStart methods which start the iteration. Invocation during iteration is allowed, but only nodes that have not been visited yet will be affected by the new sorting.

Parameters
valueSorterA custom comparison method used for sorting the children of the nodes.

◆ value()

T value ( )

Retrieves the current StringTree nodes value.

Returns
The current StringTree node templated, custom value.

Member Data Documentation

◆ actPath

AString actPath = new AString()
protected

The path to the actual node (excluding the name of the actual node).

◆ recursionDepth

int recursionDepth = Integer.MAX_VALUE
protected

The requested depth of iteration recursion.

◆ sorter

Sorter sorter = new Sorter()
protected

The sorter object. This is a fixed member of the parent class providing a method to sort children by name or value type T.

◆ stack

ArrayList<RecursionData> stack = new ArrayList<RecursionData>()
protected

A stack holding the recursive list of child maps and the idx of their current child. Implemented as a vector in combination with member stackSize, to reuse allocated storage space.

◆ stackSize

int stackSize = 0
protected

The current use of the stack.


The documentation for this class was generated from the following file: