Package org.eclipse.imagen
Class IntegerSequence
Object
IntegerSequence
A growable sorted integer set. Adding an integer to the sequence results in it being placed into the sequence in
sorted order. Adding an integer that is already part of the sequence has no effect.
This structure is used by various subclasses of OpImage to keep track of horizontal and vertical
source splits. Each instance of IntegerSequence provides an internal enumeration by means of which the elements of
the sequence may be accessed in order. The enumerator is initialized by the startEnumeration method, and
the hasMoreElements and nextElement methods allow looping through the elements. Only one
enumeration at a time is supported. Calling insert() from multiple threads is not supported.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a sequence that may contain any integer value.IntegerSequence(int min, int max) Constructs a sequence bounded by an inclusive range of values. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of elements contained within thisIntegerSequence.booleanReturns true if more elements are available to be iterated over.voidinsert(int element) Inserts an integer into the sequence.intReturns the next element of the iteration in ascending order.voidResets the iterator to the beginning of the sequence.toString()Returns aStringrepresentation of the sequence.
-
Constructor Details
-
IntegerSequence
public IntegerSequence(int min, int max) Constructs a sequence bounded by an inclusive range of values.- Parameters:
min- Lower bound of the valid integer range.max- Upper bound of the valid integer range.- Throws:
IllegalArgumentException- if min > max.
-
IntegerSequence
public IntegerSequence()Constructs a sequence that may contain any integer value.
-
-
Method Details
-
insert
public void insert(int element) Inserts an integer into the sequence. If the value falls out of the desired range, it will be silently rejected. Inserting an element that is already a member of the sequence has no effect.- Parameters:
element- Theintto be inserted.
-
startEnumeration
public void startEnumeration()Resets the iterator to the beginning of the sequence. -
hasMoreElements
public boolean hasMoreElements()Returns true if more elements are available to be iterated over. -
nextElement
public int nextElement()Returns the next element of the iteration in ascending order. If the end of the array has been reached, ajava.util.NoSuchElementException will be thrown.- Throws:
NoSuchElementException- if the end of the array has been reached.
-
getNumElements
public int getNumElements()Returns the number of elements contained within thisIntegerSequence. -
toString
Returns aStringrepresentation of the sequence.
-