- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<T>
-
- org.xnio.Sequence<T>
-
- Type Parameters:
T
- the element type
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.List<T>
,java.util.RandomAccess
public final class Sequence<T> extends java.util.AbstractList<T> implements java.util.List<T>, java.util.RandomAccess, java.io.Serializable
An immutable sequence of elements. Though this class implementsList
, it is in fact immutable.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <N> Sequence<N>
cast(java.lang.Class<N> newType)
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
equals(java.lang.Object other)
Determine whether this sequence is equal to another.boolean
equals(Sequence<?> other)
Determine whether this sequence is equal to another.T
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.java.util.Iterator<T>
iterator()
Get an iterator over the elements of this sequence.static <T> Sequence<T>
of(java.util.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.java.lang.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
-
-
-
-
Method Detail
-
of
public static <T> Sequence<T> of(T... members)
Return a sequence of the given members.- Type Parameters:
T
- the element type- Parameters:
members
- the members- Returns:
- a sequence
-
of
public static <T> Sequence<T> of(java.util.Collection<T> members)
Return a sequence of the given members.- Type Parameters:
T
- the element type- Parameters:
members
- the members- Returns:
- a sequence
-
cast
public <N> Sequence<N> cast(java.lang.Class<N> newType) throws java.lang.ClassCastException
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:
java.lang.ClassCastException
- if any elements could not be cast
-
empty
public static <T> Sequence<T> empty()
Return an empty sequence.- Type Parameters:
T
- the element type- Returns:
- the empty sequence
-
iterator
public java.util.Iterator<T> iterator()
Get an iterator over the elements of this sequence.
-
size
public int size()
Return the number of elements in this sequence.
-
isEmpty
public boolean isEmpty()
Determine whether this sequence is empty.
-
toArray
public java.lang.Object[] toArray()
Get a copy of the values array.
-
get
public T get(int index)
Get the value at a certain index.
-
equals
public boolean equals(java.lang.Object other)
Determine whether this sequence is equal to another.
-
equals
public boolean equals(Sequence<?> other)
Determine whether this sequence is equal to another.- Parameters:
other
- the other sequence- Returns:
true
if they are equal,false
otherwise
-
-