gzz.util
Class LoopDetector
java.lang.Object
|
+--gzz.util.LoopDetector
- public final class LoopDetector
- extends java.lang.Object
A loop detector.
Uses a simple constant-space algorithm that will detect any loop before
it's cycled through 3 times, except very small loops.
Example use:
LoopDetector l = new LoopDetector();
while((x = iter(x)) != null) {
l.detect(x);
// ... do something with x.
}
Note: this only works for deterministic loops that always have the same
elements and length. Nothing is guaranteed if the content of the loop
varies even slightly. However, it is guaranteed that the loop is
detected once the loop has settled into a constant loop.
The Object.equals method is used for the comparisons.
Field Summary |
static java.lang.String |
rcsid
|
Method Summary |
void |
detect(java.lang.Object o)
Throws an exception if the parameter is a part of a looping sequence. |
void |
detectError(java.lang.Object o)
Throws an error if bla bla bla. |
boolean |
isLooping(java.lang.Object o)
Returns true if the parameter is a part of a looping sequence. |
void |
reset()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
rcsid
public static final java.lang.String rcsid
- See Also:
- Constant Field Values
LoopDetector
public LoopDetector()
reset
public void reset()
detect
public void detect(java.lang.Object o)
throws gzz.errors.InfiniteLoopException
- Throws an exception if the parameter is a part of a looping sequence.
gzz.errors.InfiniteLoopException
detectError
public void detectError(java.lang.Object o)
- Throws an error if bla bla bla.
isLooping
public boolean isLooping(java.lang.Object o)
- Returns true if the parameter is a part of a looping sequence.