AlgART Home

net.algart.arrays
Class AbstractUpdatableShortArray

java.lang.Object
  extended by net.algart.arrays.AbstractArray
      extended by net.algart.arrays.AbstractShortArray
          extended by net.algart.arrays.AbstractUpdatableShortArray
All Implemented Interfaces:
java.lang.Cloneable, Array, ArrayExchanger, PArray, PFixedArray, PIntegerArray, PNumberArray, ShortArray, UpdatableArray, UpdatablePArray, UpdatablePFixedArray, UpdatablePIntegerArray, UpdatablePNumberArray, UpdatableShortArray

public abstract class AbstractUpdatableShortArray
extends AbstractShortArray
implements UpdatableShortArray

Implementation of almost all basic functions of UpdatableShortArray interface. The only ShortArray.getShort(long) and UpdatableShortArray.setShort(long, short) methods are not defined in this class; all other methods are implemented via calls of these 2 methods.

AlgART Laboratory 2007-2013

Since:
JDK 1.5
Version:
1.2
Author:
Daniel Alievsky

Field Summary
Modifier and Type Field and Description
 
Fields inherited from class net.algart.arrays.AbstractArray
capacity, length, underlyingArrays
 
Constructor Summary
Modifier Constructor and Description
protected AbstractUpdatableShortArray(long initialCapacityAndLength, boolean underlyingArraysAreParallel, Array... underlyingArrays)
          Equivalent to the constructor AbstractUpdatableShortArray(long, long, boolean, Array...), where both initialCapacity and initialLength arguments are equal to initialCapacityAndLength.
protected AbstractUpdatableShortArray(long initialCapacity, long initialLength, boolean underlyingArraysAreParallel, Array... underlyingArrays)
          Creates an updatable array with the given initial capacity and length.
 
Method Summary
Modifier and Type Method and Description
 UpdatableArray asCopyOnNextWrite()
          This implementation returns updatableClone(Arrays.SMM).
 ShortArray asImmutable()
          This implementation returns an instance of the subclass of AbstractShortArray, where the following method are overridden and call the same methods of this instance: AbstractShortArray.getShort(long), AbstractShortArray.getData(long, Object, int, int), AbstractShortArray.getData(long, Object), AbstractShortArray.loadResources(ArrayContext, long, long), AbstractShortArray.flushResources(ArrayContext, long, long, boolean) and AbstractShortArray.freeResources(ArrayContext, long, long, boolean).
 UpdatableShortArray asUnresizable()
          This implementation returns this object.
 UpdatableArray copy(Array src)
          This implementation calls defaultCopy(thisInstance, src).
 void copy(long destIndex, long srcIndex)
          This implementation calls setShort(destIndex, (short) getShort(srcIndex)).
 void copy(long destIndex, long srcIndex, long count)
          This implementation is based on a loop of calls of copy(long, long) method.
 UpdatableShortArray fill(double value)
          This implementation just calls fill(0, thisArray.length(), value).
 UpdatableShortArray fill(long value)
          This implementation just calls fill(0, thisArray.length(), value).
 UpdatableShortArray fill(long position, long count, double value)
          This implementation just calls fill(position, count, (short)value).
 UpdatableShortArray fill(long position, long count, long value)
          This implementation just calls fill(position, count, (short)value).
 UpdatableShortArray fill(long position, long count, short value)
          This implementation does the following: subArr(position, count).copy(Arrays.nShortCopies(count, value)).
 UpdatableShortArray fill(short value)
          This implementation just calls fill(0, thisArray.length(), value).
 boolean isImmutable()
          This implementation returns false.
 UpdatableArray setData(long arrayPos, java.lang.Object srcArray)
          This implementation calls setData(long, Object, int, int) with corresponding arguments.
 UpdatableArray setData(long arrayPos, java.lang.Object srcArray, int srcArrayOffset, int count)
          This implementation is based on a loop of calls of setShort(long, short) method.
 void setDouble(long index, double value)
          Sets the element #index by convertion 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 setElement(long index, java.lang.Object value)
          This implementation calls setShort(index, (Short)value).shortValue()).
 void setInt(long index, int value)
          Equivalent to setLong(index, (long)value), but may work little faster.
 void setLong(long index, long value)
          Sets the element #index by convertion 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.
 void setNonNew()
          This implementation calls setNewStatus(false).
