|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ceryle.tm.SequenceIterator
public class SequenceIterator
A utility class containing one method for traversing TopicMap graphs as according to a sequence created by use of a trio of PSIs, including a sequence association type, and member roles for to (next) and from (previous).
Note 1
Because it's possible that a traversal of what can be a graph
(rather than a sequence) may lead to situations where the next
element in the traversal allows more than one option, this class
includes a getState() method which provides a way of
checking if there is more than one option. In this case, the
allNext() method will return an Iterator over all possible
next items. The returned elements in this case will be whatever
the iteration order of the Topic Map processor determines (which
is ambiguous).
Note 2
Note that because an iterator such as this could end up in an
infinite loop if the provided structure included loops, the
constructor includes a boolean to determine whether this is to
be allowed or not.
| Field Summary | |
|---|---|
static int |
STATE_AMBIGUOUS
An int constant indicating that the next traversal is not necessarily in a strict sequence (i.e., there may be more than one option in the next traversal). |
static int |
STATE_IN_SEQUENCE
An int constant indicating that the traversal is in sequence (i.e., either next or previous, depending on current direction). |
static int |
STATE_NO_TRAVERSE
An int constant indicating that no traversal is possible from the current Topic. |
static int |
STATE_UNKNOWN
An int constant indicating that the traversal state is unknown. |
static int |
TRAVERSE_FROM
An int constant indicating a 'From' traversal direction, i.e., against the direction of arrows, to-to-from. |
static int |
TRAVERSE_TO
An int constant indicating a 'To' traversal direction, i.e., in the direction of arrows, from-to-to. |
| Constructor Summary | |
|---|---|
SequenceIterator(Topic index,
int direction,
boolean allowLoops)
Creates an Iterator provided the starting Topic topic. |
|
| Method Summary | |
|---|---|
Iterator |
allNext()
In case there are multiple next() options, this returns an iterator over the entire set of topics located by hasNext(). |
int |
getState()
Returns the current traversal state as an int. |
boolean |
hasNext()
Returns true if the iterator has more elements (i.e., returns true if next would return an element rather than throwing an exception.) |
Object |
next()
Returns the next element (a Topic) in the iteration. |
void |
remove()
|
protected boolean |
roleCheck(Topic t,
Locator fwd,
Locator rev)
Returns true if the direction and role match. |
void |
setAllowLoops(boolean allowLoops)
Sets the value of the internal variable to allowLoops, controlling whether or not to traverse to Topics that have been seen before. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int TRAVERSE_FROM
public static final int TRAVERSE_TO
public static final int STATE_UNKNOWN
public static final int STATE_NO_TRAVERSE
public static final int STATE_IN_SEQUENCE
public static final int STATE_AMBIGUOUS
| Constructor Detail |
|---|
public SequenceIterator(Topic index,
int direction,
boolean allowLoops)
throws TopicMapException
This method uses the hardwired PSIs for sequences, including the
association type "sequence" and the two roles, "to" and "from". When
set to disallow loops, hasNext() returns false on iterating
to a Topic that it has already seen.
index - the Topic from which the sequence traversal beginsdirection - an enumerated int setting traversal directionallowLoops - when false, hasNext() will return false on traversing
TopicMapException| Method Detail |
|---|
public boolean hasNext()
hasNext in interface Iteratorpublic Object next()
next in interface IteratorNoSuchElementException - iteration has no more elements.public void setAllowLoops(boolean allowLoops)
public int getState()
public Iterator allNext()
Note:
If hasNext() is called while this Iterator is still active,
a ConcurrentModificationException will not be thrown (since its
reference to the underlying Collection is just removed), but the
Iterator returned from this method will no longer be valid.
protected boolean roleCheck(Topic t,
Locator fwd,
Locator rev)
public void remove()
remove in interface Iterator
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||