Class ObjectList<E>

java.lang.Object
com.globalmentor.collections.ObjectList<E>
Type Parameters:
E - The type of object contained in the list.
All Implemented Interfaces:
ImmutableCollection<E>, Iterable<E>, Collection<E>, List<E>

@Deprecated public class ObjectList<E> extends Object implements List<E>, ImmutableCollection<E>
Deprecated.
A read-only list containing a single object.
Author:
Garret Wilson
  • Constructor Summary

    Constructors
    Constructor
    Description
    ObjectList(E object)
    Deprecated.
    Object constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int index, E element)
    Deprecated.
    Inserts the specified element at the specified position in this list (optional operation).
    boolean
    add(E e)
    Deprecated.
    boolean
    addAll(int index, Collection<? extends E> c)
    Deprecated.
    boolean
    addAll(Collection<? extends E> c)
    Deprecated.
    void
    Deprecated.
    boolean
    Deprecated.
    boolean
    Deprecated.
    boolean
    Deprecated.
    get(int index)
    Deprecated.
    Returns the element at the specified position in this list.
    int
    Deprecated.
    int
    Deprecated.
    Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
    boolean
    Deprecated.
    Deprecated.
    int
    Deprecated.
    Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
    Deprecated.
    Returns a list iterator over the elements in this list (in proper sequence).
    listIterator(int index)
    Deprecated.
    Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
    remove(int index)
    Deprecated.
    Removes the element at the specified position in this list (optional operation).
    boolean
    Deprecated.
    boolean
    Deprecated.
    boolean
    Deprecated.
    set(int index, E element)
    Deprecated.
    Replaces the element at the specified position in this list with the specified element (optional operation).
    int
    Deprecated.
    subList(int fromIndex, int toIndex)
    Deprecated.
    Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
    Deprecated.
    <T> T[]
    toArray(T[] a)
    Deprecated.
    Deprecated.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Collection

    parallelStream, removeIf, stream

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.List

    replaceAll, sort, spliterator
  • Constructor Details

    • ObjectList

      public ObjectList(E object)
      Deprecated.
      Object constructor.
      Parameters:
      object - The object to hold in the list.
      Throws:
      NullPointerException - if the given object is null.
  • Method Details

    • size

      public int size()
      Deprecated.
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface List<E>
    • isEmpty

      public boolean isEmpty()
      Deprecated.
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface List<E>
    • contains

      public boolean contains(Object o)
      Deprecated.
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface List<E>
    • iterator

      public Iterator<E> iterator()
      Deprecated.
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface List<E>
    • toArray

      public Object[] toArray()
      Deprecated.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
    • toArray

      public <T> T[] toArray(T[] a)
      Deprecated.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
    • add

      public boolean add(E e)
      Deprecated.
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface List<E>
    • remove

      public boolean remove(Object o)
      Deprecated.
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface List<E>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Deprecated.
      Specified by:
      containsAll in interface Collection<E>
      Specified by:
      containsAll in interface List<E>
    • addAll

      public boolean addAll(Collection<? extends E> c)
      Deprecated.
      Specified by:
      addAll in interface Collection<E>
      Specified by:
      addAll in interface List<E>
    • addAll

      public boolean addAll(int index, Collection<? extends E> c)
      Deprecated.
      Specified by:
      addAll in interface List<E>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Deprecated.
      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface List<E>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Deprecated.
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface List<E>
    • clear

      public void clear()
      Deprecated.
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface List<E>
    • get

      public E get(int index)
      Deprecated.
      Returns the element at the specified position in this list.
      Specified by:
      get in interface List<E>
      Parameters:
      index - index of the element to return
      Returns:
      the element at the specified position in this list
      Throws:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
    • set

      public E set(int index, E element)
      Deprecated.
      Replaces the element at the specified position in this list with the specified element (optional operation).
      Specified by:
      set in interface List<E>
      Parameters:
      index - index of the element to replace
      element - element to be stored at the specified position
      Returns:
      the element previously at the specified position
      Throws:
      UnsupportedOperationException - if the set operation is not supported by this list
      ClassCastException - if the class of the specified element prevents it from being added to this list
      NullPointerException - if the specified element is null and this list does not permit null elements
      IllegalArgumentException - if some property of the specified element prevents it from being added to this list
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
    • add

      public void add(int index, E element)
      Deprecated.
      Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
      Specified by:
      add in interface List<E>
      Parameters:
      index - index at which the specified element is to be inserted
      element - element to be inserted
      Throws:
      UnsupportedOperationException - if the add operation is not supported by this list
      ClassCastException - if the class of the specified element prevents it from being added to this list
      NullPointerException - if the specified element is null and this list does not permit null elements
      IllegalArgumentException - if some property of the specified element prevents it from being added to this list
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size())
    • remove

      public E remove(int index)
      Deprecated.
      Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
      Specified by:
      remove in interface List<E>
      Parameters:
      index - the index of the element to be removed
      Returns:
      the element previously at the specified position
      Throws:
      UnsupportedOperationException - if the remove operation is not supported by this list
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
    • indexOf

      public int indexOf(Object o)
      Deprecated.
      Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
      Specified by:
      indexOf in interface List<E>
      Parameters:
      o - element to search for
      Returns:
      the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element
      Throws:
      ClassCastException - if the type of the specified element is incompatible with this list (optional)
      NullPointerException - if the specified element is null and this list does not permit null elements (optional)
    • lastIndexOf

      public int lastIndexOf(Object o)
      Deprecated.
      Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
      Specified by:
      lastIndexOf in interface List<E>
      Parameters:
      o - element to search for
      Returns:
      the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element
      Throws:
      ClassCastException - if the type of the specified element is incompatible with this list (optional)
      NullPointerException - if the specified element is null and this list does not permit null elements (optional)
    • listIterator

      public ListIterator<E> listIterator()
      Deprecated.
      Returns a list iterator over the elements in this list (in proper sequence).
      Specified by:
      listIterator in interface List<E>
      Returns:
      a list iterator over the elements in this list (in proper sequence)
    • listIterator

      public ListIterator<E> listIterator(int index)
      Deprecated.
      Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.
      Specified by:
      listIterator in interface List<E>
      Parameters:
      index - index of first element to be returned from the list iterator (by a call to the next method)
      Returns:
      a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list
      Throws:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size())
    • subList

      public List<E> subList(int fromIndex, int toIndex)
      Deprecated.
      Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

      This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

       list.subList(from, to).clear();
       
      Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

      The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

      Specified by:
      subList in interface List<E>
      Parameters:
      fromIndex - low endpoint (inclusive) of the subList
      toIndex - high endpoint (exclusive) of the subList
      Returns:
      a view of the specified range within this list
      Throws:
      IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex)
    • equals

      public boolean equals(Object o)
      Deprecated.
      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface List<E>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Deprecated.
      Specified by:
      hashCode in interface Collection<E>
      Specified by:
      hashCode in interface List<E>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Deprecated.
      Overrides:
      toString in class Object