abstract  void setShort(long index, short value)
          Sets the element #index to specified value.
 UpdatableArray shallowClone()
          This implementation returns (UpdatableArray)super.shallowClone().
 UpdatableShortArray subArr(long position, long count)
          This implementation returns subArray(position, position + count).
 UpdatableShortArray subArray(long fromIndex, long toIndex)
          This implementation returns new instance of AbstractUpdatableShortArray with the same memory model and underlying arrays, that were passed to the constructor of this instance, and with overridden methods AbstractShortArray.getShort(long), setShort(long, short), AbstractShortArray.getData(long, Object, int, int) and setData(long, Object, int, int) calling the same methods of this instance with corresponding corrections of the arguments.
 void swap(long firstIndex, long secondIndex)
          This implementation swaps two elements by AbstractShortArray.getShort(long) and setShort(long, short) methods.
 void swap(long firstIndex, long secondIndex, long count)
          This implementation is based on a loop of calls of swap(long, long) method.
 UpdatableArray swap(UpdatableArray another)
          This implementation calls defaultSwap(thisInstance, another).
 java.lang.String toString()
          Returns a brief string description of this object.
 
Methods inherited from class net.algart.arrays.AbstractShortArray
asTrustedImmutable, bitsPerElement, buffer, buffer, buffer, buffer, checkUnallowedMutation, elementType, flushResources, flushResources, freeResources, freeResources, getData, getData, getDouble, getElement, getInt, getLong, getShort, indexOf, indexOf, indexOf, isCopyOnNextWrite, isUnresizable, lastIndexOf, lastIndexOf, lastIndexOf, loadResources, loadResources, maxPossibleValue, maxPossibleValue, minPossibleValue, minPossibleValue, mutableClone, mutableType, type, updatableClone, updatableType
 
Methods inherited from class net.algart.arrays.AbstractArray
byteOrder, capacity, checkCopyArguments, checkSubArrArguments, checkSubArrayArguments, checkSwapArguments, defaultAppend, defaultBuffer, defaultBufferCapacity, defaultCopy, defaultCopy, defaultSwap, equals, equals, flushResources, freeResources, hashCode, hashCode, isLazy, isNew, isNewReadOnlyView, isZeroFilled, length, newJavaArray, setNewReadOnlyViewStatus, setNewStatus, standardObjectClone
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.algart.arrays.ShortArray
asTrustedImmutable, buffer, buffer, buffer, buffer, getShort, indexOf, lastIndexOf, mutableClone, mutableType, type, updatableClone, updatableType
 
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
byteOrder, capacity, checkUnallowedMutation, elementType, equals, flushResources, flushResources, freeResources, freeResources, getData, getData, getElement, hashCode, isCopyOnNextWrite, isLazy, isNew, isNewReadOnlyView, isUnresizable, length, loadResources, newJavaArray
 

Constructor Detail

AbstractUpdatableShortArray

protected AbstractUpdatableShortArray(long initialCapacity,
                                      long initialLength,
                                      boolean underlyingArraysAreParallel,
                                      Array... underlyingArrays)
Creates an updatable array with the given initial capacity and length.

This array is not new by default. This is correct usually, because this class is often used for creating a view of another data. However, if the instance if this class does not depend on any other data sources, you may call setNewStatus(true) in the constructor of your subclass.

