Package rma.util
Class ShortArray
java.lang.Object
rma.util.ShortArray
- All Implemented Interfaces:
AsciiSerializable
,FieldAccessor
,Serializable
,Cloneable
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
The amount by which the capacity of the array is automatically incremented when its size becomes greater than its capacity.protected int
The number of valid components in the array.protected short[]
The array buffer into which the components of the array are stored. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty array.ShortArray
(int initialCapacity) Constructs an empty array with the specified initial capacity.ShortArray
(int initialCapacity, int capacityIncrement) Constructs an empty array with the specified initial capacity and capacity increment.ShortArray
(short[] array) Constructs a new IntArray with the capacity set to the argument array length then copys the argument array data into the element data array. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(short obj) Adds the specified component to the end of this array, increasing its size by one.boolean
addAll
(short[] array) Appends the ints in the argument array to this int array.boolean
addAll
(ShortArray sa) Appends the shorts in the argument array to this shortarray.final void
addElement
(short obj) Adds the specified component to the end of this array, increasing its size by one.final int
capacity()
Returns the current capacity of this array.void
clear()
Removes all components from this array and sets its size to zero.clone()
Returns a clone of this array.final boolean
contains
(short elem) Tests if the specified short is a component in this array.final void
copyInto
(short[] anArray) Copies the components of this array into the specified array.final void
Copies the components of this array into the specified array.final short
elementAt
(int index) Returns the component at the specified index.long
Returns the total value of all the elementsfinal void
ensureCapacity
(int minCapacity) Increases the capacity of this array, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.final short
Returns the first component of this array.short
get
(int index) Returns the component at the specified index.getFieldObject
(Field fld) Gets the FieldObject attribute of the IntVector objectfinal int
indexOf
(short elem) Searches for the first occurrence of the given argument, testing for equality using==
.final int
indexOf
(short elem, int index) Searches for the first occurrence of the given argument, beginning the search atindex
, and testing for equality using==
.final void
insertElementAt
(short obj, int index) Inserts the specified short as a component in this array at the specifiedindex
.final boolean
isEmpty()
Tests if this array has no components.final short
Returns the last component of the array.final int
lastIndexOf
(short elem) Returns the index of the last occurrence of the specified short in this array.final int
lastIndexOf
(short elem, int index) Searches backwards for the specified short, starting from the specified index, and returns an index to it.boolean
remove
(short obj) Removes the first occurrence of the argument from this array.int
removeAll
(short[] objs) Removes the first occurrence of the argument from this array.final void
Removes all components from this array and sets its size to zero.final boolean
removeElement
(short obj) Removes the first occurrence of the argument from this array.final void
removeElementAt
(int index) Deletes the component at the specified index.final short
remove and return the last element of the arrayfinal void
setElementAt
(short obj, int index) Sets the component at the specifiedindex
of this array to be the specified short.boolean
setFieldObject
(Field fld, Object fobj) Sets the FieldObject attribute of the IntVector objectfinal void
setSize
(int newSize) Sets the size of this array.final int
size()
Returns the number of components in this array.short[]
toArray()
Returns the short data in a new array.final String
toString()
Returns a string representation of this array.final void
Trims the capacity of this array to be the arrays's current size.
-
Field Details
-
_elementData
protected short[] _elementDataThe array buffer into which the components of the array are stored. The capacity of the array is the length of this array buffer. -
_elementCount
protected int _elementCountThe number of valid components in the array. -
_capacityIncrement
protected int _capacityIncrementThe amount by which the capacity of the array is automatically incremented when its size becomes greater than its capacity. If the capacity increment is0
, the capacity of the array is doubled each time it needs to grow.
-
-
Constructor Details
-
ShortArray
public ShortArray(int initialCapacity, int capacityIncrement) Constructs an empty array with the specified initial capacity and capacity increment.- Parameters:
initialCapacity
- the initial capacity of the array._capacityIncrement
- the amount by which the capacity is increased when the array overflows.
-
ShortArray
public ShortArray(int initialCapacity) Constructs an empty array with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the array.
-
ShortArray
public ShortArray()Constructs an empty array. -
ShortArray
public ShortArray(short[] array) Constructs a new IntArray with the capacity set to the argument array length then copys the argument array data into the element data array.- Parameters:
array
-
-
-
Method Details
-
addAll
public boolean addAll(short[] array) Appends the ints in the argument array to this int array. Returns a boolean if the number of ints added is > 0. -
addAll
Appends the shorts in the argument array to this shortarray. Returns a boolean if the number of ints added is > 0. -
toArray
public short[] toArray()Returns the short data in a new array.- Returns:
-
copyInto
public final void copyInto(short[] anArray) Copies the components of this array into the specified array. The array must be big enough to hold all the ints in this array.- Parameters:
anArray
- the array into which the components get copied.
-
copyInto
Copies the components of this array into the specified array. The array must be big enough to hold all the ints in this array.- Parameters:
anArray
- the Integer array into which the components get copied.
-
trimToSize
public final void trimToSize()Trims the capacity of this array to be the arrays's current size. An application can use this operation to minimize the storage of a array. -
ensureCapacity
public final void ensureCapacity(int minCapacity) Increases the capacity of this array, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.- Parameters:
minCapacity
- the desired minimum capacity.
-
setSize
public final void setSize(int newSize) Sets the size of this array. If the new size is greater than the current size, newRMAConst.UNDEF_INT
items are added to the end of the array. If the new size is less than the current size, all components at indexnewSize
and greater are discarded.- Parameters:
newSize
- the new size of this array.
-
capacity
public final int capacity()Returns the current capacity of this array.- Returns:
- the current capacity of this array.
- Since:
- JDK1.0
-
size
public final int size()Returns the number of components in this array.- Returns:
- the number of components in this array.
- Since:
- JDK1.0
-
isEmpty
public final boolean isEmpty()Tests if this array has no components.- Returns:
true
if this array has no components;false
otherwise.- Since:
- JDK1.0
-
contains
public final boolean contains(short elem) Tests if the specified short is a component in this array.- Parameters:
elem
- an short.- Returns:
true
if the specified short is a component in this array;false
otherwise.
-
indexOf
public final int indexOf(short elem) Searches for the first occurrence of the given argument, testing for equality using==
.- Parameters:
elem
- an short.- Returns:
- the index of the first occurrence of the argument in this
array; returns
-1
if the short is not found.
-
indexOf
public final int indexOf(short elem, int index) Searches for the first occurrence of the given argument, beginning the search atindex
, and testing for equality using==
.- Parameters:
elem
- an short.index
- the index to start searching from.- Returns:
- the index of the first occurrence of the short argument in this
array at position
index
or later in the array; returns-1
if the short is not found.
-
lastIndexOf
public final int lastIndexOf(short elem) Returns the index of the last occurrence of the specified short in this array.- Parameters:
elem
- the desired component.- Returns:
- the index of the last occurrence of the specified short in this
array; returns
-1
if the short is not found.
-
lastIndexOf
public final int lastIndexOf(short elem, int index) Searches backwards for the specified short, starting from the specified index, and returns an index to it.- Parameters:
elem
- the desired component.index
- the index to start searching from.- Returns:
- the index of the last occurrence of the specified short in this
array at position less than
index
in the array;-1
if the short is not found.
-
get
public short get(int index) Returns the component at the specified index. wrapper for elementAt(int);- Parameters:
index
- Description- Returns:
- Description
-
elementAt
public final short elementAt(int index) Returns the component at the specified index.- Parameters:
index
- an index into this array.- Returns:
- the component at the specified index.
-
firstElement
public final short firstElement()Returns the first component of this array.- Returns:
- the first component of this array.
- Since:
- JDK1.0
-
lastElement
public final short lastElement()Returns the last component of the array.- Returns:
- the last component of the array, i.e.,
the component at index
size() - 1
. - Since:
- JDK1.0
-
removeLastElement
public final short removeLastElement()remove and return the last element of the array- Returns:
-
setElementAt
public final void setElementAt(short obj, int index) Sets the component at the specifiedindex
of this array to be the specified short. The previous component at that position is discarded.The index must be a value greater than or equal to
0
and less than the current size of the array.- Parameters:
obj
- what the component is to be set to.index
- the specified index.- See Also:
-
java.util.array#size()
-
removeElementAt
public final void removeElementAt(int index) Deletes the component at the specified index. Each component in this array with an index greater or equal to the specifiedindex
is shifted downward to have an index one smaller than the value it had previously.The index must be a value greater than or equal to
0
and less than the current size of the array.- Parameters:
index
- the index of the int to remove.- See Also:
-
java.util.array#size()
-
insertElementAt
public final void insertElementAt(short obj, int index) Inserts the specified short as a component in this array at the specifiedindex
. Each component in this array with an index greater or equal to the specifiedindex
is shifted upward to have an index one greater than the value it had previously.The index must be a value greater than or equal to
0
and less than or equal to the current size of the array.- Parameters:
obj
- the component to insert.index
- where to insert the new component.- See Also:
-
java.util.array#size()
-
add
public void add(short obj) Adds the specified component to the end of this array, increasing its size by one. The capacity of this array is increased if its size becomes greater than its capacity. wrapper for addElement(short);- Parameters:
obj
- Description
-
addElement
public final void addElement(short obj) Adds the specified component to the end of this array, increasing its size by one. The capacity of this array is increased if its size becomes greater than its capacity.- Parameters:
obj
- the component to be added.
-
remove
public boolean remove(short obj) Removes the first occurrence of the argument from this array. If the int is found in this array, each component in the array with an index greater or equal to the int's index is shifted downward to have an index one smaller than the value it had previously. wrapper for removeElement(int)- Parameters:
obj
- Description- Returns:
- Description
-
removeAll
public int removeAll(short[] objs) Removes the first occurrence of the argument from this array. If the int is found in this array, each component in the array with an index greater or equal to the int's index is shifted downward to have an index one smaller than the value it had previously.- Parameters:
objs
- Description- Returns:
- the number of items removed
-
removeElement
public final boolean removeElement(short obj) Removes the first occurrence of the argument from this array. If the int is found in this array, each component in the array with an index greater or equal to the int's index is shifted downward to have an index one smaller than the value it had previously.- Parameters:
obj
- the component to be removed.- Returns:
true
if the argument was a component of this array;false
otherwise.
-
clear
public void clear()Removes all components from this array and sets its size to zero. wrapper for removeAllElements(); -
removeAllElements
public final void removeAllElements()Removes all components from this array and sets its size to zero. -
clone
Returns a clone of this array. -
elementTotal
public long elementTotal()Returns the total value of all the elements -
toString
Returns a string representation of this array. -
getFieldObject
Gets the FieldObject attribute of the IntVector object- Specified by:
getFieldObject
in interfaceFieldAccessor
- Parameters:
fld
- Description- Returns:
- The FieldObject value
-
setFieldObject
Sets the FieldObject attribute of the IntVector object- Specified by:
setFieldObject
in interfaceFieldAccessor
- Parameters:
fld
- The new FieldObject valuefobj
- The new FieldObject value- Returns:
- Description
-