Package org.xnio
Class Sequence<T>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<T>
org.xnio.Sequence<T>
- Type Parameters:
T
- the element type
- All Implemented Interfaces:
Serializable
,Iterable<T>
,Collection<T>
,List<T>
,RandomAccess
public final class Sequence<T>
extends AbstractList<T>
implements List<T>, RandomAccess, Serializable
An immutable sequence of elements. Though this class implements
List
, it is in fact
immutable.- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Method Summary
Modifier and TypeMethodDescription<N> Sequence<N>
Cast a sequence to a different type if all the contained elements are of the subtype.static <T> Sequence<T>
empty()
Return an empty sequence.boolean
Determine whether this sequence is equal to another.boolean
Determine whether this sequence is equal to another.get
(int index) Get the value at a certain index.int
hashCode()
Get the hash code for this sequence.boolean
isEmpty()
Determine whether this sequence is empty.iterator()
Get an iterator over the elements of this sequence.static <T> Sequence<T>
of
(Collection<T> members) Return a sequence of the given members.static <T> Sequence<T>
of
(T... members) Return a sequence of the given members.int
size()
Return the number of elements in this sequence.Object[]
toArray()
Get a copy of the values array.Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, indexOf, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, spliterator, subList, toArray
-
Method Details
-
of
Return a sequence of the given members.- Type Parameters:
T
- the element type- Parameters:
members
- the members- Returns:
- a sequence
-
of
Return a sequence of the given members.- Type Parameters:
T
- the element type- Parameters:
members
- the members- Returns:
- a sequence
-
cast
Cast a sequence to a different type if all the contained elements are of the subtype.- Type Parameters:
N
- the new type- Parameters:
newType
- the class to cast to- Returns:
- the typecast sequence
- Throws:
ClassCastException
- if any elements could not be cast
-
empty
Return an empty sequence.- Type Parameters:
T
- the element type- Returns:
- the empty sequence
-
iterator
Get an iterator over the elements of this sequence. -
size
public int size()Return the number of elements in this sequence.- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceList<T>
- Specified by:
size
in classAbstractCollection<T>
- Returns:
- the number of elements
-
isEmpty
public boolean isEmpty()Determine whether this sequence is empty.- Specified by:
isEmpty
in interfaceCollection<T>
- Specified by:
isEmpty
in interfaceList<T>
- Overrides:
isEmpty
in classAbstractCollection<T>
- Returns:
true
if the sequence has no elements
-
toArray
Get a copy of the values array.- Specified by:
toArray
in interfaceCollection<T>
- Specified by:
toArray
in interfaceList<T>
- Overrides:
toArray
in classAbstractCollection<T>
- Returns:
- a copy of the values array
-
get
Get the value at a certain index. -
equals
Determine whether this sequence is equal to another.- Specified by:
equals
in interfaceCollection<T>
- Specified by:
equals
in interfaceList<T>
- Overrides:
equals
in classAbstractList<T>
- Parameters:
other
- the other sequence- Returns:
true
if they are equal,false
otherwise
-
equals
Determine whether this sequence is equal to another.- Parameters:
other
- the other sequence- Returns:
true
if they are equal,false
otherwise
-
hashCode
public int hashCode()Get the hash code for this sequence.- Specified by:
hashCode
in interfaceCollection<T>
- Specified by:
hashCode
in interfaceList<T>
- Overrides:
hashCode
in classAbstractList<T>
- Returns:
- the hash code
-