Package org.jibx.runtime.impl
Class GrowableIntArray
java.lang.Object
org.jibx.runtime.impl.GrowableIntArray
Growable
int
array with type specific access methods. This
implementation is unsynchronized in order to provide the best possible
performance for typical usage scenarios, so explicit synchronization must
be implemented by a wrapper class or directly by the application in cases
where instances are modified in a multithreaded environment.- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default initial array size.private int[]
The underlying array used for storing the data.private int
Size of the current array.private int
The number of values currently present in the array.private int
Maximum size increment for growing array. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.GrowableIntArray
(int size) Constructor with initial size specified.GrowableIntArray
(int size, int growth) Constructor with full specification.Copy (clone) constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int value) Add a value at the end of the array.void
addAll
(int[] values) Add an array of values at the end of the array.void
clear()
Set the array to the empty state.clone()
Duplicates the object with the generic call.final void
ensureCapacity
(int min) Ensure that the array has the capacity for at least the specified number of values.int
get
(int index) Get a value from the array.private int
Gets the array offset for appending a value to those in the array.private void
growArray
(int required) Increase the size of the array to at least a specified size.boolean
isEmpty()
Check if array is empty.void
remove
(int count) Remove some number of values from the end of the array.private void
resizeCopy
(Object base, Object grown) Copy data after array resize.void
set
(int index, int value) Overwrite an existing value in the array.int
size()
Get the number of values currently present in the array.int[]
toArray()
Constructs and returns a simple array containing the same data as held in this array.
-
Field Details
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEDefault initial array size.- See Also:
-
m_countLimit
private int m_countLimitSize of the current array. -
m_countPresent
private int m_countPresentThe number of values currently present in the array. -
m_maximumGrowth
private int m_maximumGrowthMaximum size increment for growing array. -
m_baseArray
private int[] m_baseArrayThe underlying array used for storing the data.
-
-
Constructor Details
-
GrowableIntArray
public GrowableIntArray(int size, int growth) Constructor with full specification.- Parameters:
size
- number ofint
values initially allowed in arraygrowth
- maximum size increment for growing array
-
GrowableIntArray
public GrowableIntArray(int size) Constructor with initial size specified.- Parameters:
size
- number ofint
values initially allowed in array
-
GrowableIntArray
public GrowableIntArray()Default constructor. -
GrowableIntArray
Copy (clone) constructor.- Parameters:
base
- instance being copied
-
-
Method Details
-
resizeCopy
Copy data after array resize. This just copies the entire contents of the old array to the start of the new array. It should be overridden in cases where data needs to be rearranged in the array after a resize.- Parameters:
base
- original array containing datagrown
- resized array for data
-
growArray
private void growArray(int required) Increase the size of the array to at least a specified size. The array will normally be at least doubled in size, but if a maximum size increment was specified in the constructor and the value is less than the current size of the array, the maximum increment will be used instead. If the requested size requires more than the default growth, the requested size overrides the normal growth and determines the size of the replacement array.- Parameters:
required
- new minimum size required
-
ensureCapacity
public final void ensureCapacity(int min) Ensure that the array has the capacity for at least the specified number of values.- Parameters:
min
- minimum capacity to be guaranteed
-
set
public void set(int index, int value) Overwrite an existing value in the array.- Parameters:
index
- position of value to be overwrittenvalue
- value to be added
-
add
public void add(int value) Add a value at the end of the array.- Parameters:
value
- value to be added
-
addAll
public void addAll(int[] values) Add an array of values at the end of the array.- Parameters:
values
- values to be added
-
remove
public void remove(int count) Remove some number of values from the end of the array.- Parameters:
count
- number of values to be removed- Throws:
ArrayIndexOutOfBoundsException
- on attempt to remove more than the count present
-
get
public int get(int index) Get a value from the array.- Parameters:
index
- index of value to be returned- Returns:
- value from stack
- Throws:
ArrayIndexOutOfBoundsException
- on attempt to access outside valid range
-
toArray
public int[] toArray()Constructs and returns a simple array containing the same data as held in this array.- Returns:
- array containing a copy of the data
-
clone
Duplicates the object with the generic call. -
getAddIndex
private int getAddIndex()Gets the array offset for appending a value to those in the array. If the underlying array is full, it is grown by the appropriate size increment so that the index value returned is always valid for the array in use by the time of the return.- Returns:
- index position for added element
-
size
public int size()Get the number of values currently present in the array.- Returns:
- count of values present
-
isEmpty
public boolean isEmpty()Check if array is empty.- Returns:
true
if array empty,false
if not
-
clear
public void clear()Set the array to the empty state.
-