Class ImmutableListCopy<E>

  • All Implemented Interfaces:
    Iterable<E>, Collection<E>, List<E>, Immutables.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.

    Manik Surtani (
    • Constructor Detail

      • ImmutableListCopy

        public ImmutableListCopy()
        Constructs a new ImmutableListCopy. Required by Serialization.
      • ImmutableListCopy

        public ImmutableListCopy​(Collection<? extends E> c)
        Only one copy constructor since the list is immutable.
        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!
        array - to reference
      • ImmutableListCopy

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

      • 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​(int index)
      • subList

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

        public boolean equals​(Object o)
      • hashCode

        public int hashCode()