Class ImmutableListCopy<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.infinispan.commons.util.ImmutableListCopy<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, Immutables.Immutable

@Immutable public class ImmutableListCopy<E> extends AbstractList<E> implements Immutables.Immutable
A lightweight, read-only copy of a List. Typically used in place of the common idiom: return Collections.unmodifiableList(new ArrayList( myInternalList ));

a it is far more efficient than making a defensive copy and then wrapping the defensive copy in a read-only wrapper.

Also used whenever a read-only reference List is needed.

Since:
4.0
Author:
Manik Surtani (manik@jboss.org)
  • Field Details

    • EMPTY_ARRAY

      public static final Object[] EMPTY_ARRAY
  • Constructor Details

    • ImmutableListCopy

      public ImmutableListCopy()
      Constructs an empty ImmutableListCopy.
    • ImmutableListCopy

      public ImmutableListCopy(Collection<? extends E> c)
      Only one copy constructor since the list is immutable.
      Parameters:
      c - collection to copy from
    • ImmutableListCopy

      public ImmutableListCopy(E[] array)
      Assumes that the array passed in is "safe", i.e., is not referenced from elsewhere. Use with care!
      Parameters:
      array - to reference
    • ImmutableListCopy

      public ImmutableListCopy(Collection<? extends E> collection1, Collection<? extends E> collection2)
      Utility constructors to allow combining collections
      Parameters:
      collection1 - collection to copy from
      collection2 - collection to copy from
  • Method Details

    • size

      public final int size()
    • isEmpty

      public final boolean isEmpty()
    • contains

      public final boolean contains(Object o)
    • iterator

      public final Iterator<E> iterator()
    • toArray

      public final Object[] toArray()
    • toArray

      public final <T> T[] toArray(T[] a)
    • add

      public final boolean add(E o)
    • remove

      public final boolean remove(Object o)
    • addAll

      public final boolean addAll(Collection<? extends E> c)
    • addAll

      public final boolean addAll(int index, Collection<? extends E> c)
    • removeAll

      public final boolean removeAll(Collection<?> c)
    • retainAll

      public final boolean retainAll(Collection<?> c)
    • get

      public final E get(int index)
    • indexOf

      public final int indexOf(Object o)
    • lastIndexOf

      public final int lastIndexOf(Object o)
    • listIterator

      public final ListIterator<E> listIterator()
    • listIterator

      public final ListIterator<E> listIterator(int index)
    • subList

      public final List<E> subList(int fromIndex, int toIndex)
    • equals

      public boolean equals(Object o)
    • hashCode

      public int hashCode()