Package com.tangosol.util
Class SimpleEnumerator<E>
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.util.SimpleEnumerator<E>
-
- All Implemented Interfaces:
Enumeration<E>
,Iterator<E>
- Direct Known Subclasses:
SortedEnumerator
public class SimpleEnumerator<E> extends Base implements Enumeration<E>, Iterator<E>
Provide a generic implementation of an array enumerator.- Version:
- 0.50, 09/05/97, 1.00, 08/07/98
- Author:
- Cameron Purdy
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected E[]
m_aoItem
Array of items to enumerate.protected boolean
m_fForward
Iterator direction.protected int
m_iItem
Iterator position: next item to return.protected int
m_ofLimit
Iterator end position (beyond last).
-
Constructor Summary
Constructors Constructor Description SimpleEnumerator(E[] aoItem)
Construct the simple enumerator based on an array of objects.SimpleEnumerator(E[] aoItem, int ofStart, int cItems)
Construct the simple enumerator based on an array of objects.SimpleEnumerator(E[] aoItem, int ofStart, int cItems, boolean fForward, boolean fCopy)
Construct the simple enumerator based on an array of objects, making a copy of the array if specified.SimpleEnumerator(Collection<E> col)
Construct a simple enumerator based on a collection.SimpleEnumerator(Enumeration<E> enmr)
Construct a simple enumerator based on another Enumeration.SimpleEnumerator(Iterator<E> iter)
Construct a simple enumerator based on another Iterator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasMoreElements()
Tests if this enumeration contains more elements.boolean
hasNext()
Tests if this Iterator contains more elements.E
next()
Returns the next element of this Iterator.E
nextElement()
Returns the next element of this enumeration.void
remove()
Remove the last-returned element that was returned by the Iterator.Object[]
toArray()
Return the remaining contents of this SimpleEnumerator as an array.static <T> T[]
toArray(Enumeration<T> enmr)
Turns an enumeration into an array.static <T> T[]
toArray(Enumeration<T> enmr, T[] ao)
Turns an enumeration into an array.static <T> T[]
toArray(Iterator<T> iter)
Turns an Iterator into an array.static <T> T[]
toArray(Iterator<T> iter, T[] ao)
Turns an Iterator into an array.<T> T[]
toArray(T[] ao)
Return the remaining contents of this SimpleEnumerator as an array of the type specified by the passed array, and use that passed array to store the values if it is big enough, putting a null in the first unused element if the size of the passed array is bigger than the number of remaining elements in this enumerator, as per the contract of theCollection.toArray(Object[])
method.-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Enumeration
asIterator
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Field Detail
-
m_aoItem
protected E[] m_aoItem
Array of items to enumerate.
-
m_iItem
protected int m_iItem
Iterator position: next item to return.
-
m_ofLimit
protected int m_ofLimit
Iterator end position (beyond last).
-
m_fForward
protected boolean m_fForward
Iterator direction.
-
-
Constructor Detail
-
SimpleEnumerator
public SimpleEnumerator(E[] aoItem)
Construct the simple enumerator based on an array of objects.- Parameters:
aoItem
- array of objects to enumerate
-
SimpleEnumerator
public SimpleEnumerator(E[] aoItem, int ofStart, int cItems)
Construct the simple enumerator based on an array of objects.- Parameters:
aoItem
- array of objects to enumerateofStart
- the first object positioncItems
- the number of objects to enumerate
-
SimpleEnumerator
public SimpleEnumerator(E[] aoItem, int ofStart, int cItems, boolean fForward, boolean fCopy)
Construct the simple enumerator based on an array of objects, making a copy of the array if specified.- Parameters:
aoItem
- array of objects to enumerateofStart
- the first object positioncItems
- the number of objects to enumeratefForward
- true to iterate forwards, false to iterate from the end backwards to the beginningfCopy
- pass true to make a copy of the array or false if the array's contents will not change
-
SimpleEnumerator
public SimpleEnumerator(Enumeration<E> enmr)
Construct a simple enumerator based on another Enumeration. This forces an initial pass through the elements of the passed enumerator, making a copy of that data, thus capturing a "point in time" view of an Enumeration which may be backed by mutable data. In other words, this constructs a "safe enumerator" based on a "not-safe enumerator".- Parameters:
enmr
- the java.util.Enumeration to enumerate
-
SimpleEnumerator
public SimpleEnumerator(Iterator<E> iter)
Construct a simple enumerator based on another Iterator. This forces an initial pass through the elements of the passed enumerator, making a copy of that data, thus capturing a "point in time" view of an Iterator which may be backed by mutable data. In other words, this constructs a "safe enumerator" based on a "not-safe enumerator".- Parameters:
iter
- the java.util.Iterator to enumerate
-
SimpleEnumerator
public SimpleEnumerator(Collection<E> col)
Construct a simple enumerator based on a collection.- Parameters:
col
- the java.util.Collection to enumerate
-
-
Method Detail
-
hasMoreElements
public boolean hasMoreElements()
Tests if this enumeration contains more elements.- Specified by:
hasMoreElements
in interfaceEnumeration<E>
- Returns:
- true if the enumeration contains more elements, false otherwise
-
nextElement
public E nextElement()
Returns the next element of this enumeration.- Specified by:
nextElement
in interfaceEnumeration<E>
- Returns:
- the next element in the enumeration
-
hasNext
public boolean hasNext()
Tests if this Iterator contains more elements.
-
next
public E next()
Returns the next element of this Iterator.
-
remove
public void remove()
Remove the last-returned element that was returned by the Iterator. This method always throws UnsupportedOperationException because the Iterator is immutable.
-
toArray
public static <T> T[] toArray(Enumeration<T> enmr)
Turns an enumeration into an array.- Parameters:
enmr
- the enumerator- Returns:
- an array of the objects from the enumerator
-
toArray
public static <T> T[] toArray(Enumeration<T> enmr, T[] ao)
Turns an enumeration into an array. The behavior of this method differs from the simpletoArray(Enumeration)
method in the same way that theCollection.toArray(Object[])
method differs from theCollection.toArray()
method.- Parameters:
enmr
- the enumeratorao
- the array into which the elements of the Enumeration are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose- Returns:
- an array of the objects from the enumerator
-
toArray
public static <T> T[] toArray(Iterator<T> iter)
Turns an Iterator into an array.- Parameters:
iter
- the Iterator- Returns:
- an array of the objects
-
toArray
public static <T> T[] toArray(Iterator<T> iter, T[] ao)
Turns an Iterator into an array. The behavior of this method differs from the simpletoArray(Iterator)
method in the same way that theCollection.toArray(Object[])
method differs from theCollection.toArray()
method.- Parameters:
iter
- the Iteratorao
- the array into which the elements of the Iterator are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose- Returns:
- an array of the objects from the Iterator
-
toArray
public Object[] toArray()
Return the remaining contents of this SimpleEnumerator as an array.- Returns:
- an array containing all of the elements in this enumerator
-
toArray
public <T> T[] toArray(T[] ao)
Return the remaining contents of this SimpleEnumerator as an array of the type specified by the passed array, and use that passed array to store the values if it is big enough, putting a null in the first unused element if the size of the passed array is bigger than the number of remaining elements in this enumerator, as per the contract of theCollection.toArray(Object[])
method.- Parameters:
ao
- the array into which the elements of the Enumeration are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose- Returns:
- an array containing the elements of the collection
- Throws:
ArrayStoreException
- if the runtime type of the specified array is not a supertype of the runtime type of every element in this collection
-
-