Parameters:
initialCapacity - initial capacity of the array.
initialLength - initial length of the array.
underlyingArraysAreParallel - see the same argument of AbstractShortArray.AbstractShortArray(long, long, boolean, Array...).
underlyingArrays - see the same argument of AbstractArray.AbstractArray(long, long, Array...).
Throws:
java.lang.NullPointerException - if underlyingArrays argument or some of underlyingArrays[k] elements is null.
java.lang.IllegalArgumentException - if the initialCapacity or initialLength arguments are illegal (negative, or capacity < length).
SizeMismatchException - if underlyingArraysAreParallel=true, underlyingArrays.length>1 and some of passed arrays have different lengths.

AbstractUpdatableShortArray

protected AbstractUpdatableShortArray(long initialCapacityAndLength,
                                      boolean underlyingArraysAreParallel,
                                      Array... underlyingArrays)
Equivalent to the constructor AbstractUpdatableShortArray(long, long, boolean, Array...), where both initialCapacity and initialLength arguments are equal to initialCapacityAndLength.

Parameters:
initialCapacityAndLength - initial capacity and length of the array.
underlyingArraysAreParallel - see AbstractUpdatableShortArray(long, long, boolean, Array...).
underlyingArrays - see AbstractUpdatableShortArray(long, long, boolean, Array...)
Throws:
java.lang.IllegalArgumentException - if the passed argument are illegal (negative).
Method Detail

subArray

public UpdatableShortArray subArray(long fromIndex,
                                    long toIndex)
This implementation returns new instance of AbstractUpdatableShortArray with the same memory model and underlying arrays, that were passed to the constructor of this instance, and with overridden methods AbstractShortArray.getShort(long), setShort(long, short), AbstractShortArray.getData(long, Object, int, int) and setData(long, Object, int, int) calling the same methods of this instance with corresponding corrections of the arguments.

The returned instance also have overridden methods AbstractShortArray.loadResources(ArrayContext, long, long), AbstractShortArray.flushResources(ArrayContext, long, long, boolean) and AbstractShortArray.freeResources(ArrayContext, long, long, boolean), that also call the same methods of this instance with corresponding correction of their fromIndex argument.

The returned instance also have overridden method AbstractArray.isLazy(), that just calls the same methods of this instance with the same arguments.

Specified by:
subArray in interface Array
Specified by:
subArray in interface UpdatableArray
Specified by:
subArray in interface UpdatablePArray
Specified by:
subArray in interface UpdatablePFixedArray
Specified by:
subArray in interface UpdatablePIntegerArray
Specified by:
subArray in interface UpdatableShortArray
Overrides:
subArray in class AbstractShortArray
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.
Throws:
java.lang.IndexOutOfBoundsException - for illegal fromIndex and toIndex (fromIndex < 0 || toIndex > length() || fromIndex > toIndex).
See Also:
Array.subArr(long, long)

subArr

public UpdatableShortArray subArr(long position,
                                  long count)
Description copied from class: AbstractArray
This implementation returns subArray(position, position + count). Please note that the exception message can be not fully correct for the very exotic case position+count>Long.MAX_VALUE.

Specified by:
subArr in interface Array
Specified by:
subArr in interface UpdatableArray
Specified by:
subArr in interface UpdatablePArray
Specified by:
subArr in interface UpdatablePFixedArray
Specified by:
subArr in interface UpdatablePIntegerArray
Specified by:
subArr in interface UpdatableShortArray
Overrides:
subArr in class AbstractArray
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:
Array.subArray(long, long)

setDouble

public void setDouble(long index,
                      double value)
Description copied from interface: UpdatablePArray
Sets the element #index by convertion 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.

Specified by:
setDouble in interface UpdatablePArray
Parameters:
index - index of element to replace.
value - element to be stored at the specified position.
See Also:
PArray.getDouble(long)

setLong

public void setLong(long index,
                    long value)
Description copied from interface: UpdatablePArray
Sets the element #index by convertion 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.

Specified by:
setLong in interface UpdatablePArray
Parameters:
index - index of element to replace.
value - element to be stored at the specified position.
See Also:
PFixedArray.getLong(long)

