|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.openbp.common.util.iterator.CascadeIterator
public class CascadeIterator
This class provides an iterator over a treelike structure. It does this by using the
Composite-pattern: a component (node) can either be composite (map or a collection)
or a leaf (everything else). A composite contains components itself (again either
comosites or leaves) and so on, forming a treelike structure with leaves at the ends.
This class creates an iterator over all LEAVES of such a structure. An optional
second parameter (keyOrValue) specifies whether the iterator should return keys or values
of maps.
KeyOrValue can either be KEY, VALUE, or a positive integer.
KEY:
The iterator traverses all keys of maps (which usually means it does not go
beyond the first map/collection encountered)
VALUE (Default):
the iterator traverses all leaves of the structure (theoretically to any depth)\n
positive Integer n:
This is somewhat tricky. The class traverses the first n levels of the structure for values,
and if an element on the n+1'th level is a map/collection, it returns it's keys (see example).
Example:
| Field Summary | |
|---|---|
static int |
KEY
Iterate through keys. |
static int |
VALUE
Iterate through values. |
| Constructor Summary | |
|---|---|
CascadeIterator()
Default constructor |
|
| Method Summary | |
|---|---|
protected java.util.Iterator |
getCustomIterator(java.lang.Object obj,
int modus)
This method checks if the object is of a known type that can be iterated. |
protected java.util.Iterator |
getIterator(java.lang.Object next,
int modus)
This static method returns an iterator over any given object. |
boolean |
hasNext()
Returns true if there are elements left. |
protected CascadeIterator |
init(java.lang.Object target)
Creates an iterator over the given object. |
protected CascadeIterator |
init(java.lang.Object[] targets)
Creates an iterator over an array of Objects, chaining their values together. |
protected CascadeIterator |
init(java.lang.Object[] targets,
int keyOrValue)
Creates an iterator over an array of Objects, chaining their values together. |
protected CascadeIterator |
init(java.lang.Object target,
int keyOrValue)
Creates an iterator over the given object. |
java.util.Iterator |
iterator(java.lang.Object obj)
Convenience method for iterating values (as opposed to keys). |
java.util.Iterator |
iterator(java.lang.Object[] objs,
int modus)
Iterate over a given object-array. |
java.util.Iterator |
iterator(java.lang.Object obj,
int modus)
Iterate over a given object. |
static void |
main(java.lang.String[] args)
Main method for test. |
java.lang.Object |
next()
Returns the next Element of the iterator and advances the internal counter. |
void |
remove()
Always throws an UnsupportedOperationException: removal is not supported by this iterator. |
protected void |
stepAhead()
Internally used method to advance the pointer to the next element. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int KEY
public static final int VALUE
| Constructor Detail |
|---|
public CascadeIterator()
| Method Detail |
|---|
protected CascadeIterator init(java.lang.Object target)
target - The object to iterate
protected CascadeIterator init(java.lang.Object target,
int keyOrValue)
target - The object to iteratekeyOrValue - Whether keys or values of maps should be traversed
protected CascadeIterator init(java.lang.Object[] targets)
targets - The object-array
protected CascadeIterator init(java.lang.Object[] targets,
int keyOrValue)
targets - the object-arraykeyOrValue - Return keys or values in hastables
public boolean hasNext()
hasNext in interface java.util.Iteratorpublic java.lang.Object next()
next in interface java.util.Iteratorpublic void remove()
remove in interface java.util.Iteratorprotected void stepAhead()
protected java.util.Iterator getIterator(java.lang.Object next,
int modus)
next - The object to iteratormodus - Return keys (KEY) or values (VALUE) in maps
protected java.util.Iterator getCustomIterator(java.lang.Object obj,
int modus)
obj - The object to iteratemodus - The modus (keyOrValue for maps)
public java.util.Iterator iterator(java.lang.Object obj)
obj - The object to iterate
public java.util.Iterator iterator(java.lang.Object obj,
int modus)
obj - The object to iteratemodus - The modus (KEY, VALUE or a positive integer, see above)
public java.util.Iterator iterator(java.lang.Object[] objs,
int modus)
objs - The object-array to iteratemodus - The modus (KEY, VALUE or a positive integer, see above)
public static void main(java.lang.String[] args)
args - Argument vector; No arguments needed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||