Module 
Package org.xnio

Class 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 implements List, it is in fact immutable.
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class java.util.AbstractList

        modCount
    • 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
      • 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.lang.Iterable

        forEach
      • 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 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.
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in interface java.util.List<T>
        Overrides:
        iterator in class java.util.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 java.util.Collection<T>
        Specified by:
        size in interface java.util.List<T>
        Specified by:
        size in class java.util.AbstractCollection<T>
        Returns:
        the number of elements
      • isEmpty

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

        public java.lang.Object[] toArray()
        Get a copy of the values array.
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.List<T>
        Overrides:
        toArray in class java.util.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 java.util.List<T>
        Specified by:
        get in class java.util.AbstractList<T>
        Parameters:
        index - the index
        Returns:
        the value
      • equals

        public boolean equals​(java.lang.Object other)
        Determine whether this sequence is equal to another.
        Specified by:
        equals in interface java.util.Collection<T>
        Specified by:
        equals in interface java.util.List<T>
        Overrides:
        equals in class java.util.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 java.util.Collection<T>
        Specified by:
        hashCode in interface java.util.List<T>
        Overrides:
        hashCode in class java.util.AbstractList<T>
        Returns:
        the hash code