Class ObjectImmutableList<K>

All Implemented Interfaces:
ObjectCollection<K>, ObjectIterable<K>, ObjectList<K>, Stack<K>, Serializable, Cloneable, Comparable<List<? extends K>>, Iterable<K>, Collection<K>, List<K>, RandomAccess

public class ObjectImmutableList<K> extends AbstractObjectList<K> implements ObjectList<K>, RandomAccess, Cloneable, Serializable
A type-specific array-based immutable list; provides some additional methods that use polymorphism to avoid (un)boxing.

Instances of this class are immutable and (contrarily to mutable array-based list implementations) the backing array is not exposed. Instances can be built using a variety of methods, but note that constructors using an array will not make a defensive copy.

This class implements the bulk method getElements() using high-performance system calls (e.g., System.arraycopy()) instead of expensive loops.

See Also:
  • Constructor Details

    • ObjectImmutableList

      public ObjectImmutableList(K[] a)
      Creates a new immutable list using a given array.

      Note that this constructor does not perform a defensive copy.

      Parameters:
      a - the array that will be used to back this immutable list.
    • ObjectImmutableList

      public ObjectImmutableList(Collection<? extends K> c)
      Creates a new immutable list and fills it with a given collection.
      Parameters:
      c - a collection that will be used to fill the immutable list.
    • ObjectImmutableList

      public ObjectImmutableList(ObjectCollection<? extends K> c)
      Creates a new immutable list and fills it with a given type-specific collection.
      Parameters:
      c - a type-specific collection that will be used to fill the immutable list.
    • ObjectImmutableList

      public ObjectImmutableList(ObjectList<? extends K> l)
      Creates a new immutable list and fills it with a given type-specific list.
      Parameters:
      l - a type-specific list that will be used to fill the immutable list.
    • ObjectImmutableList

      public ObjectImmutableList(K[] a, int offset, int length)
      Creates a new immutable list and fills it with the elements of a given array.
      Parameters:
      a - an array whose elements will be used to fill the immutable list.
      offset - the first element to use.
      length - the number of elements to use.
    • ObjectImmutableList

      public ObjectImmutableList(ObjectIterator<? extends K> i)
      Creates a new immutable list and fills it with the elements returned by a type-specific iterator..
      Parameters:
      i - a type-specific iterator whose returned elements will fill the immutable list.
  • Method Details