setInt

public void setInt(long index,
                   int value)
Description copied from interface: UpdatablePArray
Equivalent to setLong(index, (long)value), but may work little faster.

Specified by:
setInt in interface UpdatablePArray
Parameters:
index - index of element to replace.
value - element to be stored at the specified position.
See Also:
PFixedArray.getInt(long)

setShort

public abstract void setShort(long index,
                              short value)
Description copied from interface: UpdatableShortArray
Sets the element #index to specified value.

Specified by:
setShort in interface UpdatableShortArray
Parameters:
index - index of element to replace.
value - element to be stored at the specified position.

fill

public final UpdatableShortArray fill(double value)
This implementation just calls fill(0, thisArray.length(), value).

Specified by:
fill in interface UpdatablePArray
Parameters:
value - the value to be stored in all elements of the array.
Returns:
a reference to this array.
See Also:
UpdatablePArray.fill(long, long, double), Arrays.zeroFill(UpdatableArray)

fill

public UpdatableShortArray fill(long position,
                                long count,
                                double value)
This implementation just calls fill(position, count, (short)value).

Specified by:
fill in interface UpdatablePArray
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:
java.lang.IndexOutOfBoundsException - for illegal position and count (position < 0 || count < 0 || position + count > length()).
See Also:
UpdatablePArray.fill(double), Arrays.zeroFill(UpdatableArray)

fill

public final UpdatableShortArray fill(long value)
This implementation just calls fill(0, thisArray.length(), value).

Specified by:
fill in interface UpdatablePArray
Parameters:
value - the value to be stored in all elements of the array.
Returns:
a reference to this array.
See Also:
UpdatablePArray.fill(long, long, long), Arrays.zeroFill(UpdatableArray)

fill

public UpdatableShortArray fill(long position,
                                long count,
                                long value)
This implementation just calls fill(position, count, (short)value).

Specified by:
fill in interface UpdatablePArray
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:
java.lang.IndexOutOfBoundsException - for illegal position and count (position < 0 || count < 0 || position + count > length()).
See Also:
UpdatablePArray.fill(long), Arrays.zeroFill(UpdatableArray)

fill

public final UpdatableShortArray fill(short value)
This implementation just calls fill(0, thisArray.length(), value).

Specified by:
fill in interface UpdatableShortArray
Parameters:
value - the value to be stored in all elements of the array.
Returns:
a reference to this array.
See Also:
UpdatableShortArray.fill(long, long, short), Arrays.zeroFill(UpdatableArray)

fill

public UpdatableShortArray fill(long position,
                                long count,
                                short value)
This implementation does the following: subArr(position, count).copy(Arrays.nShortCopies(count, value)). Please override this method if it's possible to perform the same task more efficiently.

Specified by:
fill in interface UpdatableShortArray
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:
java.lang.IndexOutOfBoundsException - for illegal position and count (position < 0 || count < 0 || position + count > length()).
See Also:
UpdatableShortArray.fill(short), Arrays.zeroFill(UpdatableArray)

isImmutable

public boolean isImmutable()
This implementation returns false.

Specified by:
isImmutable in interface Array
Overrides:
isImmutable in class AbstractShortArray
Returns:
true if this instance is immutable.
See Also:
Array.asImmutable()

asImmutable

public ShortArray asImmutable()
This implementation returns an instance of the subclass of AbstractShortArray, where the following method are overridden and call the same methods of this instance: AbstractShortArray.getShort(long), AbstractShortArray.getData(long, Object, int, int), AbstractShortArray.getData(long, Object), AbstractShortArray.loadResources(ArrayContext, long, long), AbstractShortArray.flushResources(ArrayContext, long, long, boolean) and AbstractShortArray.freeResources(ArrayContext, long, long, boolean).

The returned instance also have overridden method AbstractArray.isLazy(), that just calls the same methods of this instance with the same arguments.

