Module org.scijava.collections
Package org.scijava.collections
Class AbstractPrimitiveArray<ArrayType,BaseType>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<BaseType>
-
- org.scijava.collections.AbstractPrimitiveArray<ArrayType,BaseType>
-
- Type Parameters:
ArrayType- Type of the primitive array; e.g.,double[].BaseType- Boxed type of the array element; e.g.,Double.
- All Implemented Interfaces:
Iterable<BaseType>,Collection<BaseType>,List<BaseType>,PrimitiveArray<ArrayType,BaseType>
- Direct Known Subclasses:
BoolArray,ByteArray,CharArray,DoubleArray,FloatArray,IntArray,LongArray,ObjectArray,ShortArray
public abstract class AbstractPrimitiveArray<ArrayType,BaseType> extends AbstractList<BaseType> implements PrimitiveArray<ArrayType,BaseType>
Abstract base class for primitive-type extensible arrays.This class makes it easy to implement extensible arrays backed by fixed-size primitive type arrays, re-allocating and copying data as needed. To avoid frequent re-allocation, by default, the fixed-size array will be expanded by 50% when running out of space.
- Author:
- Johannes Schindelin, Curtis Rueden
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description AbstractPrimitiveArray(Class<BaseType> type)Constructs an extensible array of primitive type elements, backed by a fixed-size array.AbstractPrimitiveArray(Class<BaseType> type, int size)Constructs an extensible array of primitive type elements, backed by a fixed-size array.AbstractPrimitiveArray(Class<BaseType> type, ArrayType array)Constructs an extensible array of primitive type elements, backed by the given fixed-size array.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidadd(int index, BaseType element)intcapacity()Gets the current capacity of the backing array.protected voidcheckBounds(int index)Checks that the index is less than the size of the array.voidclear()ArrayTypecopyArray()Returns a copy of the primitive-array array.voiddelete(int index, int count)Shifts the array to delete space starting at a specified index.voidensureCapacity(int minCapacity)Makes sure the backing array at least a specified capacity.intgetMaximumGrowth()Gets the maximal step size by which to grow the fixed-size array when running out of space.voidinsert(int index, int count)Shifts the array to insert space at a specified index.BaseTyperemove(int index)abstract BaseTypeset(int index, BaseType element)voidsetMaximumGrowth(int growth)Sets the maximal step size by which to grow the fixed-size array when running out of space.voidsetSize(int size)intsize()-
Methods inherited from class java.util.AbstractList
add, addAll, equals, get, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
add, addAll, addAll, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, replaceAll, retainAll, sort, spliterator, subList, toArray, toArray
-
Methods inherited from interface org.scijava.collections.PrimitiveArray
defaultValue, getArray, setArray
-
-
-
-
Constructor Detail
-
AbstractPrimitiveArray
public AbstractPrimitiveArray(Class<BaseType> type)
Constructs an extensible array of primitive type elements, backed by a fixed-size array.- Parameters:
type- the class of the primitive type
-
AbstractPrimitiveArray
public AbstractPrimitiveArray(Class<BaseType> type, int size)
Constructs an extensible array of primitive type elements, backed by a fixed-size array.- Parameters:
type- the class of the primitive typesize- the initial size
-
-
Method Detail
-
getMaximumGrowth
public int getMaximumGrowth()
Description copied from interface:PrimitiveArrayGets the maximal step size by which to grow the fixed-size array when running out of space.- Specified by:
getMaximumGrowthin interfacePrimitiveArray<ArrayType,BaseType>
-
setMaximumGrowth
public void setMaximumGrowth(int growth)
Description copied from interface:PrimitiveArraySets the maximal step size by which to grow the fixed-size array when running out of space.- Specified by:
setMaximumGrowthin interfacePrimitiveArray<ArrayType,BaseType>
-
copyArray
public ArrayType copyArray()
Description copied from interface:PrimitiveArrayReturns a copy of the primitive-array array.The returned array is guaranteed to have
List.size()elements.- Specified by:
copyArrayin interfacePrimitiveArray<ArrayType,BaseType>- Returns:
- the fixed-size array
-
capacity
public int capacity()
Gets the current capacity of the backing array.- Specified by:
capacityin interfacePrimitiveArray<ArrayType,BaseType>
-
ensureCapacity
public void ensureCapacity(int minCapacity)
Description copied from interface:PrimitiveArrayMakes sure the backing array at least a specified capacity.After calling this method, the internal array will have at least
minCapacityelements.- Specified by:
ensureCapacityin interfacePrimitiveArray<ArrayType,BaseType>- Parameters:
minCapacity- the minimum capacity
-
insert
public void insert(int index, int count)Shifts the array to insert space at a specified index.- Specified by:
insertin interfacePrimitiveArray<ArrayType,BaseType>- Parameters:
index- the index where the space should be insertedcount- the number of values to insert
-
delete
public void delete(int index, int count)Shifts the array to delete space starting at a specified index.- Specified by:
deletein interfacePrimitiveArray<ArrayType,BaseType>- Parameters:
index- the index where the space should be deletedcount- the number of values to delete
-
add
public abstract void add(int index, BaseType element)
-
remove
public BaseType remove(int index)
-
size
public int size()
- Specified by:
sizein interfaceCollection<ArrayType>- Specified by:
sizein interfaceList<ArrayType>- Specified by:
sizein classAbstractCollection<BaseType>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<ArrayType>- Specified by:
clearin interfaceList<ArrayType>- Overrides:
clearin classAbstractList<BaseType>
-
setSize
public void setSize(int size)
- Specified by:
setSizein interfacePrimitiveArray<ArrayType,BaseType>
-
checkBounds
protected void checkBounds(int index)
Checks that the index is less than the size of the array.
-
-