Package com.linkedin.venice.utils
Class SparseConcurrentListWithOffset<E>
- java.lang.Object
-
- java.util.concurrent.CopyOnWriteArrayList<E>
-
- com.linkedin.venice.utils.SparseConcurrentList<E>
-
- com.linkedin.venice.utils.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 ofSparseConcurrentList
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 byCopyOnWriteArrayList
may be insufficient to achieve correct/efficient synchronization.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SparseConcurrentListWithOffset(int offset)
-
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 likeMap.remove(Object)
, rather thanList.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 regularList.remove(int)
would.E
set(int index, E item)
A function which behaves likeMap.put(Object, Object)
, rather thanList.set(int, Object)
.java.util.List<E>
subList(int fromIndex, int toIndex)
-
Methods inherited from class com.linkedin.venice.utils.SparseConcurrentList
add, addAll, addAllAbsent, clear, computeIfAbsent, forEach, isEmpty, nonNullSize, remove, removeAll, removeIf, replaceAll, retainAll, sort, values
-
Methods inherited from class java.util.concurrent.CopyOnWriteArrayList
addIfAbsent, clone, contains, containsAll, indexOf, iterator, lastIndexOf, listIterator, size, spliterator, toArray, toArray, toString
-
-
-
-
Method Detail
-
add
public void add(int index, E element)
- Specified by:
add
in interfacejava.util.List<E>
- Overrides:
add
in classSparseConcurrentList<E>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)
- Specified by:
addAll
in interfacejava.util.List<E>
- Overrides:
addAll
in classSparseConcurrentList<E>
-
get
public E get(int index)
- Specified by:
get
in interfacejava.util.List<E>
- Overrides:
get
in classSparseConcurrentList<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 classjava.util.concurrent.CopyOnWriteArrayList<E>
-
lastIndexOf
public int lastIndexOf(E e, int index)
- Overrides:
lastIndexOf
in classjava.util.concurrent.CopyOnWriteArrayList<E>
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
-
remove
public E remove(int index)
Description copied from class:SparseConcurrentList
A function which behaves likeMap.remove(Object)
, rather thanList.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 regularList.remove(int)
would.- Specified by:
remove
in interfacejava.util.List<E>
- Overrides:
remove
in classSparseConcurrentList<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 likeMap.put(Object, Object)
, rather thanList.set(int, Object)
.- Specified by:
set
in interfacejava.util.List<E>
- Overrides:
set
in classSparseConcurrentList<E>
-
subList
public java.util.List<E> subList(int fromIndex, int toIndex)
- Specified by:
subList
in interfacejava.util.List<E>
- Overrides:
subList
in classSparseConcurrentList<E>
-
equals
public boolean equals(java.lang.Object o)
-
-