Specified by:
asImmutable in interface Array
Specified by:
asImmutable in interface PArray
Specified by:
asImmutable in interface PFixedArray
Specified by:
asImmutable in interface PIntegerArray
Specified by:
asImmutable in interface ShortArray
Overrides:
asImmutable in class AbstractShortArray
Returns:
an immutable view of this array.
See Also:
Array.isImmutable(), Array.asTrustedImmutable(), Array.mutableClone(MemoryModel), Array.updatableClone(MemoryModel), UpdatableArray.asUnresizable()

shallowClone

public UpdatableArray shallowClone()
This implementation returns (UpdatableArray)super.shallowClone().

Specified by:
shallowClone in interface Array
Specified by:
shallowClone in interface UpdatableArray
Overrides:
shallowClone in class AbstractArray
Returns:
a shallow copy of this object.
See Also:
Array.length(), Array.capacity(), DirectAccessible.javaArrayOffset(), Array.isCopyOnNextWrite()

setElement

public void setElement(long index,
                       java.lang.Object value)
This implementation calls setShort(index, (Short)value).shortValue()).

Specified by:
setElement in interface UpdatableArray
Parameters:
index - index of element to replace.
value - element to be stored at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range 0..length()-1.
java.lang.NullPointerException - if value == null and it is an array of primitive elements
java.lang.ClassCastException - if it is an array of primitive elements and value is not a corresponding wrapped class (Boolean, Integer, etc.)
java.lang.ArrayStoreException - if it is an array of non-primitive elements and value is not an instance of AbstractShortArray.elementType() class

setData

public UpdatableArray setData(long arrayPos,
                              java.lang.Object srcArray,
                              int srcArrayOffset,
                              int count)
This implementation is based on a loop of calls of setShort(long, short) method. Please override this method if it's possible to perform the same task more efficiently than such a loop.

Specified by:
setData in interface UpdatableArray
Parameters:
arrayPos - starting position in this AlgART array.
srcArray - the source Java array.
srcArrayOffset - starting position in the source Java array.
count - the number of elements to be copied.
Returns:
a reference to this AlgART array.
Throws:
java.lang.NullPointerException - if srcArray argument is null.
java.lang.IllegalArgumentException - if srcArray argument is not an array.
java.lang.IndexOutOfBoundsException - if copying would cause access of data outside this array or source Java array.
java.lang.ArrayStoreException - if destArray element type mismatches with this array elementType().
java.lang.ClassCastException - if destArray element type mismatches with this array elementType() (both this and ArrayStoreException are possible, depending on implementation).
See Also:
DirectAccessible, Array.getData(long, Object, int, int)

setData

public UpdatableArray setData(long arrayPos,
                              java.lang.Object srcArray)
This implementation calls setData(long, Object, int, int) with corresponding arguments.

Specified by:
setData in interface UpdatableArray
Parameters:
arrayPos - starting position in this AlgART array.
srcArray - the source Java array.
Returns:
a reference to this AlgART array.
Throws:
java.lang.NullPointerException - if srcArray argument is null.
java.lang.IllegalArgumentException - if srcArray argument is not an array.
java.lang.IndexOutOfBoundsException - if copying would cause access of data outside this array or source Java array.
java.lang.ArrayStoreException - if destArray element type mismatches with this array AbstractShortArray.elementType().
java.lang.ClassCastException - if destArray element type mismatches with this array AbstractShortArray.elementType() (both this and ArrayStoreException are possible, depending on implementation).
See Also:
DirectAccessible, UpdatableArray.setData(long, Object, int, int), Array.getData(long, Object), UpdatableBitArray.setBits(long, long[], long, long)

copy

public void copy(long destIndex,
                 long srcIndex)
This implementation calls setShort(destIndex, (short) getShort(srcIndex)).

