Package org.xnio

Class 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:
  • Method Details

    • 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(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(Class<N> newType) throws 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:
      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 Iterator<T> iterator()
      Get an iterator over the elements of this sequence.
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface List<T>
      Overrides:
      iterator in class AbstractList<T>
      Returns:
      an iterator over the elements of this sequence
    • size

      public int size()
      Return the number of elements in this sequence.
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface List<T>
      Specified by:
      size in class AbstractCollection<T>
      Returns:
      the number of elements
    • isEmpty

      public boolean isEmpty()
      Determine whether this sequence is empty.
      Specified by:
      isEmpty in interface Collection<T>
      Specified by:
      isEmpty in interface List<T>
      Overrides:
      isEmpty in class AbstractCollection<T>
      Returns:
      true if the sequence has no elements
    • toArray

      public Object[] toArray()
      Get a copy of the values array.
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface List<T>
      Overrides:
      toArray in class AbstractCollection<T>
      Returns:
      a copy of the values array
    • get

      public T get(int index)
      Get the value at a certain index.
      Specified by:
      get in interface List<T>
      Specified by:
      get in class AbstractList<T>
      Parameters:
      index - the index
      Returns:
      the value
    • equals

      public boolean equals(Object other)
      Determine whether this sequence is equal to another.
      Specified by:
      equals in interface Collection<T>
      Specified by:
      equals in interface List<T>
      Overrides:
      equals in class AbstractList<T>
      Parameters:
      other - the other sequence
      Returns:
      true if they are equal, false otherwise
    • 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
    • hashCode

      public int hashCode()
      Get the hash code for this sequence.
      Specified by:
      hashCode in interface Collection<T>
      Specified by:
      hashCode in interface List<T>
      Overrides:
      hashCode in class AbstractList<T>
      Returns:
      the hash code