Interface UpdatablePArray
- All Superinterfaces:
Array
,ArrayExchanger
,PArray
,UpdatableArray
- All Known Subinterfaces:
MutableBitArray
,MutableByteArray
,MutableCharArray
,MutableDoubleArray
,MutableFloatArray
,MutableIntArray
,MutableLongArray
,MutablePArray
,MutablePFixedArray
,MutablePFloatingArray
,MutablePIntegerArray
,MutablePNumberArray
,MutableShortArray
,UpdatableBitArray
,UpdatableByteArray
,UpdatableCharArray
,UpdatableDoubleArray
,UpdatableFloatArray
,UpdatableIntArray
,UpdatableLongArray
,UpdatablePFixedArray
,UpdatablePFloatingArray
,UpdatablePIntegerArray
,UpdatablePNumberArray
,UpdatableShortArray
- All Known Implementing Classes:
AbstractUpdatableBitArray
,AbstractUpdatableByteArray
,AbstractUpdatableCharArray
,AbstractUpdatableDoubleArray
,AbstractUpdatableFloatArray
,AbstractUpdatableIntArray
,AbstractUpdatableLongArray
,AbstractUpdatableShortArray
AlgART array of primitive elements (boolean, char, byte, short, int, long, float or double), read/write access, no resizing.
Any class implementing this interface must implement one of
UpdatableBitArray
, UpdatableCharArray
,
UpdatableByteArray
, UpdatableShortArray
,
UpdatableIntArray
, UpdatableLongArray
,
UpdatableFloatArray
, UpdatableDoubleArray
subinterfaces.
- Author:
- Daniel Alievsky
-
Method Summary
Modifier and TypeMethodDescriptionReturns an unresizable view of this array.fill
(double value) Fills all elements of this array with the specified value.fill
(long value) Fills all elements of this array by the specified value.fill
(long position, long count, double value) Fills count elements of this array, starting from position index, by the specified value.fill
(long position, long count, long value) Fills count elements of this array, starting from position index, by the specified value.default Matrix<? extends UpdatablePArray>
matrix
(long... dim) Equivalent tomatrix
(thisArray, dim).void
setDouble
(long index, double value) Sets the element #index with conversion from double, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0.0 for boolean element type.void
setInt
(long index, int value) Sets the element #index with conversion from int, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0 for boolean element type.void
setLong
(long index, long value) Sets the element #index with conversion from long, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0 for boolean element type.subArr
(long position, long count) Equivalent tosubArray(position, position + count)
.subArray
(long fromIndex, long toIndex) Returns a view of the portion of this array between fromIndex, inclusive, and toIndex, exclusive.Class<? extends UpdatablePArray>
Returns the canonical updatable AlgART type of arrays with the same element types: the class of one of 9 basic interfaces, describing all kinds of updatable AlgART arrays for 8 primitive and any non-primitive element types.Methods inherited from interface net.algart.arrays.Array
buffer, buffer, buffer, buffer, byteOrder, capacity, checkUnallowedMutation, elementType, equals, flushResources, flushResources, freeResources, freeResources, getData, getData, getElement, hashCode, isCopyOnNextWrite, isEmpty, isImmutable, isLazy, isNew, isNewReadOnlyView, isUnresizable, ja, length, length32, loadResources, newJavaArray, toString
Methods inherited from interface net.algart.arrays.PArray
asImmutable, asTrustedImmutable, bitsPerElement, getDouble, indexOf, isZeroFilled, jaByte, jaDouble, jaFloat, jaInt, jaLong, jaShort, lastIndexOf, maxPossibleValue, minPossibleValue, mutableClone, mutableType, type, updatableClone
Methods inherited from interface net.algart.arrays.UpdatableArray
asCopyOnNextWrite, copy, copy, copy, setData, setData, setElement, setNonNew, shallowClone, swap, swap, swap
-
Method Details
-
setDouble
void setDouble(long index, double value) Sets the element #index with conversion from double, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0.0 for boolean element type.Depending on the specific subinterface implemented by the object, this method is equivalent to one of the following calls:
- for
UpdatableBitArray
:setBit
(index, value != 0.0); - for
UpdatableCharArray
:setChar
(index, (char) value); - for
UpdatableByteArray
:setByte
(index, (byte) value); - for
UpdatableShortArray
:setShort
(index, (short) value); - for
UpdatableLongArray
:setLong
(index, (long) value); - for
UpdatableFloatArray
:setFloat
(index, (float) value); - for
UpdatableDoubleArray
: the same method is already declared in this interface.
- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.- Throws:
IndexOutOfBoundsException
- if index out of range 0..length()-1.- See Also:
- for
-
setLong
void setLong(long index, long value) Sets the element #index with conversion from long, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0 for boolean element type.Depending on the specific subinterface implemented by the object, this method is equivalent to one of the following calls:
- for
UpdatableBitArray
:setBit
(index, value != 0); - for
UpdatableCharArray
:setChar
(index, (char) value); - for
UpdatableByteArray
:setByte
(index, (byte) value); - for
UpdatableShortArray
:setShort
(index, (short) value); - for
UpdatableLongArray
: the same method is already declared in this interface; - for
UpdatableFloatArray
:setFloat
(index, (float) value); - for
UpdatableDoubleArray
:setDouble
(index, (double) value).
- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.- Throws:
IndexOutOfBoundsException
- if index out of range 0..length()-1.- See Also:
- for
-
setInt
void setInt(long index, int value) Sets the element #index with conversion from int, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0 for boolean element type.This method is equivalent to both
setLong(index, (long) value)
andsetDouble(index, (double) value)
, but can work little faster.- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.- Throws:
IndexOutOfBoundsException
- if index out of range 0..length()-1.- See Also:
-
fill
Fills all elements of this array with the specified value. Equivalent tofill
(0, thisArray.length(), value).- Parameters:
value
- the value to be stored in all elements of the array.- Returns:
- a reference to this array.
- See Also:
-
fill
Fills count elements of this array, starting from position index, by the specified value. Equivalent to the following loop:for (long k = 0; k < count; k++) {
but works much faster and checks indexes (and throws possible IndexOutOfBoundsException) in the very beginning.setDouble
(position + k, value); }- Parameters:
position
- start index (inclusive) to be filled.count
- number of filled elements.value
- the value to be stored in the elements of the array.- Returns:
- a reference to this array.
- Throws:
IndexOutOfBoundsException
- for illegal position and count (position < 0 || count < 0 || position + count > length()).- See Also:
-
fill
Fills all elements of this array by the specified value. Equivalent tofill
(0, thisArray.length(), value).- Parameters:
value
- the value to be stored in all elements of the array.- Returns:
- a reference to this array.
- See Also:
-
fill
Fills count elements of this array, starting from position index, by the specified value. Equivalent to the following loop:for (long k = 0; k < count; k++) {
but works much faster and checks indexes (and throws possible IndexOutOfBoundsException) in the very beginning.setLong
(position + k, value); }- Parameters:
position
- start index (inclusive) to be filled.count
- number of filled elements.value
- the value to be stored in the elements of the array.- Returns:
- a reference to this array.
- Throws:
IndexOutOfBoundsException
- for illegal position and count (position < 0 || count < 0 || position + count > length()).- See Also:
-
updatableType
Class<? extends UpdatablePArray> updatableType()Description copied from interface:Array
Returns the canonical updatable AlgART type of arrays with the same element types: the class of one of 9 basic interfaces, describing all kinds of updatable AlgART arrays for 8 primitive and any non-primitive element types. More precisely, returns:UpdatableBitArray
.class, if this object is an instance ofBitArray
,UpdatableCharArray
.class, if this object is an instance ofCharArray
,UpdatableByteArray
.class, if this object is an instance ofByteArray
,UpdatableShortArray
.class, if this object is an instance ofShortArray
,UpdatableIntArray
.class, if this object is an instance ofIntArray
,UpdatableLongArray
.class, if this object is an instance ofLongArray
,UpdatableFloatArray
.class, if this object is an instance ofFloatArray
,UpdatableDoubleArray
.class, if this object is an instance ofDoubleArray
,UpdatableObjectArray
.class, if this object is an instance ofObjectArray
.
There is a guarantee that this method works very quickly (usually it just returns a constant value).
- Specified by:
updatableType
in interfaceArray
- Specified by:
updatableType
in interfacePArray
- Returns:
- canonical AlgART type of an updatable array of the same kind.
-
subArray
Description copied from interface:Array
Returns a view of the portion of this array between fromIndex, inclusive, and toIndex, exclusive.- If fromIndex and toIndex are equal, the returned array is empty.
- The returned array is backed by this array, so — if this array is not immutable — any changes of the elements of the returned array are reflected in this array, and vice-versa.
- The capacity of returned array (returned by
Array.capacity()
method) will be equal to the its length (returned byArray.length()
, that is toIndex-fromIndex. - The
type of elements
of the returned array is the same as the type of elements of this array. - The returned array is
immutable
,trusted immutable
orcopy-on-next-write
, if, and only if, this array is immutable, trusted immutable or copy-on-next-write correspondingly. - If (and only if) this array implements
UpdatableArray
interface, then the returned array also implements it. If (and only if) this array implementsDirectAccessible
interface, then the returned array also implements it. The returned array never implementsMutableArray
interface; it is always unresizable.
Like List.subList method, this method eliminates the need for explicit range operations. For example, you may use
Arrays.sort(UpdatableArray, ArrayComparator)
method for sorting a fragment of the array.Unlike List.subList, the semantics of the array returned by this method is well-defined in any case, even in case of resizing of the source array. Namely, if the internal storage of this or returned array is reallocated, then the returned array will cease to be a view of this array. The only possible reasons for reallocation are the following: calling
MutableArray.length(long)
,MutableArray.ensureCapacity(long)
orMutableArray.trim()
methods for this array, or any modification of this or returned array in a case when this array iscopy-on-next-write
. Also, if the length of this array will be reduced, it can lead to clearing some elements in returned array: see comments toMutableArray.length(long)
method.- Specified by:
subArray
in interfaceArray
- Specified by:
subArray
in interfaceUpdatableArray
- Parameters:
fromIndex
- low endpoint (inclusive) of the subarray.toIndex
- high endpoint (exclusive) of the subarray.- Returns:
- a view of the specified range within this array.
- See Also:
-
subArr
Description copied from interface:Array
Equivalent tosubArray(position, position + count)
. The only possible difference is other exception messages. If position+count>Long.MAX_VALUE (overflow), an exception message is allowed to be not fully correct (maximal speed is more important than absolutely correct exception messages for such exotic situations).- Specified by:
subArr
in interfaceArray
- Specified by:
subArr
in interfaceUpdatableArray
- Parameters:
position
- start position (inclusive) of the subarray.count
- number of elements in the subarray.- Returns:
- a view of the specified range within this array.
- See Also:
-
asUnresizable
UpdatablePArray asUnresizable()Description copied from interface:UpdatableArray
Returns an unresizable view of this array. If this array is not resizable already, returns a reference to this object. Query operations on the returned array "read through" and "write through" to this array.The returned view (when it is not a reference to this object) contains the same elements as this array, but independent length, start offset, capacity, copy-on-next-write and possible other information about array characteristics besides its elements, as for
UpdatableArray.shallowClone()
method. If modifications of this or returned array characteristics lead to reallocation of the internal storage, then the returned array ceases to be a view of this array. The only possible reasons for reallocation are the following: callingMutableArray.length(long)
,MutableArray.ensureCapacity(long)
orMutableArray.trim()
methods for this array, or any modification of this or returned array in a case when this array iscopy-on-next-write
.Resizable arrays, created by this package, implement full
MutableArray
interface, but unresizable ones implement only itsUpdatableArray
superinterface.- Specified by:
asUnresizable
in interfaceUpdatableArray
- Returns:
- an unresizable view of this array.
- See Also:
-
matrix
Description copied from interface:Array
Equivalent tomatrix
(thisArray, dim).
-