Class UnmodifiableArrayList<T>

java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractList<T>
org.olap4j.impl.UnmodifiableArrayList<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>

public class UnmodifiableArrayList<T> extends AbstractList<T> implements List<T>
Unmodifiable list backed by an array.

The traditional solution to this problem is to call Arrays.asList(Object[]) followed by Collections.unmodifiableList(java.util.List), but this class has one fewer wrapper object, saving space and indirection effort.

Since:
May 7, 2009
Author:
jhyde
  • Constructor Details

    • UnmodifiableArrayList

      public UnmodifiableArrayList(T... elements)
      Creates an UnmodifiableArrayList.

      Does not create a copy of the array. Future changes to the array will be reflected in the contents of the list.

      Parameters:
      elements - Array
  • Method Details

    • get

      public T get(int index)
      Specified by:
      get in interface List<T>
      Specified by:
      get in class AbstractList<T>
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface List<T>
      Specified by:
      size in class AbstractCollection<T>
    • asCopyOf

      public static <T> UnmodifiableArrayList<T> asCopyOf(T... elements)
      Creates an unmodifable list as a shallow copy of an array.

      Future changes to the array will not be reflected in the contents of the list.

      Type Parameters:
      T - Type of elements
      Parameters:
      elements - Elements of list
      Returns:
      Unmodifiable list with same contents that the array had at call time
    • of

      public static <T> UnmodifiableArrayList<T> of(Collection<? extends T> collection)
      Creates an unmodifable list as a shallow copy of a collection.

      Future changes to the collection will not be reflected in the contents of the list.

      Type Parameters:
      T - Type of elements
      Parameters:
      collection - Elements of list
      Returns:
      Unmodifiable list with same contents that the collection had at call time