Class SparseConcurrentListWithOffset<E>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess

    public class SparseConcurrentListWithOffset<E>
    extends SparseConcurrentList<E>
    A very simple subclass of SparseConcurrentList which adds some immutable offset to all index. Useful for cases where the list needs to contain negative indices. A more fancy version where the offset adjusts dynamically based on the indices it needs to contain would be interesting, but more complex. It would likely require starting from scratch, as the facilities provided by CopyOnWriteArrayList may be insufficient to achieve correct/efficient synchronization.
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, E element)  
      boolean addAll​(int index, java.util.Collection<? extends E> c)  
      boolean equals​(java.lang.Object o)  
      E get​(int index)  
      int hashCode()  
      int indexOf​(E e, int index)  
      int lastIndexOf​(E e, int index)  
      java.util.ListIterator<E> listIterator​(int index)  
      E remove​(int index)
      A function which behaves like Map.remove(Object), rather than List.remove(int), in the sense that it removes the item from the collection, returns the previous value (if any), but *does not* shift subsequent items to the left (as the regular List.remove(int) would.
      E set​(int index, E item)
      A function which behaves like Map.put(Object, Object), rather than List.set(int, Object).
      java.util.List<E> subList​(int fromIndex, int toIndex)  
      • Methods inherited from class java.util.concurrent.CopyOnWriteArrayList

        addIfAbsent, clone, contains, containsAll, indexOf, iterator, lastIndexOf, listIterator, size, spliterator, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, stream, toArray
    • Constructor Detail

      • SparseConcurrentListWithOffset

        public SparseConcurrentListWithOffset​(int offset)
    • Method Detail

      • add

        public void add​(int index,
                        E element)
        Specified by:
        add in interface java.util.List<E>
        Overrides:
        add in class SparseConcurrentList<E>
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.List<E>
        Overrides:
        addAll in class SparseConcurrentList<E>
      • get

        public E get​(int index)
        Specified by:
        get in interface java.util.List<E>
        Overrides:
        get in class SparseConcurrentList<E>
        Parameters:
        index - of the item to retrieve
        Returns:
        the item at this index, or null
      • indexOf

        public int indexOf​(E e,
                           int index)
        Overrides:
        indexOf in class java.util.concurrent.CopyOnWriteArrayList<E>
      • lastIndexOf

        public int lastIndexOf​(E e,
                               int index)
        Overrides:
        lastIndexOf in class java.util.concurrent.CopyOnWriteArrayList<E>
      • listIterator

        public java.util.ListIterator<E> listIterator​(int index)
        Specified by:
        listIterator in interface java.util.List<E>
        Overrides:
        listIterator in class java.util.concurrent.CopyOnWriteArrayList<E>
      • remove

        public E remove​(int index)
        Description copied from class: SparseConcurrentList
        A function which behaves like Map.remove(Object), rather than List.remove(int), in the sense that it removes the item from the collection, returns the previous value (if any), but *does not* shift subsequent items to the left (as the regular List.remove(int) would.
        Specified by:
        remove in interface java.util.List<E>
        Overrides:
        remove in class SparseConcurrentList<E>
        Parameters:
        index - of the item to nullify
        Returns:
        the previous item at that {@param index}
      • set

        public E set​(int index,
                     E item)
        Description copied from class: SparseConcurrentList
        A function which behaves like Map.put(Object, Object), rather than List.set(int, Object).
        Specified by:
        set in interface java.util.List<E>
        Overrides:
        set in class SparseConcurrentList<E>
      • subList

        public java.util.List<E> subList​(int fromIndex,
                                         int toIndex)
        Specified by:
        subList in interface java.util.List<E>
        Overrides:
        subList in class SparseConcurrentList<E>
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Collection<E>
        Specified by:
        equals in interface java.util.List<E>
        Overrides:
        equals in class java.util.concurrent.CopyOnWriteArrayList<E>
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface java.util.List<E>
        Overrides:
        hashCode in class java.util.concurrent.CopyOnWriteArrayList<E>