Class CopyOnWriteArrayIdentityList<E>

  • Type Parameters:
    E - the element type
    All Implemented Interfaces:
    Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

    public class CopyOnWriteArrayIdentityList<E>
    extends Object
    implements List<E>, RandomAccess, Cloneable, Serializable
    Implements a ArrayList variant that is thread-safe. All write operation result in a new copy of the underlying data being created. Iterators reflect the state of the CopyOnWriteArrayIdentityList at the time they were created. They are not updated to reflect subsequent changes to the list. In addition, these iterators cannot be used for modifying the underlying CopyOnWriteArrayIdentityList. In addition, elements are compared based on reference equality instead of object equality when comparing values.
    See Also:
    Serialized Form
    • Constructor Detail

      • CopyOnWriteArrayIdentityList

        public CopyOnWriteArrayIdentityList()
        Creates a new, empty instance of CopyOnWriteArrayList.
      • CopyOnWriteArrayIdentityList

        public CopyOnWriteArrayIdentityList​(Collection<? extends E> c)
        Creates a new instance of CopyOnWriteArrayList and fills it with the contents of a given Collection.
        Parameters:
        c - the collection the elements of which are to be copied into the new instance.
      • CopyOnWriteArrayIdentityList

        public CopyOnWriteArrayIdentityList​(E[] array)
        Creates a new instance of CopyOnWriteArrayList and fills it with the contents of a given array.
        Parameters:
        array - the array the elements of which are to be copied into the new instance.
    • Method Detail

      • add

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

        public void add​(int index,
                        E e)
        Specified by:
        add in interface List<E>
      • addAll

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

        public int addAllAbsent​(Collection<? extends E> c)
        Adds to this CopyOnWriteArrayList all those elements from a given collection that are not yet part of the list.
        Parameters:
        c - the collection from which the potential new elements are taken.
        Returns:
        the number of elements actually added to this list.
      • addIfAbsent

        public boolean addIfAbsent​(E e)
        Adds to this CopyOnWriteArrayList another element, given that this element is not yet part of the list.
        Parameters:
        e - the potential new element.
        Returns:
        true if the element was added, or false otherwise.
      • get

        public E get​(int index)
        Specified by:
        get in interface List<E>
      • indexOf

        public int indexOf​(E e,
                           int index)
        Returns the index of a given element, starting the search from a given position in the list.
        Parameters:
        e - the element to search.
        index - the index at which to start the search.
        Returns:
        the index of the element or null, if the element has not been found at or beyond the given start index.
      • lastIndexOf

        public int lastIndexOf​(E e,
                               int index)
        Returns the last index of a given element, starting the search from a given position in the list and going backwards.
        Parameters:
        e - the element to search.
        index - the index at which to start the search.
        Returns:
        the index of the element or null, if the element has not been found at or before the given start index.
      • remove

        public E remove​(int index)
        Specified by:
        remove in interface List<E>
      • set

        public E set​(int index,
                     E e)
        Specified by:
        set in interface List<E>
      • subList

        public List<E> subList​(int fromIndex,
                               int toIndex)
        Specified by:
        subList in interface List<E>