Class ImmutableVector<E>

    • Constructor Detail

      • ImmutableVector

        public ImmutableVector​(Collection<? extends E> collection)
        Parameters:
        collection - Collection<? extends E>; the collection to use for the immutable vector.
      • ImmutableVector

        public ImmutableVector​(Vector<E> vector,
                               Immutable copyOrWrap)
        Parameters:
        vector - Vector<E>; the vector to use for the immutable vector.
        copyOrWrap - COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
      • ImmutableVector

        public ImmutableVector​(ImmutableAbstractCollection<? extends E> collection)
        Parameters:
        collection - ImmutableAbstractCollection<? extends E>; the immutable collection to use for the immutable vector.
      • ImmutableVector

        public ImmutableVector​(ImmutableVector<E> vector,
                               Immutable copyOrWrap)
        Parameters:
        vector - ImmutableVector<E>; the vector to use for the immutable vector.
        copyOrWrap - COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
    • Method Detail

      • toList

        public final List<E> toList()
        Returns a modifiable copy of this immutable list.
        Returns:
        a modifiable copy of this immutable list.
      • toVector

        public final Vector<E> toVector()
        Returns a modifiable copy of this immutable vector.
        Returns:
        a modifiable copy of this immutable vector.
      • getUnderlyingCollection

        protected Vector<E> getUnderlyingCollection()
        Returns the underlying collection of this immutable collection. In case of Immutable.WRAP, this will be the original collection. In case of IMMUTABLE.COPY, this will be the internally stored (mutable) copy of the collection.
        Overrides:
        getUnderlyingCollection in class ImmutableAbstractList<E>
        Returns:
        the underlying collection of this immutable collection.
      • subList

        public final ImmutableList<E> subList​(int fromIndex,
                                              int toIndex)
        Returns a safe, immutable copy of the portion of this immutable list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned immutable list is empty).
        Parameters:
        fromIndex - int; low endpoint (inclusive) of the subList
        toIndex - int; high endpoint (exclusive) of the subList
        Returns:
        a view of the specified range within this immutable list
      • copyInto

        public final void copyInto​(Object[] anArray)
        Copies the components of this immutable vector into the specified array. The item at index k in this immutable vector is copied into component k of anArray.
        Parameters:
        anArray - Object[]; the array into which the components get copied
        Throws:
        NullPointerException - if the given array is null
        IndexOutOfBoundsException - if the specified array is not large enough to hold all the components of this immutable vector
        ArrayStoreException - if a component of this immutable vector is not of a runtime type that can be stored in the specified array
        See Also:
        ImmutableAbstractList.toArray(Object[])
      • capacity

        public final int capacity()
        Returns the current capacity of this immutable vector.
        Returns:
        the current capacity of this immutable vector.
      • elements

        public final Enumeration<E> elements()
        Returns an enumeration of the components of this vector. The returned Enumeration object will generate all items in this vector. The first item generated is the item at index 0, then the item at index 1, and so on.
        Returns:
        an enumeration of the components of this vector
        See Also:
        Iterator
      • indexOf

        public final int indexOf​(Object o,
                                 int index)
        Returns the index of the first occurrence of the specified element in this immutable vector, searching forwards from index, or returns -1 if the element is not found. More formally, returns the lowest index i such that (i >= index && (o==null ? get(i)==null : o.equals(get(i)))), or -1 if there is no such index.
        Parameters:
        o - Object; element to search for
        index - int; index to start searching from
        Returns:
        the index of the first occurrence of the element in this immutable vector at position index or later in the vector; -1 if the element is not found.
        Throws:
        IndexOutOfBoundsException - if the specified index is negative
        See Also:
        Object.equals(Object)
      • lastIndexOf

        public final int lastIndexOf​(Object o,
                                     int index)
        Returns the index of the last occurrence of the specified element in this immutable vector, searching backwards from index, or returns -1 if the element is not found. More formally, returns the highest index i such that (i <= index && (o==null ? get(i)==null : o.equals(get(i)))), or -1 if there is no such index.
        Parameters:
        o - Object; element to search for
        index - int; index to start searching backwards from
        Returns:
        the index of the last occurrence of the element at position less than or equal to index in this immutable vector; -1 if the element is not found.
        Throws:
        IndexOutOfBoundsException - if the specified index is greater than or equal to the current size of this immutable vector
      • elementAt

        public final E elementAt​(int index)
        Returns the component at the specified index.

        This method is identical in functionality to the ImmutableAbstractList.get(int) method (which is part of the List interface).

        Parameters:
        index - int; an index into this immutable vector
        Returns:
        the component at the specified index
        Throws:
        ArrayIndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • firstElement

        public final E firstElement()
        Returns the first component (the item at index 0) of this immutable vector.
        Returns:
        the first component of this immutable vector
        Throws:
        NoSuchElementException - if this immutable vector has no components
      • lastElement

        public final E lastElement()
        Returns the last component of the immutable vector.
        Returns:
        the last component of the immutable vector, i.e., the component at index size() - 1.
        Throws:
        NoSuchElementException - if this immutable vector is empty
      • toString

        public final String toString()
        Force to redefine toString.
        Specified by:
        toString in interface ImmutableList<E>
        Overrides:
        toString in class Object
        Returns:
        String; a description of this immutable list