Interface UpdatableObjectInPlaceArray<E>
- All Superinterfaces:
Array
,ArrayExchanger
,ObjectArray<E>
,ObjectInPlaceArray<E>
,UpdatableArray
,UpdatableObjectArray<E>
- All Known Subinterfaces:
MutableObjectInPlaceArray<E>
Special version of UpdatableObjectArray
allowing
to load an element without creating new Java object.
The arrays of object created via some memory models
may not implement this interface.
You may check, is this interface implemented, by intstanceof operator.
- Author:
- Daniel Alievsky
-
Method Summary
Modifier and TypeMethodDescriptionReturns an unresizable view of this array.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.Methods inherited from interface net.algart.arrays.Array
byteOrder, capacity, checkUnallowedMutation, equals, flushResources, flushResources, freeResources, freeResources, getData, getData, getElement, hashCode, isCopyOnNextWrite, isEmpty, isImmutable, isLazy, isNew, isNewReadOnlyView, isUnresizable, length, length32, loadResources, newJavaArray, toString
Methods inherited from interface net.algart.arrays.ObjectArray
asImmutable, asTrustedImmutable, buffer, buffer, buffer, buffer, elementType, get, indexOf, ja, lastIndexOf, mutableClone, mutableType, type, updatableClone, updatableType
Methods inherited from interface net.algart.arrays.ObjectInPlaceArray
allocateElement, getInPlace
Methods inherited from interface net.algart.arrays.UpdatableArray
asCopyOnNextWrite, copy, copy, copy, setData, setData, setElement, setNonNew, shallowClone, swap, swap, swap
-
Method Details
-
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
- Specified by:
subArray
in interfaceUpdatableObjectArray<E>
- 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
- Specified by:
subArr
in interfaceUpdatableObjectArray<E>
- 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
UpdatableObjectInPlaceArray<E> 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
- Specified by:
asUnresizable
in interfaceUpdatableObjectArray<E>
- Returns:
- an unresizable view of this array.
- See Also:
-