Package uk.ac.starlink.util
Class PrimitiveList
- java.lang.Object
-
- uk.ac.starlink.util.PrimitiveList
-
public abstract class PrimitiveList extends java.lang.Object
Provides an extendable list of primitive values. This provides an abstract superclass for concrete implementations which do roughly the same job for numeric primitive types thatStringBuffer
does forchar
s andList
does forObject
s.- Since:
- 12 Oct 2006
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PrimitiveList(java.lang.Object array, int size)
Constructs a list from an initial array object, whose component type determines the primitive type which this list will work with, and a size, which indicates number of elements of the array which are initially considered to constitute the contents of this list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all of the elements from this list (optional operation).protected int
nextCapacity(int currentCapacity)
Determines by how much the storage array will grow if it needs to expand.int
size()
Returns the current size of this list.java.lang.Object
toArray()
Creates and returns a copy of the contents of this list, in the form of a primitive array of the right length to hold all the elements it currently contains.
-
-
-
Constructor Detail
-
PrimitiveList
protected PrimitiveList(java.lang.Object array, int size)
Constructs a list from an initial array object, whose component type determines the primitive type which this list will work with, and a size, which indicates number of elements of the array which are initially considered to constitute the contents of this list.- Parameters:
array
- array objectsize
- initial list size (note, not capacity)
-
-
Method Detail
-
size
public int size()
Returns the current size of this list.- Returns:
- number of elements which have been stored
-
clear
public void clear()
Removes all of the elements from this list (optional operation). The list will be empty after this call returns.
-
toArray
public java.lang.Object toArray()
Creates and returns a copy of the contents of this list, in the form of a primitive array of the right length to hold all the elements it currently contains.- Returns:
- array containing contents of this list
-
nextCapacity
protected int nextCapacity(int currentCapacity)
Determines by how much the storage array will grow if it needs to expand. Any return value is legal; if a value less than thecurrentCapacity
is returned, Integer.MAX_VALUE will be used. The effect of this is that implementations probably do not need to worry about integer arithmetic overflow. May be overridden by subclasses.- Parameters:
currentCapacity
- initial size of buffer- Returns:
- next size up
-
-