org.scijava.util
Class AbstractPrimitiveArray<ArrayType,BaseType>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<BaseType>
          extended by org.scijava.util.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>, Sizable
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
AbstractPrimitiveArray(Class<BaseType> type)
          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.
AbstractPrimitiveArray(Class<BaseType> type, int size)
          Constructs an extensible array of primitive type elements, backed by a fixed-size array.
 
Method Summary
abstract  void add(int index, BaseType element)
           
 int capacity()
          Gets the current capacity of the backing array.
protected  void checkBounds(int index)
          Checks that the index is less than the size of the array.
 void clear()
           
 ArrayType copyArray()
          Returns a copy of the primitive-array array.
 void delete(int index, int count)
          Shifts the array to delete space starting at a specified index.
 void ensureCapacity(int minCapacity)
          Makes sure the backing array at least a specified capacity.
 int getMaximumGrowth()
          Gets the maximal step size by which to grow the fixed-size array when running out of space.
 void insert(int index, int count)
          Shifts the array to insert space at a specified index.
 BaseType remove(int index)
           
abstract  BaseType set(int index, BaseType element)
           
 void setMaximumGrowth(int growth)
          Sets the maximal step size by which to grow the fixed-size array when running out of space.
 void setSize(int size)
           
 int size()
           
 
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 org.scijava.util.PrimitiveArray
defaultValue, getArray, setArray
 
Methods inherited from interface java.util.List
add, addAll, addAll, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, subList, toArray, toArray
 

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 type
size - the initial size

AbstractPrimitiveArray

public AbstractPrimitiveArray(Class<BaseType> type,
                              ArrayType array)
Constructs an extensible array of primitive type elements, backed by the given fixed-size array.

Parameters:
array - the array to wrap
type - the class of the primitive type
Method Detail

getMaximumGrowth

public int getMaximumGrowth()
Description copied from interface: PrimitiveArray
Gets the maximal step size by which to grow the fixed-size array when running out of space.

Specified by:
getMaximumGrowth in interface PrimitiveArray<ArrayType,BaseType>

setMaximumGrowth

public void setMaximumGrowth(int growth)
Description copied from interface: PrimitiveArray
Sets the maximal step size by which to grow the fixed-size array when running out of space.

Specified by:
setMaximumGrowth in interface PrimitiveArray<ArrayType,BaseType>

copyArray

public ArrayType copyArray()
Description copied from interface: PrimitiveArray
Returns a copy of the primitive-array array.

The returned array is guaranteed to have List.size() elements.

Specified by:
copyArray in interface PrimitiveArray<ArrayType,BaseType>
Returns:
the fixed-size array

capacity

public int capacity()
Gets the current capacity of the backing array.

Specified by:
capacity in interface PrimitiveArray<ArrayType,BaseType>

ensureCapacity

public void ensureCapacity(int minCapacity)
Description copied from interface: PrimitiveArray
Makes sure the backing array at least a specified capacity.

After calling this method, the internal array will have at least minCapacity elements.

Specified by:
ensureCapacity in interface PrimitiveArray<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:
insert in interface PrimitiveArray<ArrayType,BaseType>
Parameters:
index - the index where the space should be inserted
count - 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:
delete in interface PrimitiveArray<ArrayType,BaseType>
Parameters:
index - the index where the space should be deleted
count - the number of values to delete

set

public abstract BaseType set(int index,
                             BaseType element)
Specified by:
set in interface List<BaseType>
Overrides:
set in class AbstractList<BaseType>

add

public abstract void add(int index,
                         BaseType element)
Specified by:
add in interface List<BaseType>
Overrides:
add in class AbstractList<BaseType>

remove

public BaseType remove(int index)
Specified by:
remove in interface List<BaseType>
Overrides:
remove in class AbstractList<BaseType>

size

public int size()
Specified by:
size in interface Collection<BaseType>
Specified by:
size in interface List<BaseType>
Specified by:
size in interface Sizable
Specified by:
size in class AbstractCollection<BaseType>

clear

public void clear()
Specified by:
clear in interface Collection<BaseType>
Specified by:
clear in interface List<BaseType>
Overrides:
clear in class AbstractList<BaseType>

setSize

public void setSize(int size)
Specified by:
setSize in interface Sizable

checkBounds

protected void checkBounds(int index)
Checks that the index is less than the size of the array.



Copyright © 2009–2014 SciJava. All rights reserved.