Top Description Inners Fields Constructors Methods
org.apache.commons.math3.util

public Class ResizableDoubleArray

extends Object
implements DoubleArray, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.util.DoubleArray
Imports
java.io.Serializable, java.util.Arrays, org.apache.commons.math3.exception.MathIllegalArgumentException, .MathIllegalStateException, .MathInternalError, .NullArgumentException, .NotStrictlyPositiveException, .NumberIsTooSmallException, org.apache.commons.math3.exception.util.LocalizedFormats

A variable length DoubleArray implementation that automatically handles expanding and contracting its internal storage array as elements are added and removed.

Important note: Usage should not assume that this class is thread-safe even though some of the methods are synchronized. This qualifier will be dropped in the next major release (4.0).

The internal storage array starts with capacity determined by the initialCapacity property, which can be set by the constructor. The default initial capacity is 16. Adding elements using addElement(double) appends elements to the end of the array. When there are no open entries at the end of the internal storage array, the array is expanded. The size of the expanded array depends on the expansionMode and expansionFactor properties. The expansionMode determines whether the size of the array is multiplied by the expansionFactor (ExpansionMode#MULTIPLICATIVE) or if the expansion is additive (ExpansionMode#ADDITIVE -- expansionFactor storage locations added). The default expansionMode is MULTIPLICATIVE and the default expansionFactor is 2.

The addElementRolling(double) method adds a new element to the end of the internal storage array and adjusts the "usable window" of the internal array forward by one position (effectively making what was the second element the first, and so on). Repeated activations of this method (or activation of discardFrontElements(int)) will effectively orphan the storage locations at the beginning of the internal storage array. To reclaim this storage, each time one of these methods is activated, the size of the internal storage array is compared to the number of addressable elements (the numElements property) and if the difference is too large, the internal array is contracted to size numElements + 1. The determination of when the internal storage array is "too large" depends on the expansionMode and contractionFactor properties. If the expansionMode is MULTIPLICATIVE, contraction is triggered when the ratio between storage array length and numElements exceeds contractionFactor. If the expansionMode is ADDITIVE, the number of excess storage locations is compared to contractionFactor.

To avoid cycles of expansions and contractions, the expansionFactor must not exceed the contractionFactor. Constructors and mutators for both of these properties enforce this requirement, throwing a MathIllegalArgumentException if it is violated.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
ResizableDoubleArray.ExpansionMode

Specification of expansion algorithm.

Field Summary

Modifier and TypeField and Description
public static final int
ADDITIVE_MODE

Deprecated As of 3.1. Please use ExpansionMode#ADDITIVE instead.
Additive expansion mode.
private double
contractionCriterion

The contraction criteria determines when the internal array will be contracted to fit the number of elements contained in the element array + 1.

private static final double
DEFAULT_CONTRACTION_DELTA

Default value for the difference between contractionCriterion and expansionFactor.

private static final double
DEFAULT_EXPANSION_FACTOR

Default value for array size modifier.

private static final int
DEFAULT_INITIAL_CAPACITY

Default value for initial capacity.

private double
expansionFactor

The expansion factor of the array.

private ResizableDoubleArray.ExpansionMode
expansionMode

Determines whether array expansion by expansionFactor is additive or multiplicative.

private double[]
internalArray

The internal storage array.

public static final int
MULTIPLICATIVE_MODE

Deprecated As of 3.1. Please use ExpansionMode#MULTIPLICATIVE instead.
Multiplicative expansion mode.
private int
numElements

The number of addressable elements in the array.

private static final long
serialVersionUID

Serializable version identifier.

private int
startIndex

The position of the first addressable element in the internal storage array.

Constructor Summary

AccessConstructor and Description
public
ResizableDoubleArray()

Creates an instance with default properties.

public
ResizableDoubleArray(int
Initial size of the internal storage array.
initialCapacity
)

Creates an instance with the specified initial capacity.

public
ResizableDoubleArray(double[]
initial array
initialArray
)

Creates an instance from an existing double[] with the initial capacity and numElements corresponding to the size of the supplied double[] array.

public
ResizableDoubleArray(int
Initial size of the internal storage array.
initialCapacity
,
float
The array will be expanded based on this parameter.
expansionFactor
)
Deprecated As of 3.1. Please use ResizableDoubleArray(int, double) instead.

Creates an instance with the specified initial capacity and expansion factor.

public
ResizableDoubleArray(int
Initial size of the internal storage array.
initialCapacity
,
double
The array will be expanded based on this parameter.
expansionFactor
)

Creates an instance with the specified initial capacity and expansion factor.

public
ResizableDoubleArray(int
Initial size of the internal storage array..
initialCapacity
,
float
The array will be expanded based on this parameter.
expansionFactor
,
float
Contraction criteria.
contractionCriteria
)
Deprecated As of 3.1. Please use ResizableDoubleArray(int, double, double) instead.

Creates an instance with the specified initialCapacity, expansionFactor, and contractionCriterion.

public
ResizableDoubleArray(int
Initial size of the internal storage array..
initialCapacity
,
double
The array will be expanded based on this parameter.
expansionFactor
,
double
Contraction criterion.
contractionCriterion
)

Creates an instance with the specified initial capacity, expansion factor, and contraction criteria.

public
ResizableDoubleArray(int
the initial size of the internal storage array
initialCapacity
,
float
the array will be expanded based on this parameter
expansionFactor
,
float
the contraction Criteria
contractionCriteria
,
int
the expansion mode
expansionMode
)
Deprecated As of 3.1.

Create a ResizableArray with the specified properties.

public
ResizableDoubleArray(int
Initial size of the internal storage array.
initialCapacity
,
double
The array will be expanded based on this parameter.
expansionFactor
,
double
Contraction criteria.
contractionCriterion
,
ResizableDoubleArray.ExpansionMode
Expansion mode.
expansionMode
,
double...
Initial contents of the array.
data
)

Creates an instance with the specified properties.

public
ResizableDoubleArray(ResizableDoubleArray
array to copy
original
)

Copy constructor.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addElement(double
Value to be added to end of array.
value
)

Implements org.apache.commons.math3.util.DoubleArray.addElement.

Adds an element to the end of this expandable array.

public synchronized double

Returns:

the value which has been discarded or "pushed" out of the array by this rolling insert.
addElementRolling
(double
Value to be added to the array.
value
)

Implements org.apache.commons.math3.util.DoubleArray.addElementRolling.

Adds an element to the end of the array and removes the first element in the array.

public synchronized void
addElements(double[]
Values to be added to end of array.
values
)

Implements org.apache.commons.math3.util.DoubleArray.addElements.

Adds several element to the end of this expandable array.

protected void
checkContractExpand(float
criteria to be checked
contraction
,
float
factor to be checked
expansion
)
Deprecated As of 3.1. Please use checkContractExpand(double, double) instead.

Checks the expansion factor and the contraction criterion and throws an IllegalArgumentException if the contractionCriteria is less than the expansionCriteria

protected void
checkContractExpand(double
Criterion to be checked.
contraction
,
double
Factor to be checked.
expansion
)

Checks the expansion factor and the contraction criterion and raises an exception if the contraction criterion is smaller than the expansion criterion.

public synchronized void
clear()

Implements org.apache.commons.math3.util.DoubleArray.clear.

Clear the array contents, resetting the number of elements to zero.

public double

Returns:

the result.
compute
(MathArrays.Function
Function to be applied on this array.
f
)

Performs an operation on the addressable elements of the array.

public synchronized void
contract()

Contracts the storage array to the (size of the element set) + 1 - to avoid a zero length array.

public static void
copy(ResizableDoubleArray
ResizableDoubleArray to copy
source
,
ResizableDoubleArray
ResizableArray to replace with a copy of the source array
dest
)

Copies source to dest, copying the underlying data, so dest is a new, independent copy of source.

public synchronized ResizableDoubleArray

Returns:

a new ResizableDoubleArray with the same data and configuration properties as this
copy
()

Returns a copy of the ResizableDoubleArray.

private synchronized void
discardExtremeElements(int
the number of elements to discard from the front/end of the array
i
,
boolean
true if elements are to be discarded from the front of the array, false if elements are to be discarded from the end of the array
front
)

Discards the i first or last elements of the array, depending on the value of front.

public synchronized void
discardFrontElements(int
the number of elements to discard from the front of the array
i
)

Discards the i initial elements of the array.

public synchronized void
discardMostRecentElements(int
the number of elements to discard from the end of the array
i
)

Discards the i last elements of the array.

public boolean

Returns:

true iff object is a ResizableDoubleArray with the same data and properties as this
equals
(Object
object to be compared for equality with this
object
)

Overrides java.lang.Object.equals.

Returns true iff object is a ResizableDoubleArray with the same properties as this and an identical internal storage array.

protected synchronized void
expand()

Expands the internal storage array using the expansion factor.

private synchronized void
expandTo(int
Size of the new internal storage array.
size
)

Expands the internal storage array to the specified size.

protected double[]

Returns:

the internal storage array used by this object.
getArrayRef
()

Provides direct access to the internal storage array.

public int

Returns:

the length of the internal array.
getCapacity
()

Gets the currently allocated size of the internal data structure used for storing elements.

public float

Returns:

the contraction criteria used to reclaim memory.
getContractionCriteria
()
Deprecated As of 3.1. Please use getContractionCriterion() instead.

The contraction criteria defines when the internal array will contract to store only the number of elements in the element array.

public double

Returns:

the contraction criterion used to reclaim memory.
getContractionCriterion
()

The contraction criterion defines when the internal array will contract to store only the number of elements in the element array.

public synchronized double

Returns:

value stored at the specified index
getElement
(int
index to fetch a value from
index
)

Implements org.apache.commons.math3.util.DoubleArray.getElement.

Returns the element at the specified index

public synchronized double[]

Returns:

the double array.
getElements
()

Implements org.apache.commons.math3.util.DoubleArray.getElements.

Returns a double array containing the elements of this ResizableArray.

public float

Returns:

the expansion factor of this expandable double array
getExpansionFactor
()
Deprecated As of 3.1. Return type will be changed to "double" in 4.0.

The expansion factor controls the size of a new array when an array needs to be expanded.

public int

Returns:

the expansion mode.
getExpansionMode
()
Deprecated As of 3.1. Return value to be changed to ExpansionMode in 4.0.

The expansion mode determines whether the internal storage array grows additively or multiplicatively when it is expanded.

pack-priv synchronized int

Returns:

the length of the internal storage array.
getInternalLength
()
Deprecated As of 3.1. Please use getCapacity() instead.

Notice the package scope on this method.

public synchronized double[]

Returns:

the internal storage array used by this object
getInternalValues
()
Deprecated As of 3.1.

Returns the internal storage array.

public synchronized int

Returns:

the number of elements.
getNumElements
()

Implements org.apache.commons.math3.util.DoubleArray.getNumElements.

Returns the number of elements currently in the array.

protected int

Returns:

the start index.
getStartIndex
()

Returns the "start index" of the internal array.

public synchronized int

Returns:

the hash code representing this ResizableDoubleArray.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code consistent with equals.

public void
setContractionCriteria(float
contraction criteria
contractionCriteria
)
Deprecated As of 3.1 (to be removed in 4.0 as field will become "final").

Sets the contraction criteria.

public synchronized void
setElement(int
index to store a value in
index
,
double
value to store at the specified index
value
)

Implements org.apache.commons.math3.util.DoubleArray.setElement.

Sets the element at the specified index.

public void
setExpansionFactor(float
the new expansion factor value.
expansionFactor
)
Deprecated As of 3.1 (to be removed in 4.0 as field will become "final").

Sets the expansionFactor.

public void
setExpansionMode(int
The expansionMode to set.
expansionMode
)
Deprecated As of 3.1.

Sets the expansionMode.

public void
setExpansionMode(ResizableDoubleArray.ExpansionMode
Expansion mode to use for resizing the array.
expansionMode
)
Deprecated As of 3.1 (to be removed in 4.0 as field will become "final").

Sets the expansion mode.

protected void
setInitialCapacity(int
of the array
initialCapacity
)
Deprecated As of 3.1, this is a no-op.

Sets the initial capacity.

public synchronized void
setNumElements(int
a new number of elements
i
)

This function allows you to control the number of elements contained in this array, and can be used to "throw out" the last n values in an array.

private synchronized boolean

Returns:

true if array satisfies the contraction criteria
shouldContract
()

Returns true if the internal storage array has too many unused storage positions.

public synchronized int

Returns:

the starting index.
start
()
Deprecated As of 3.1.

Returns the starting index of the internal array.

public synchronized double

Returns:

the value that has been replaced in the array.
substituteMostRecentElement
(double
New value to substitute for the most recently added value
value
)

Substitutes value for the most recently added value.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

ADDITIVE_MODEback to summary
public static final int ADDITIVE_MODE

Deprecated

As of 3.1. Please use ExpansionMode#ADDITIVE instead.

Additive expansion mode.

Annotations
@Deprecated
contractionCriterionback to summary
private double contractionCriterion

The contraction criteria determines when the internal array will be contracted to fit the number of elements contained in the element array + 1.

DEFAULT_CONTRACTION_DELTAback to summary
private static final double DEFAULT_CONTRACTION_DELTA

Default value for the difference between contractionCriterion and expansionFactor.

DEFAULT_EXPANSION_FACTORback to summary
private static final double DEFAULT_EXPANSION_FACTOR

Default value for array size modifier.

DEFAULT_INITIAL_CAPACITYback to summary
private static final int DEFAULT_INITIAL_CAPACITY

Default value for initial capacity.

expansionFactorback to summary
private double expansionFactor

The expansion factor of the array. When the array needs to be expanded, the new array size will be internalArray.length * expansionFactor if expansionMode is set to MULTIPLICATIVE_MODE, or internalArray.length + expansionFactor if expansionMode is set to ADDITIVE_MODE.

expansionModeback to summary
private ResizableDoubleArray.ExpansionMode expansionMode

Determines whether array expansion by expansionFactor is additive or multiplicative.

internalArrayback to summary
private double[] internalArray

The internal storage array.

MULTIPLICATIVE_MODEback to summary
public static final int MULTIPLICATIVE_MODE

Deprecated

As of 3.1. Please use ExpansionMode#MULTIPLICATIVE instead.

Multiplicative expansion mode.

Annotations
@Deprecated
numElementsback to summary
private int numElements

The number of addressable elements in the array. Note that this has nothing to do with the length of the internal storage array.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier.

startIndexback to summary
private int startIndex

The position of the first addressable element in the internal storage array. The addressable elements in the array are internalArray[startIndex],...,internalArray[startIndex + numElements - 1].

Constructor Detail

ResizableDoubleArrayback to summary
public ResizableDoubleArray()

Creates an instance with default properties.

  • initialCapacity = 16
  • expansionMode = MULTIPLICATIVE
  • expansionFactor = 2.0
  • contractionCriterion = 2.5
ResizableDoubleArrayback to summary
public ResizableDoubleArray(int initialCapacity) throws MathIllegalArgumentException

Creates an instance with the specified initial capacity. Other properties take default values:

  • expansionMode = MULTIPLICATIVE
  • expansionFactor = 2.0
  • contractionCriterion = 2.5
Parameters
initialCapacity:int

Initial size of the internal storage array.

Exceptions
MathIllegalArgumentException:
if initialCapacity <= 0.
ResizableDoubleArrayback to summary
public ResizableDoubleArray(double[] initialArray)

Creates an instance from an existing double[] with the initial capacity and numElements corresponding to the size of the supplied double[] array. If the supplied array is null, a new empty array with the default initial capacity will be created. The input array is copied, not referenced. Other properties take default values:

  • initialCapacity = 16
  • expansionMode = MULTIPLICATIVE
  • expansionFactor = 2.0
  • contractionCriterion = 2.5
Parameters
initialArray:double[]

initial array

Since
2.2
ResizableDoubleArrayback to summary
public ResizableDoubleArray(int initialCapacity, float expansionFactor) throws MathIllegalArgumentException

Deprecated

As of 3.1. Please use ResizableDoubleArray(int, double) instead.

Creates an instance with the specified initial capacity and expansion factor. The remaining properties take default values:

  • expansionMode = MULTIPLICATIVE
  • contractionCriterion = 0.5 + expansionFactor

Throws IllegalArgumentException if the following conditions are not met:
  • initialCapacity > 0
  • expansionFactor > 1
Parameters
initialCapacity:int

Initial size of the internal storage array.

expansionFactor:float

The array will be expanded based on this parameter.

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if parameters are not valid.
ResizableDoubleArrayback to summary
public ResizableDoubleArray(int initialCapacity, double expansionFactor) throws MathIllegalArgumentException

Creates an instance with the specified initial capacity and expansion factor. The remaining properties take default values:

  • expansionMode = MULTIPLICATIVE
  • contractionCriterion = 0.5 + expansionFactor

Throws IllegalArgumentException if the following conditions are not met:
  • initialCapacity > 0
  • expansionFactor > 1
Parameters
initialCapacity:int

Initial size of the internal storage array.

expansionFactor:double

The array will be expanded based on this parameter.

Exceptions
MathIllegalArgumentException:
if parameters are not valid.
Since
3.1
ResizableDoubleArrayback to summary
public ResizableDoubleArray(int initialCapacity, float expansionFactor, float contractionCriteria) throws MathIllegalArgumentException

Deprecated

As of 3.1. Please use ResizableDoubleArray(int, double, double) instead.

Creates an instance with the specified initialCapacity, expansionFactor, and contractionCriterion. The expansion mode will default to MULTIPLICATIVE.
Throws IllegalArgumentException if the following conditions are not met:

  • initialCapacity > 0
  • expansionFactor > 1
  • contractionCriterion >= expansionFactor
Parameters
initialCapacity:int

Initial size of the internal storage array..

expansionFactor:float

The array will be expanded based on this parameter.

contractionCriteria:float

Contraction criteria.

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if parameters are not valid.
ResizableDoubleArrayback to summary
public ResizableDoubleArray(int initialCapacity, double expansionFactor, double contractionCriterion) throws MathIllegalArgumentException

Creates an instance with the specified initial capacity, expansion factor, and contraction criteria. The expansion mode will default to MULTIPLICATIVE.
Throws IllegalArgumentException if the following conditions are not met:

  • initialCapacity > 0
  • expansionFactor > 1
  • contractionCriterion >= expansionFactor
Parameters
initialCapacity:int

Initial size of the internal storage array..

expansionFactor:double

The array will be expanded based on this parameter.

contractionCriterion:double

Contraction criterion.

Exceptions
MathIllegalArgumentException:
if the parameters are not valid.
Since
3.1
ResizableDoubleArrayback to summary
public ResizableDoubleArray(int initialCapacity, float expansionFactor, float contractionCriteria, int expansionMode) throws MathIllegalArgumentException

Create a ResizableArray with the specified properties.

Throws IllegalArgumentException if the following conditions are not met:

  • initialCapacity > 0
  • expansionFactor > 1
  • contractionFactor >= expansionFactor
  • expansionMode in {MULTIPLICATIVE_MODE, ADDITIVE_MODE}

Parameters
initialCapacity:int

the initial size of the internal storage array

expansionFactor:float

the array will be expanded based on this parameter

contractionCriteria:float

the contraction Criteria

expansionMode:int

the expansion mode

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if parameters are not valid
ResizableDoubleArrayback to summary
public ResizableDoubleArray(int initialCapacity, double expansionFactor, double contractionCriterion, ResizableDoubleArray.ExpansionMode expansionMode, double... data) throws MathIllegalArgumentException

Creates an instance with the specified properties.
Throws MathIllegalArgumentException if the following conditions are not met:

  • initialCapacity > 0
  • expansionFactor > 1
  • contractionCriterion >= expansionFactor
Parameters
initialCapacity:int

Initial size of the internal storage array.

expansionFactor:double

The array will be expanded based on this parameter.

contractionCriterion:double

Contraction criteria.

expansionMode:ResizableDoubleArray.ExpansionMode

Expansion mode.

data:double[]

Initial contents of the array.

Exceptions
MathIllegalArgumentException:
if the parameters are not valid.
ResizableDoubleArrayback to summary
public ResizableDoubleArray(ResizableDoubleArray original) throws NullArgumentException

Copy constructor. Creates a new ResizableDoubleArray that is a deep, fresh copy of the original. Needs to acquire synchronization lock on original. Original may not be null; otherwise a NullArgumentException is thrown.

Parameters
original:ResizableDoubleArray

array to copy

Exceptions
NullArgumentException:
if original is null
Since
2.0

Method Detail

addElementback to summary
public synchronized void addElement(double value)

Implements org.apache.commons.math3.util.DoubleArray.addElement.

Adds an element to the end of this expandable array.

Parameters
value:double

Value to be added to end of array.

addElementRollingback to summary
public synchronized double addElementRolling(double value)

Implements org.apache.commons.math3.util.DoubleArray.addElementRolling.

Adds an element to the end of the array and removes the first element in the array. Returns the discarded first element. The effect is similar to a push operation in a FIFO queue.

Example: If the array contains the elements 1, 2, 3, 4 (in that order) and addElementRolling(5) is invoked, the result is an array containing the entries 2, 3, 4, 5 and the value returned is 1.

Parameters
value:double

Value to be added to the array.

Returns:double

the value which has been discarded or "pushed" out of the array by this rolling insert.

addElementsback to summary
public synchronized void addElements(double[] values)

Implements org.apache.commons.math3.util.DoubleArray.addElements.

Adds several element to the end of this expandable array.

Parameters
values:double[]

Values to be added to end of array.

Since
2.2
checkContractExpandback to summary
protected void checkContractExpand(float contraction, float expansion) throws MathIllegalArgumentException

Deprecated

As of 3.1. Please use checkContractExpand(double, double) instead.

Checks the expansion factor and the contraction criterion and throws an IllegalArgumentException if the contractionCriteria is less than the expansionCriteria

Parameters
contraction:float

criteria to be checked

expansion:float

factor to be checked

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if the contractionCriteria is less than the expansionCriteria.
checkContractExpandback to summary
protected void checkContractExpand(double contraction, double expansion) throws NumberIsTooSmallException

Checks the expansion factor and the contraction criterion and raises an exception if the contraction criterion is smaller than the expansion criterion.

Parameters
contraction:double

Criterion to be checked.

expansion:double

Factor to be checked.

Exceptions
NumberIsTooSmallException:
  • if contraction < expansion.
  • if contraction <= 1.
  • if expansion <= 1 .
Since
3.1
clearback to summary
public synchronized void clear()

Implements org.apache.commons.math3.util.DoubleArray.clear.

Clear the array contents, resetting the number of elements to zero.

computeback to summary
public double compute(MathArrays.Function f)

Performs an operation on the addressable elements of the array.

Parameters
f:MathArrays.Function

Function to be applied on this array.

Returns:double

the result.

Since
3.1
contractback to summary
public synchronized void contract()

Contracts the storage array to the (size of the element set) + 1 - to avoid a zero length array. This function also resets the startIndex to zero.

copyback to summary
public static void copy(ResizableDoubleArray source, ResizableDoubleArray dest) throws NullArgumentException

Copies source to dest, copying the underlying data, so dest is a new, independent copy of source. Does not contract before the copy.

Obtains synchronization locks on both source and dest (in that order) before performing the copy.

Neither source nor dest may be null; otherwise a NullArgumentException is thrown

Parameters
source:ResizableDoubleArray

ResizableDoubleArray to copy

dest:ResizableDoubleArray

ResizableArray to replace with a copy of the source array

Exceptions
NullArgumentException:
if either source or dest is null
Since
2.0
copyback to summary
public synchronized ResizableDoubleArray copy()

Returns a copy of the ResizableDoubleArray. Does not contract before the copy, so the returned object is an exact copy of this.

Returns:ResizableDoubleArray

a new ResizableDoubleArray with the same data and configuration properties as this

Since
2.0
discardExtremeElementsback to summary
private synchronized void discardExtremeElements(int i, boolean front) throws MathIllegalArgumentException

Discards the i first or last elements of the array, depending on the value of front. For example, if the array contains the elements 1,2,3,4, invoking discardExtremeElements(2,false) will cause the last two elements to be discarded, leaving 1,2 in the array. For example, if the array contains the elements 1,2,3,4, invoking discardExtremeElements(2,true) will cause the first two elements to be discarded, leaving 3,4 in the array. Throws illegalArgumentException if i exceeds numElements.

Parameters
i:int

the number of elements to discard from the front/end of the array

front:boolean

true if elements are to be discarded from the front of the array, false if elements are to be discarded from the end of the array

Exceptions
MathIllegalArgumentException:
if i is greater than numElements.
Since
2.0
discardFrontElementsback to summary
public synchronized void discardFrontElements(int i) throws MathIllegalArgumentException

Discards the i initial elements of the array. For example, if the array contains the elements 1,2,3,4, invoking discardFrontElements(2) will cause the first two elements to be discarded, leaving 3,4 in the array. Throws illegalArgumentException if i exceeds numElements.

Parameters
i:int

the number of elements to discard from the front of the array

Exceptions
MathIllegalArgumentException:
if i is greater than numElements.
Since
2.0
discardMostRecentElementsback to summary
public synchronized void discardMostRecentElements(int i) throws MathIllegalArgumentException

Discards the i last elements of the array. For example, if the array contains the elements 1,2,3,4, invoking discardMostRecentElements(2) will cause the last two elements to be discarded, leaving 1,2 in the array. Throws illegalArgumentException if i exceeds numElements.

Parameters
i:int

the number of elements to discard from the end of the array

Exceptions
MathIllegalArgumentException:
if i is greater than numElements.
Since
2.0
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Returns true iff object is a ResizableDoubleArray with the same properties as this and an identical internal storage array.

Parameters
object:Object

object to be compared for equality with this

Returns:boolean

true iff object is a ResizableDoubleArray with the same data and properties as this

Annotations
@Override
Since
2.0
expandback to summary
protected synchronized void expand()

Expands the internal storage array using the expansion factor.

if expansionMode is set to MULTIPLICATIVE_MODE, the new array size will be internalArray.length * expansionFactor. If expansionMode is set to ADDITIVE_MODE, the length after expansion will be internalArray.length + expansionFactor

expandToback to summary
private synchronized void expandTo(int size)

Expands the internal storage array to the specified size.

Parameters
size:int

Size of the new internal storage array.

getArrayRefback to summary
protected double[] getArrayRef()

Provides direct access to the internal storage array. Please note that this method returns a reference to this object's storage array, not a copy.
To correctly address elements of the array, the "start index" is required (available via the getStartIndex method.
This method should only be used to avoid copying the internal array. The returned value must be used for reading only; other uses could lead to this object becoming inconsistent.
The getElements method has no such limitation since it returns a copy of this array's addressable elements.

Returns:double[]

the internal storage array used by this object.

Since
3.1
getCapacityback to summary
public int getCapacity()

Gets the currently allocated size of the internal data structure used for storing elements. This is not to be confused with the number of elements actually stored.

Returns:int

the length of the internal array.

Since
3.1
getContractionCriteriaback to summary
public float getContractionCriteria()

Deprecated

As of 3.1. Please use getContractionCriterion() instead.

The contraction criteria defines when the internal array will contract to store only the number of elements in the element array. If the expansionMode is MULTIPLICATIVE_MODE, contraction is triggered when the ratio between storage array length and numElements exceeds contractionFactor. If the expansionMode is ADDITIVE_MODE, the number of excess storage locations is compared to contractionFactor.

Returns:float

the contraction criteria used to reclaim memory.

Annotations
@Deprecated
getContractionCriterionback to summary
public double getContractionCriterion()

The contraction criterion defines when the internal array will contract to store only the number of elements in the element array. If the expansionMode is MULTIPLICATIVE_MODE, contraction is triggered when the ratio between storage array length and numElements exceeds contractionFactor. If the expansionMode is ADDITIVE_MODE, the number of excess storage locations is compared to contractionFactor.

Returns:double

the contraction criterion used to reclaim memory.

Since
3.1
getElementback to summary
public synchronized double getElement(int index)

Implements org.apache.commons.math3.util.DoubleArray.getElement.

Returns the element at the specified index

Parameters
index:int

index to fetch a value from

Returns:double

value stored at the specified index

Exceptions
ArrayIndexOutOfBoundsException:
if index is less than zero or is greater than getNumElements() - 1.
getElementsback to summary
public synchronized double[] getElements()

Implements org.apache.commons.math3.util.DoubleArray.getElements.

Returns a double array containing the elements of this ResizableArray. This method returns a copy, not a reference to the underlying array, so that changes made to the returned array have no effect on this ResizableArray.

Returns:double[]

the double array.

getExpansionFactorback to summary
public float getExpansionFactor()

Deprecated

As of 3.1. Return type will be changed to "double" in 4.0.

The expansion factor controls the size of a new array when an array needs to be expanded. The expansionMode determines whether the size of the array is multiplied by the expansionFactor (MULTIPLICATIVE_MODE) or if the expansion is additive (ADDITIVE_MODE -- expansionFactor storage locations added). The default expansionMode is MULTIPLICATIVE_MODE and the default expansionFactor is 2.0.

Returns:float

the expansion factor of this expandable double array

Annotations
@Deprecated
getExpansionModeback to summary
public int getExpansionMode()

Deprecated

As of 3.1. Return value to be changed to ExpansionMode in 4.0.

The expansion mode determines whether the internal storage array grows additively or multiplicatively when it is expanded.

Returns:int

the expansion mode.

Annotations
@Deprecated
getInternalLengthback to summary
pack-priv synchronized int getInternalLength()

Deprecated

As of 3.1. Please use getCapacity() instead.

Notice the package scope on this method. This method is simply here for the JUnit test, it allows us check if the expansion is working properly after a number of expansions. This is not meant to be a part of the public interface of this class.

Returns:int

the length of the internal storage array.

Annotations
@Deprecated
getInternalValuesback to summary
public synchronized double[] getInternalValues()

Deprecated

As of 3.1.

Returns the internal storage array. Note that this method returns a reference to the internal storage array, not a copy, and to correctly address elements of the array, the startIndex is required (available via the start method). This method should only be used in cases where copying the internal array is not practical. The getElements method should be used in all other cases.

Returns:double[]

the internal storage array used by this object

Annotations
@Deprecated
Since
2.0
getNumElementsback to summary
public synchronized int getNumElements()

Implements org.apache.commons.math3.util.DoubleArray.getNumElements.

Returns the number of elements currently in the array. Please note that this is different from the length of the internal storage array.

Returns:int

the number of elements.

getStartIndexback to summary
protected int getStartIndex()

Returns the "start index" of the internal array. This index is the position of the first addressable element in the internal storage array. The addressable elements in the array are at indices contained in the interval [getStartIndex(), getStartIndex() + getNumElements() - 1].

Returns:int

the start index.

Since
3.1
hashCodeback to summary
public synchronized int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code consistent with equals.

Returns:int

the hash code representing this ResizableDoubleArray.

Annotations
@Override
Since
2.0
setContractionCriteriaback to summary
public void setContractionCriteria(float contractionCriteria) throws MathIllegalArgumentException

Deprecated

As of 3.1 (to be removed in 4.0 as field will become "final").

Sets the contraction criteria.

Parameters
contractionCriteria:float

contraction criteria

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if the contractionCriteria is less than the expansionCriteria.
setElementback to summary
public synchronized void setElement(int index, double value)

Implements org.apache.commons.math3.util.DoubleArray.setElement.

Sets the element at the specified index. If the specified index is greater than getNumElements() - 1, the numElements property is increased to index +1 and additional storage is allocated (if necessary) for the new element and all (uninitialized) elements between the new element and the previous end of the array).

Parameters
index:int

index to store a value in

value:double

value to store at the specified index

Exceptions
ArrayIndexOutOfBoundsException:
if index < 0.
setExpansionFactorback to summary
public void setExpansionFactor(float expansionFactor) throws MathIllegalArgumentException

Deprecated

As of 3.1 (to be removed in 4.0 as field will become "final").

Sets the expansionFactor. Throws IllegalArgumentException if the the following conditions are not met:

  • expansionFactor > 1
  • contractionFactor >= expansionFactor
Parameters
expansionFactor:float

the new expansion factor value.

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if expansionFactor is <= 1 or greater than contractionFactor
setExpansionModeback to summary
public void setExpansionMode(int expansionMode) throws MathIllegalArgumentException

Deprecated

As of 3.1. Please use setExpansionMode(ExpansionMode) instead.

Sets the expansionMode. The specified value must be one of ADDITIVE_MODE, MULTIPLICATIVE_MODE.

Parameters
expansionMode:int

The expansionMode to set.

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if the specified mode value is not valid.
setExpansionModeback to summary
public void setExpansionMode(ResizableDoubleArray.ExpansionMode expansionMode)

Deprecated

As of 3.1 (to be removed in 4.0 as field will become "final").

Sets the expansion mode.

Parameters
expansionMode:ResizableDoubleArray.ExpansionMode

Expansion mode to use for resizing the array.

Annotations
@Deprecated
setInitialCapacityback to summary
protected void setInitialCapacity(int initialCapacity) throws MathIllegalArgumentException

Deprecated

As of 3.1, this is a no-op.

Sets the initial capacity. Should only be invoked by constructors.

Parameters
initialCapacity:int

of the array

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if initialCapacity is not positive.
setNumElementsback to summary
public synchronized void setNumElements(int i) throws MathIllegalArgumentException

This function allows you to control the number of elements contained in this array, and can be used to "throw out" the last n values in an array. This function will also expand the internal array as needed.

Parameters
i:int

a new number of elements

Exceptions
MathIllegalArgumentException:
if i is negative.
shouldContractback to summary
private synchronized boolean shouldContract()

Returns true if the internal storage array has too many unused storage positions.

Returns:boolean

true if array satisfies the contraction criteria

startback to summary
public synchronized int start()

Deprecated

As of 3.1.

Returns the starting index of the internal array. The starting index is the position of the first addressable element in the internal storage array. The addressable elements in the array are internalArray[startIndex],...,internalArray[startIndex + numElements -1]

Returns:int

the starting index.

Annotations
@Deprecated
substituteMostRecentElementback to summary
public synchronized double substituteMostRecentElement(double value) throws MathIllegalStateException

Substitutes value for the most recently added value. Returns the value that has been replaced. If the array is empty (i.e. if numElements is zero), an IllegalStateException is thrown.

Parameters
value:double

New value to substitute for the most recently added value

Returns:double

the value that has been replaced in the array.

Exceptions
MathIllegalStateException:
if the array is empty
Since
2.0
org.apache.commons.math3.util back to summary

public final Enum ResizableDoubleArray.ExpansionMode

extends Enum<ResizableDoubleArray.ExpansionMode>
Class Inheritance

Specification of expansion algorithm.
Since
3.1

Field Summary

Modifier and TypeField and Description
public static final ResizableDoubleArray.ExpansionMode
ADDITIVE

Additive expansion mode.

public static final ResizableDoubleArray.ExpansionMode
MULTIPLICATIVE

Multiplicative expansion mode.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ResizableDoubleArray.ExpansionMode
public static ResizableDoubleArray.ExpansionMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ADDITIVEback to summary
public static final ResizableDoubleArray.ExpansionMode ADDITIVE

Additive expansion mode.

MULTIPLICATIVEback to summary
public static final ResizableDoubleArray.ExpansionMode MULTIPLICATIVE

Multiplicative expansion mode.

Constructor Detail

ExpansionModeback to summary
private ExpansionMode()

Method Detail

valueOfback to summary
public static ResizableDoubleArray.ExpansionMode valueOf(String name)
valuesback to summary
public static ResizableDoubleArray.ExpansionMode[] values()