Package io.opentelemetry.sdk.internal
Class DynamicPrimitiveLongList
- All Implemented Interfaces:
Iterable<Long>,Collection<Long>,List<Long>,SequencedCollection<Long>
A resizable list for storing primitive `long` values.
This class implements a dynamically resizable list specifically for primitive long values. The values are stored in a chain of arrays (named sub-array), so it can grow efficiently, by adding more sub-arrays per its defined size. The backing array also helps avoid auto-boxing and helps provide access to values as primitives without boxing.
The list is designed to minimize memory allocations, by:
- Adding sub-arrays and not creating new arrays and copying.
- When the size is changing to a smaller size, arrays are not removed.
Supported List<Long> methods:
get(int)- Retrieves the element at the specified position in this list as aLongobject.set(int, Long)- Replaces the element at the specified position in this list with the specifiedLongobject.size()- Returns the number of elements in this list.
Additional utility methods:
getLong(int)- Retrieves the element at the specified position in this list as a primitive long.setLong(int, long)- Replaces the element at the specified position in this list with the specified primitive long element.resizeAndClear(int)- Resizes the list to the specified size, resetting all elements to zero.
This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
This class is not thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate long[][]private static final intprivate intprivate final intFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DynamicPrimitiveLongListempty()private voidensureCapacity(int minCapacity) get(int index) longgetLong(int index) static DynamicPrimitiveLongListof(long... values) static DynamicPrimitiveLongListofSubArrayCapacity(int subarrayCapacity) private StringoutOfBoundsMsg(int index) private voidrangeCheck(int index) voidresizeAndClear(int newSize) longsetLong(int index, long element) intsize()Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
DEFAULT_SUBARRAY_CAPACITY
private static final int DEFAULT_SUBARRAY_CAPACITY- See Also:
-
subarrayCapacity
private final int subarrayCapacity -
arrays
private long[][] arrays -
size
private int size -
arrayCount
private int arrayCount
-
-
Constructor Details
-
DynamicPrimitiveLongList
DynamicPrimitiveLongList() -
DynamicPrimitiveLongList
DynamicPrimitiveLongList(int subarrayCapacity)
-
-
Method Details
-
of
-
ofSubArrayCapacity
-
empty
-
get
-
getLong
public long getLong(int index) -
set
-
setLong
public long setLong(int index, long element) -
size
public int size()- Specified by:
sizein interfaceCollection<Long>- Specified by:
sizein interfaceList<Long>- Specified by:
sizein classAbstractCollection<Long>
-
resizeAndClear
public void resizeAndClear(int newSize) -
ensureCapacity
private void ensureCapacity(int minCapacity) -
rangeCheck
private void rangeCheck(int index) -
outOfBoundsMsg
-