AlgART Home

net.algart.arrays
Interface PIntegerArray

All Superinterfaces:
Array, PArray, PFixedArray, PNumberArray
All Known Subinterfaces:
ByteArray, IntArray, LongArray, MutableByteArray, MutableIntArray, MutableLongArray, MutablePIntegerArray, MutableShortArray, ShortArray, UpdatableByteArray, UpdatableIntArray, UpdatableLongArray, UpdatablePIntegerArray, UpdatableShortArray
All Known Implementing Classes:
AbstractByteArray, AbstractIntArray, AbstractLongArray, AbstractShortArray, AbstractUpdatableByteArray, AbstractUpdatableIntArray, AbstractUpdatableLongArray, AbstractUpdatableShortArray

public interface PIntegerArray
extends PFixedArray, PNumberArray

AlgART array of any fixed-point primitive numeric elements (byte, short, int or long), read-only access.

Any class implementing this interface must implement one of ByteArray, ShortArray, IntArray, LongArray subinterfaces.

AlgART Laboratory 2007-2013

Since:
JDK 1.5
Version:
1.2
Author:
Daniel Alievsky

Method Summary
Modifier and Type Method and Description
 PIntegerArray asImmutable()
          Returns an immutable view of this array.
 PIntegerArray asTrustedImmutable()
          Returns a trusted immutable view of this array.
 MutablePIntegerArray mutableClone(MemoryModel memoryModel)
          Returns a mutable resizable copy of this array.
 java.lang.Class<? extends MutablePIntegerArray> mutableType()
          Returns the canonical resizable AlgART type of arrays with the same element types: the class of one of 9 basic interfaces, describing all kinds of resizable AlgART arrays for 8 primitive and any non-primitive element types.
 java.lang.Class<? extends PIntegerArray> type()
          Returns the canonical AlgART type of this array: the class of one of 9 basic interfaces, describing all kinds of AlgART arrays for 8 primitive and any non-primitive element types.
 UpdatablePIntegerArray updatableClone(MemoryModel memoryModel)
          Returns an unresizable updatable copy of this array.
 java.lang.Class<? extends UpdatablePIntegerArray> updatableType()
          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.PFixedArray
getInt, getLong, indexOf, lastIndexOf, maxPossibleValue, minPossibleValue
 
Methods inherited from interface net.algart.arrays.PArray
bitsPerElement, getDouble, indexOf, isZeroFilled, lastIndexOf, maxPossibleValue, minPossibleValue
 
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, isImmutable, isLazy, isNew, isNewReadOnlyView, isUnresizable, length, loadResources, newJavaArray, shallowClone, subArr, subArray, toString
 

Method Detail

type

java.lang.Class<? extends PIntegerArray> type()
Description copied from interface: Array
Returns the canonical AlgART type of this array: the class of one of 9 basic interfaces, describing all kinds of AlgART arrays for 8 primitive and any non-primitive element types. More precisely, returns:

There is a guarantee that this method works very quickly (usually it just returns a constant value).

Specified by:
type in interface Array
Specified by:
type in interface PArray
Specified by:
type in interface PNumberArray
Returns:
canonical AlgART type of this array.

updatableType

java.lang.Class<? extends UpdatablePIntegerArray> 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:

There is a guarantee that this method works very quickly (usually it just returns a constant value).

Specified by:
updatableType in interface Array
Specified by:
updatableType in interface PArray
Specified by:
updatableType in interface PNumberArray
Returns:
canonical AlgART type of an updatable array of the same kind.

mutableType

java.lang.Class<? extends MutablePIntegerArray> mutableType()
Description copied from interface: Array
Returns the canonical resizable AlgART type of arrays with the same element types: the class of one of 9 basic interfaces, describing all kinds of resizable AlgART arrays for 8 primitive and any non-primitive element types. More precisely, returns:

There is a guarantee that this method works very quickly (usually it just returns a constant value).

Specified by:
mutableType in interface Array
Specified by:
mutableType in interface PArray
Specified by:
mutableType in interface PNumberArray
Returns:
canonical AlgART type of a resizable array of the same kind.

asImmutable

PIntegerArray 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 or DirectAccessible interfaces. Moreover, any third-party implementation of Array interface must return an instance of a class, which has no public 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: calling MutableArray.length(long), MutableArray.ensureCapacity(long) or MutableArray.trim() methods for this array, or any modification of this or returned array in a case when this array is copy-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 implement UpdatableArray.

Also note: Array.isNewReadOnlyView() method, called for the result of this method, always returns the same value as Array.isNewReadOnlyView() for this object. Really,

Specified by:
asImmutable in interface Array
Specified by:
asImmutable in interface PArray
Specified by:
asImmutable in interface PFixedArray
Returns:
an immutable view of this array (or a reference to this array if it is already immutable).
See Also:
Array.isImmutable(), Array.asTrustedImmutable(), Array.mutableClone(MemoryModel), Array.updatableClone(MemoryModel), UpdatableArray.asUnresizable()

asTrustedImmutable

PIntegerArray 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 implement DirectAccessible, that allow quick access to its elements. As for usual 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, the UnallowedMutationError may be thrown by the call of Array.checkUnallowedMutation() method.

In some implementations — for example, if DirectAccessible interface is not supported by this array — this method may return the same result as Array.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: calling MutableArray.length(long), MutableArray.ensureCapacity(long) or MutableArray.trim() methods for this array, or any modification of this or returned array in a case when this array is copy-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 interface Array
Specified by:
asTrustedImmutable in interface PArray
Specified by:
asTrustedImmutable in interface PFixedArray
Returns:
a trusted immutable view of this array (or a reference to this array if it is already trusted immutable).
See Also:
Array.asImmutable(), Array.checkUnallowedMutation()

mutableClone

MutablePIntegerArray mutableClone(MemoryModel memoryModel)
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 interface Array
Specified by:
mutableClone in interface PArray
Specified by:
mutableClone in interface PFixedArray
Parameters:
memoryModel - the memory model, used for allocation a new copy of this array.
Returns:
a mutable copy of this array.
See Also:
Array.updatableClone(MemoryModel)

updatableClone

UpdatablePIntegerArray updatableClone(MemoryModel memoryModel)
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 interface Array
Specified by:
updatableClone in interface PArray
Specified by:
updatableClone in interface PFixedArray
Parameters:
memoryModel - the memory model, used for allocation a new copy of this array.
Returns:
an updatable copy of this array.
See Also:
Array.mutableClone(MemoryModel)