Specified by:
copy in interface UpdatableArray
Parameters:
destIndex - index of element to replace.
srcIndex - index of element to be copied.
Throws:
java.lang.IndexOutOfBoundsException - if one of indexes is out of range 0..length()-1.

copy

public void copy(long destIndex,
                 long srcIndex,
                 long count)
This implementation is based on a loop of calls of copy(long, long) method.

Specified by:
copy in interface UpdatableArray
Parameters:
destIndex - starting index of element to replace.
srcIndex - starting index of element to be copied.
count - the number of elements to be copied.
Throws:
java.lang.IndexOutOfBoundsException - if one of indexes is out of range 0..length()-1.

swap

public void swap(long firstIndex,
                 long secondIndex)
This implementation swaps two elements by AbstractShortArray.getShort(long) and setShort(long, short) methods.

Specified by:
swap in interface ArrayExchanger
Specified by:
swap in interface UpdatableArray
Parameters:
firstIndex - first index of element to exchange.
secondIndex - second index of element to exchange.
Throws:
java.lang.IndexOutOfBoundsException - if one of indexes is out of range 0..length()-1.

swap

public void swap(long firstIndex,
                 long secondIndex,
                 long count)
This implementation is based on a loop of calls of swap(long, long) method.

Specified by:
swap in interface UpdatableArray
Parameters:
firstIndex - starting first index of element to exchange.
secondIndex - starting second index of element to exchange.
count - the number of elements to be exchanged.
Throws:
java.lang.IndexOutOfBoundsException - if one of indexes is out of range 0..length()-1.

copy

public UpdatableArray copy(Array src)
This implementation calls defaultCopy(thisInstance, src).

Specified by:
copy in interface UpdatableArray
Parameters:
src - the source array.
Returns:
a reference to this array.
Throws:
java.lang.NullPointerException - if src argument is null.
java.lang.IllegalArgumentException - if the source and this element types do not match.
See Also:
Arrays.copy(ArrayContext, UpdatableArray, Array)

swap

public UpdatableArray swap(UpdatableArray another)
This implementation calls defaultSwap(thisInstance, another).

Specified by:
swap in interface UpdatableArray
Parameters:
another - another array.
Returns:
a reference to this array.
Throws:
java.lang.NullPointerException - if another argument is null.
java.lang.IllegalArgumentException - if another and this element types do not match.

setNonNew

public void setNonNew()
This implementation calls setNewStatus(false).

Specified by:
setNonNew in interface UpdatableArray

asCopyOnNextWrite

public UpdatableArray asCopyOnNextWrite()
This implementation returns updatableClone(Arrays.SMM).

Specified by:
asCopyOnNextWrite in interface Array
Specified by:
asCopyOnNextWrite in interface UpdatableArray
Overrides:
asCopyOnNextWrite in class AbstractShortArray
Returns:
a copy of this object.
See Also:
Array.isCopyOnNextWrite(), MemoryModel.newLazyCopy(Array), MemoryModel.newUnresizableLazyCopy(Array)

asUnresizable

public UpdatableShortArray asUnresizable()
This implementation returns this object. Should be overridden if the inheritor is resizable.

Specified by:
asUnresizable in interface UpdatableArray
Specified by:
asUnresizable in interface UpdatablePArray
Specified by:
asUnresizable in interface UpdatablePFixedArray
Specified by:
asUnresizable in interface UpdatablePIntegerArray
Specified by:
asUnresizable in interface UpdatableShortArray
Returns:
an unresizable view of this array.
See Also:
Array.isUnresizable()

toString

public java.lang.String toString()
Description copied from interface: Array
Returns a brief string description of this object.

The result of this method may depend on implementation and usually contains a short description of the array length, capacity, element type.

Note: for character arrays, unlike CharSequence.toString(), this method works as for all other array types. If you need to convert a character array to a string, containing all characters of the array, you may use Arrays.toString(CharArray) method.

Specified by:
toString in interface Array
Overrides:
toString in class AbstractShortArray
Returns:
a brief string description of this object.