Class ResizingArrayStorage<T>
- java.lang.Object
-
- net.automatalib.common.smartcollection.ResizingArrayStorage<T>
-
- Type Parameters:
T- element class.
- All Implemented Interfaces:
CapacityManagement
public final class ResizingArrayStorage<T> extends Object implements CapacityManagement
Class that provides a resizable array storage of a certain type.
-
-
Field Summary
Fields Modifier and Type Field Description T[]arraystatic intDEFAULT_INITIAL_CAPACITYThe default initial capacity of the array storage.
-
Constructor Summary
Constructors Constructor 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 otherResizingArrayStorage.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanensureAdditionalCapacity(int additionalCapacity)Ensures that the internal storage has room for at least the provided number of additional elements.booleanensureCapacity(int minCapacity)Ensures that the internal storage has room for at least the provided number of elements.voidhintNextCapacity(int nextCapacityHint)Gives a hint regarding the capacity that should be reserved when resizing the internal storage for the next time.voidsetAll(T value)Sets all the elements in the array to the specified value.booleanshrink(int maxCapacity)Shrinks the storage to the specified maximum capacity.voidswap(ResizingArrayStorage<T> other)
-
-
-
Field Detail
-
DEFAULT_INITIAL_CAPACITY
public static final int DEFAULT_INITIAL_CAPACITY
The default initial capacity of the array storage.- See Also:
- Constant Field Values
-
array
public T[] array
-
-
Constructor Detail
-
ResizingArrayStorage
public ResizingArrayStorage(Class<? super T> arrayClazz)
Constructor. Creates an array storage with a default initial capacity ofDEFAULT_INITIAL_CAPACITY.- Parameters:
arrayClazz- the class of the storage array.
-
ResizingArrayStorage
public ResizingArrayStorage(Class<? super T> arrayClazz, int initialCapacity)
Constructor. Creates an array with the specified initial capacity.- Parameters:
arrayClazz- the class of the storage array.initialCapacity- the initial capacity.
-
ResizingArrayStorage
public ResizingArrayStorage(ResizingArrayStorage<T> other)
Copy-constructor which (shallowly) clones the storage of the otherResizingArrayStorage.- Parameters:
other- the other storage whose data should be (shallowly) cloned
-
-
Method Detail
-
ensureCapacity
public boolean ensureCapacity(int minCapacity)
Description copied from interface:CapacityManagementEnsures that the internal storage has room for at least the provided number of elements.- Specified by:
ensureCapacityin interfaceCapacityManagement- Parameters:
minCapacity- the minimal number of elements the storage should have room for.- Returns:
trueiff the internal storage had to be resized,falseotherwise.
-
ensureAdditionalCapacity
public boolean ensureAdditionalCapacity(int additionalCapacity)
Description copied from interface:CapacityManagementEnsures that the internal storage has room for at least the provided number of additional elements.Calling this method is equivalent to calling the above
CapacityManagement.ensureCapacity(int)with an argument ofsize() + additionalCapacity.- Specified by:
ensureAdditionalCapacityin interfaceCapacityManagement- Parameters:
additionalCapacity- the number of additional elements the storage should have room for.- Returns:
trueiff the internal storage had to be resized,falseotherwise.
-
hintNextCapacity
public void hintNextCapacity(int nextCapacityHint)
Description copied from interface:CapacityManagementGives a hint regarding the capacity that should be reserved when resizing the internal storage for the next time. This method acts like a "lazy"CapacityManagement.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.- Specified by:
hintNextCapacityin interfaceCapacityManagement- Parameters:
nextCapacityHint- the next capacity hint.
-
shrink
public boolean shrink(int maxCapacity)
Shrinks the storage to the specified maximum capacity.If the current capacity is less or equal to the specified capacity, nothing happens.
- Parameters:
maxCapacity- the maximal number of elements the storage array has to provide room for.- Returns:
trueiff the storage array had to be resized,falseotherwise.
-
setAll
public void setAll(T value)
Sets all the elements in the array to the specified value.- Parameters:
value- the value.
-
swap
public void swap(ResizingArrayStorage<T> other)
-
-