T - element class.public final class ResizingArrayStorage<T> extends Object implements CapacityManagement, Serializable
| Modifier and Type | Field and Description |
|---|---|
T[] |
array |
static int |
DEFAULT_INITIAL_CAPACITY
The default initial capacity of the array storage.
|
| Constructor and Description |
|---|
ResizingArrayStorage(Class<? super T> arrayClazz)
Constructor.
|
ResizingArrayStorage(Class<? super T> arrayClazz,
int initialCapacity)
Constructor.
|
ResizingArrayStorage(ResizingArrayStorage<T> other)
Copy-constructor which (shallowly) clones the storage of the other
ResizingArrayStorage. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
ensureAdditionalCapacity(int additionalCapacity)
Ensures that the internal storage has room for at least the provided number of additional elements.
|
boolean |
ensureCapacity(int minCapacity)
Ensures that the internal storage has room for at least the provided number of elements.
|
void |
hintNextCapacity(int nextCapacityHint)
Gives a hint regarding the capacity that should be reserved when resizing the internal storage for the next time.
|
void |
setAll(T value)
Sets all the elements in the array to the specified value.
|
boolean |
shrink(int maxCapacity)
Shrinks the storage to the specified maximum capacity.
|
void |
swap(ResizingArrayStorage<T> other) |
public static final int DEFAULT_INITIAL_CAPACITY
public T[] array
public ResizingArrayStorage(Class<? super T> arrayClazz)
DEFAULT_INITIAL_CAPACITY.arrayClazz - the class of the storage array.public ResizingArrayStorage(Class<? super T> arrayClazz, int initialCapacity)
arrayClazz - the class of the storage array.initialCapacity - the initial capacity.public ResizingArrayStorage(ResizingArrayStorage<T> other)
ResizingArrayStorage.other - the other storage whose data should be (shallowly) clonedpublic boolean ensureCapacity(int minCapacity)
CapacityManagementensureCapacity in interface CapacityManagementminCapacity - the minimal number of elements the storage should have room for.true iff the internal storage had to be resized, false otherwise.public boolean ensureAdditionalCapacity(int additionalCapacity)
CapacityManagement
Calling this method is equivalent to calling the above CapacityManagement.ensureCapacity(int) with an argument of
size() + additionalCapacity.
ensureAdditionalCapacity in interface CapacityManagementadditionalCapacity - the number of additional elements the storage should have room for.true iff the internal storage had to be resized, false otherwise.public void hintNextCapacity(int nextCapacityHint)
CapacityManagementCapacityManagement.ensureCapacity(int), i.e. it reserves the specified capacity at the time
the next resizing of the internal storage is performed.
This method is useful when a not too imprecise upper bound on the elements that will in consequence be added is
known. Since the actual number of elements added may be lower than the specified upper bound, a resizing that
would have been performed by CapacityManagement.ensureCapacity(int) might not be necessary.
hintNextCapacity in interface CapacityManagementnextCapacityHint - the next capacity hint.public boolean shrink(int maxCapacity)
If the current capacity is less or equal to the specified capacity, nothing happens.
maxCapacity - the maximal number of elements the storage array has to provide room for.true iff the storage array had to be resized, false otherwise.public void setAll(T value)
value - the value.public void swap(ResizingArrayStorage<T> other)
Copyright © 2020. All rights reserved.