Interface PFixedArray
- All Known Subinterfaces:
BitArray
,ByteArray
,CharArray
,IntArray
,LongArray
,MutableBitArray
,MutableByteArray
,MutableCharArray
,MutableIntArray
,MutableLongArray
,MutablePFixedArray
,MutablePIntegerArray
,MutableShortArray
,PIntegerArray
,ShortArray
,UpdatableBitArray
,UpdatableByteArray
,UpdatableCharArray
,UpdatableIntArray
,UpdatableLongArray
,UpdatablePFixedArray
,UpdatablePIntegerArray
,UpdatableShortArray
- All Known Implementing Classes:
AbstractBitArray
,AbstractByteArray
,AbstractCharArray
,AbstractIntArray
,AbstractLongArray
,AbstractShortArray
,AbstractUpdatableBitArray
,AbstractUpdatableByteArray
,AbstractUpdatableCharArray
,AbstractUpdatableIntArray
,AbstractUpdatableLongArray
,AbstractUpdatableShortArray
AlgART array of any fixed-point primitive numeric, character or bit elements (byte, short, int, long, char or boolean), read-only access.
Any class implementing this interface must implement one of
BitArray
, CharArray
,
ByteArray
, ShortArray
,
IntArray
, LongArray
subinterfaces.
- Author:
- Daniel Alievsky
-
Method Summary
Modifier and TypeMethodDescriptionReturns an immutable view of this array.Returns a trusted immutable view of this array.int
getInt
(long index) Returns the element #index converted to int: (int)value&0xFF for byte value, (int)value&0xFFFF for short value, (int)value for int or char values, value?1:0 for boolean values, min(max(value, Integer.MIN_VALUE), Integer.MAX_VALUE) (i.e. the value truncated to the range Integer.MIN_VALUE..Integer.MAX_VALUE) for long values.long
getLong
(long index) Returns the element #index converted to long: (long)value&0xFF for byte value, (long)value&0xFFFF for short value, (long)value for int, long or char values, or as value?1:0 for boolean values.long
indexOf
(long lowIndex, long highIndex, long value) long
lastIndexOf
(long lowIndex, long highIndex, long value) Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) andgetLong
(k)==value, or -1 if there is no such array element.default Matrix<? extends PFixedArray>
matrix
(long... dim) Equivalent tomatrix
(thisArray, dim).long
long
mutableClone
(MemoryModel memoryModel) Returns a mutable resizable copy of this array.updatableClone
(MemoryModel memoryModel) Returns an unresizable updatable copy of this array.Methods inherited from interface net.algart.arrays.Array
asCopyOnNextWrite, 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, shallowClone, subArr, subArray, toString
Methods inherited from interface net.algart.arrays.PArray
bitsPerElement, getDouble, indexOf, isZeroFilled, jaByte, jaDouble, jaFloat, jaInt, jaLong, jaShort, lastIndexOf, maxPossibleValue, minPossibleValue, mutableType, type, updatableType
-
Method Details
-
minPossibleValue
long minPossibleValue()Returns 0 forBitArray
,ByteArray
,CharArray
andShortArray
, Integer.MIN_VALUE forIntArray
, Long.MIN_VALUE forLongArray
. It is the minimal possible value, that can stored in elements of this array (byte and short elements are interpreted as unsigned). This method is equivalent tominPossibleIntegerValue
(thisArray.getClass()).- Returns:
- the minimal possible value, that can stored in elements of this array.
- See Also:
-
maxPossibleValue
long maxPossibleValue()Returns 1 forBitArray
, 0xFF forByteArray
, 0xFFFF forCharArray
andShortArray
, Integer.MAX_VALUE forIntArray
, Long.MAX_VALUE forLongArray
. valueForFloatingPoint forFloatArray
andDoubleArray
. It is the maximal possible value, that can stored in elements of this array (byte and short elements are interpreted as unsigned). This method is equivalent tomaxPossibleIntegerValue
(thisArray.getClass()).- Returns:
- the maximal possible value, that can stored in elements of this array.
- See Also:
-
getLong
long getLong(long index) Returns the element #index converted to long: (long)value&0xFF for byte value, (long)value&0xFFFF for short value, (long)value for int, long or char values, or as value?1:0 for boolean values. Please note that this method returns unsigned values for byte and short arrays. Returned value contains full information stored in the element, if it is not an array of float or double elements.- Parameters:
index
- index of element to get.- Returns:
- the element at the specified position in this array.
- Throws:
IndexOutOfBoundsException
- if index out of range 0..length()-1.- See Also:
-
getInt
int getInt(long index) Returns the element #index converted to int: (int)value&0xFF for byte value, (int)value&0xFFFF for short value, (int)value for int or char values, value?1:0 for boolean values, min(max(value, Integer.MIN_VALUE), Integer.MAX_VALUE) (i.e. the value truncated to the range Integer.MIN_VALUE..Integer.MAX_VALUE) for long values. Please note that this method returns unsigned values for byte and short arrays. Returned value contains full information stored in the element, if it is not an array of long, float or double elements.- Parameters:
index
- index of element to get.- Returns:
- the element at the specified position in this array.
- Throws:
IndexOutOfBoundsException
- if index out of range 0..length()-1.- See Also:
-
indexOf
long indexOf(long lowIndex, long highIndex, long value) Returns the minimal index k, so that lowIndex<=k<min(highIndex,thisArray.length()
) andgetLong
(k)==value, or -1 if there is no such array element.In particular, if lowIndex>=thisArray.
length()
} or lowIndex>=highIndex, this method returns -1, and if lowIndex<0, the result is the same as if lowIndex==0.You may specify lowIndex=0 and highIndex=Long.MAX_VALUE to search through all array elements.
- Parameters:
lowIndex
- the low index in the array for search (inclusive).highIndex
- the high index in the array for search (exclusive).value
- the value to be found.- Returns:
- the index of the first occurrence of this value in this array in range lowIndex<=index<highIndex, or -1 if this value does not occur in this range.
-
lastIndexOf
long lastIndexOf(long lowIndex, long highIndex, long value) Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) andgetLong
(k)==value, or -1 if there is no such array element.In particular, if highIndex<=0 or highIndex<=lowIndex, this method returns -1, and if highIndex>=thisArray.
length()
, the result is the same as if highIndex==thisArray.length()
.You may specify lowIndex=0 and highIndex=Long.MAX_VALUE to search through all array elements.
- Parameters:
lowIndex
- the low index in the array for search (inclusive).highIndex
- the high index in the array for search (exclusive).value
- the value to be found.- Returns:
- the index of the last occurrence of this value in this array in range lowIndex<=index<highIndex, or -1 if this value does not occur in this range.
-
asImmutable
PFixedArray asImmutable()Description copied from interface:Array
Returns an immutable view of this array. If this array is already immutable (i.e.Array.isImmutable()
is true), returns a reference to this object.A array is considered to be immutable, if there are no ways to modify its content or state with help of this instance. In particular, immutable arrays never implement
UpdatableArray
orDirectAccessible
interfaces. Moreover, any third-party implementation of Array interface must return an instance of a class, which has no methods or fields allowing to change this instance.Query operations on the returned array "read through" to this array. The returned view is also unresizable (see
UpdatableArray.asUnresizable()
).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
Array.shallowClone()
method. If modifications of this 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
.By default, the array factories (
memory models
) create mutable arrays, but they can be converted to immutable by this method.Note:
Array.isNew()
method, called for the result of this method, always returns false — because it does not implementUpdatableArray
.Also note:
Array.isNewReadOnlyView()
method, called for the result of this method, always returns the same value asArray.isNewReadOnlyView()
for this object. Really,- it this object is immutable (
Array.isImmutable()
==true), then it is obvious (this method just returns a reference to this array); - it this object is not immutable (
Array.isImmutable()
==false), then, according to the contract toArray.isNewReadOnlyView()
method,Array.isNewReadOnlyView()
must return false for this array (in other caseArray.isImmutable()
would return true) and it also must return false for the returned array (because it is a view of another array and not an original view of external data — see the beginning of the comment toArray.isNewReadOnlyView()
).
- Specified by:
asImmutable
in interfaceArray
- Specified by:
asImmutable
in interfacePArray
- Returns:
- an immutable view of this array (or a reference to this array if it is already immutable).
- See Also:
- it this object is immutable (
-
asTrustedImmutable
PFixedArray asTrustedImmutable()Description copied from interface:Array
Returns a trusted immutable view of this array. If this array is already trusted immutable, returns a reference to this object.A array is considered to be "trusted" immutable, if it potentially can change its elements, but the Java code working with this array promises that it will not change them. The returned instance never implements
UpdatableArray
, but may implementDirectAccessible
, that allow quick access to its elements. As forusual immutable view
, query operations on the returned array "read through" to this array.The only standard way allowing to change elements of returned array is using
DirectAccessible.javaArray()
method, in a case when the array is backed by an accessible array. But the Java code, processing the trusted immutable array, must use this method only for quick reading elements and not try to change them. If, despite the promise, the elements of the trusted immutable array will be changed, theUnallowedMutationError
may be thrown by the call ofArray.checkUnallowedMutation()
method.In some implementations — for example, if
DirectAccessible
interface is not supported by this array — this method may return the same result asArray.asImmutable()
.The returned view is always unresizable.
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
Array.shallowClone()
method. If modifications of this 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
.Trusted immutable view is a compromise between absolute safety, provided by
usual immutable view
, and maximal efficiency, achieved while using the original non-protected array. Please see the package description to learn more about possible usage of this method.- Specified by:
asTrustedImmutable
in interfaceArray
- Specified by:
asTrustedImmutable
in interfacePArray
- Returns:
- a trusted immutable view of this array (or a reference to this array if it is already trusted immutable).
- See Also:
-
mutableClone
Description copied from interface:Array
Returns a mutable resizable copy of this array. This method is equivalent to the following code:memoryModel.
newArray
(thisArray).copy
(thisArray);Please note: this method is a good choice for cloning little arrays (thousands, maybe millions elements). If you clone large arrays by this method, the user, in particular, has no ways to view the progress of copying or to interrupt copying. To clone large arrays, we recommend the following code:
MutableArray clone = memoryModel.
newArray
(thisArray);Arrays.copy
(someContext, clone, a);- Specified by:
mutableClone
in interfaceArray
- Specified by:
mutableClone
in interfacePArray
- Parameters:
memoryModel
- the memory model, used for allocation a new copy of this array.- Returns:
- a mutable copy of this array.
- See Also:
-
updatableClone
Description copied from interface:Array
Returns an unresizable updatable copy of this array. This method is equivalent to the following code:memoryModel.
newUnresizableArray
(thisArray).copy
(thisArray);Please note: this method is a good choice for cloning little arrays (thousands, maybe millions elements). If you clone large arrays by this method, the user, in particular, has no ways to view the progress of copying or to interrupt copying. To clone large arrays, we recommend the following code:
UpdatableArray clone = memoryModel.
newUnresizableArray
(thisArray);Arrays.copy
(someContext, clone, a);- Specified by:
updatableClone
in interfaceArray
- Specified by:
updatableClone
in interfacePArray
- Parameters:
memoryModel
- the memory model, used for allocation a new copy of this array.- Returns:
- an updatable copy of this array.
- See Also:
-
matrix
Description copied from interface:Array
Equivalent tomatrix
(thisArray, dim).
-