public final class ResizingIntArray extends Object implements CapacityManagement, Serializable
int array storage.| Modifier and Type | Field and Description |
|---|---|
int[] |
array
The storage array.
|
static int |
DEFAULT_INITIAL_CAPACITY
The arrays default initial capacity.
|
| Constructor and Description |
|---|
ResizingIntArray()
Constructor.
|
ResizingIntArray(int initialCapacity)
Constructor.
|
| 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(int 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(ResizingIntArray other) |
public static final int DEFAULT_INITIAL_CAPACITY
public int[] array
public ResizingIntArray()
DEFAULT_INITIAL_CAPACITYpublic ResizingIntArray(int initialCapacity)
initialCapacity - the initial capacity.public 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(int value)
value - the value.public void swap(ResizingIntArray other)
Copyright © 2019. All rights reserved.