Class LongVector
- All Implemented Interfaces:
AsciiSerializable,FieldAccessor,Serializable,Cloneable
LongVector class implements a growable array of
long primatives. Like an array, it contains components that can be
accessed using an integer index. However, the size of a
LongVector can grow or shrink as needed to accommodate
adding and removing items after the LongVector has been created.
Each vector tries to optimize storage management by maintaining a
capacity and a capacityIncrement. The
capacity is always at least as large as the vector
size; it is usually larger because as components are added to the
vector, the vector's storage increases in chunks the size of
capacityIncrement. An application can increase the
capacity of a vector before inserting a large number of
components; this reduces the amount of incremental reallocation.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity.protected intThe number of valid components in the vector.protected long[]The array buffer into which the components of the vector are stored. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty vector.LongVector(int initialCapacity) Constructs an empty vector with the specified initial capacity.LongVector(int initialCapacity, int capacityIncrement) Constructs an empty vector with the specified initial capacity and capacity increment. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(long obj) Adds the specified component to the end of this vector, increasing its size by one.booleanaddAll(long[] array) final voidaddElement(long obj) Adds the specified component to the end of this vector, increasing its size by one.final intcapacity()Returns the current capacity of this vector.voidclear()Removes all components from this vector and sets its size to zero.clone()Returns a clone of this vector.final booleancontains(long elem) Tests if the specified long is a component in this vector.final voidcopyInto(long[] anArray) Copies the components of this vector into the specified array.final longelementAt(int index) Returns the component at the specified index.final voidensureCapacity(int minCapacity) Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.final longReturns the first component of this vector.longget(int index) Returns the component at the specified index.getFieldObject(Field fld) This method allows access to java.lang.reflect.Field objects within the implementing class.final intindexOf(long elem) Searches for the first occurence of the given argument, testing for equality using theequalsmethod.final intindexOf(long elem, int index) Searches for the first occurence of the given argument, beginning the search atindex, and testing for equality using theequalsmethod.final voidinsertElementAt(long obj, int index) Inserts the specified long as a component in this vector at the specifiedindex.final booleanisEmpty()Tests if this vector has no components.final longReturns the last component of the vector.final intlastIndexOf(long elem) Returns the index of the last occurrence of the specified long in this vector.final intlastIndexOf(long elem, int index) Searches backwards for the specified long, starting from the specified index, and returns an index to it.booleanremove(long obj) Removes the first occurrence of the argument from this vector.final voidRemoves all components from this vector and sets its size to zero.final booleanremoveElement(long obj) Removes the first occurrence of the argument from this vector.final voidremoveElementAt(int index) Deletes the component at the specified index.final voidsetElementAt(long obj, int index) Sets the component at the specifiedindexof this vector to be the specified long.booleansetFieldObject(Field fld, Object fobj) This allows access to fields withing the implementing object to set there data.final voidsetSize(int newSize) Sets the size of this vector.final intsize()Returns the number of components in this vector.final StringtoString()Returns a string representation of this vector.final voidTrims the capacity of this vector to be the vector's current size.
-
Field Details
-
elementData
protected long[] elementDataThe array buffer into which the components of the vector are stored. The capacity of the vector is the length of this array buffer.- Since:
- JDK1.0
-
elementCount
protected int elementCountThe number of valid components in the vector.- Since:
- JDK1.0
-
capacityIncrement
protected int capacityIncrementThe amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity. If the capacity increment is0, the capacity of the vector is doubled each time it needs to grow.- Since:
- JDK1.0
-
-
Constructor Details
-
LongVector
public LongVector(int initialCapacity, int capacityIncrement) Constructs an empty vector with the specified initial capacity and capacity increment.- Parameters:
initialCapacity- the initial capacity of the vector.capacityIncrement- the amount by which the capacity is increased when the vector overflows.- Since:
- JDK1.0
-
LongVector
public LongVector(int initialCapacity) Constructs an empty vector with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity of the vector.- Since:
- JDK1.0
-
LongVector
public LongVector()Constructs an empty vector.- Since:
- JDK1.0
-
-
Method Details
-
copyInto
public final void copyInto(long[] anArray) Copies the components of this vector into the specified array. The array must be big enough to hold all the longs in this vector.- Parameters:
anArray- the array into which the components get copied.- Since:
- JDK1.0
-
trimToSize
public final void trimToSize()Trims the capacity of this vector to be the vector's current size. An application can use this operation to minimize the storage of a vector.- Since:
- JDK1.0
-
ensureCapacity
public final void ensureCapacity(int minCapacity) Increases the capacity of this vector, 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.- Since:
- JDK1.0
-
setSize
public final void setSize(int newSize) Sets the size of this vector. If the new size is greater than the current size, newRMAConst.UNDEF_LONGitems are added to the end of the vector. If the new size is less than the current size, all components at indexnewSizeand greater are discarded.- Parameters:
newSize- the new size of this vector.- Since:
- JDK1.0
-
capacity
public final int capacity()Returns the current capacity of this vector.- Returns:
- the current capacity of this vector.
- Since:
- JDK1.0
-
size
public final int size()Returns the number of components in this vector.- Returns:
- the number of components in this vector.
- Since:
- JDK1.0
-
isEmpty
public final boolean isEmpty()Tests if this vector has no components.- Returns:
trueif this vector has no components;falseotherwise.- Since:
- JDK1.0
-
contains
public final boolean contains(long elem) Tests if the specified long is a component in this vector.- Parameters:
elem- an long.- Returns:
trueif the specified long is a component in this vector;falseotherwise.- Since:
- JDK1.0
-
indexOf
public final int indexOf(long elem) Searches for the first occurence of the given argument, testing for equality using theequalsmethod.- Parameters:
elem- an long.- Returns:
- the index of the first occurrence of the argument in this
vector; returns
-1if the long is not found. - Since:
- JDK1.0
- See Also:
-
indexOf
public final int indexOf(long elem, int index) Searches for the first occurence of the given argument, beginning the search atindex, and testing for equality using theequalsmethod.- Parameters:
elem- an long.index- the index to start searching from.- Returns:
- the index of the first occurrence of the long argument in
this vector at position
indexor later in the vector; returns-1if the long is not found. - Since:
- JDK1.0
- See Also:
-
lastIndexOf
public final int lastIndexOf(long elem) Returns the index of the last occurrence of the specified long in this vector.- Parameters:
elem- the desired component.- Returns:
- the index of the last occurrence of the specified long in
this vector; returns
-1if the long is not found. - Since:
- JDK1.0
-
lastIndexOf
public final int lastIndexOf(long elem, int index) Searches backwards for the specified long, 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 long in this
vector at position less than
indexin the vector;-1if the long is not found. - Since:
- JDK1.0
-
get
public long get(int index) Returns the component at the specified index. wrapper for elementAt(int); -
elementAt
public final long elementAt(int index) Returns the component at the specified index.- Parameters:
index- an index into this vector.- Returns:
- the component at the specified index.
- Throws:
ArrayIndexOutOfBoundsException- if an invalid index was given.- Since:
- JDK1.0
-
firstElement
public final long firstElement()Returns the first component of this vector.- Returns:
- the first component of this vector.
- Throws:
NoSuchElementException- if this vector has no components.- Since:
- JDK1.0
-
lastElement
public final long lastElement()Returns the last component of the vector.- Returns:
- the last component of the vector, i.e., the component at index
size() - 1. - Throws:
NoSuchElementException- if this vector is empty.- Since:
- JDK1.0
-
setElementAt
public final void setElementAt(long obj, int index) Sets the component at the specifiedindexof this vector to be the specified long. The previous component at that position is discarded.The index must be a value greater than or equal to
0and less than the current size of the vector.- Parameters:
obj- what the component is to be set to.index- the specified index.- Throws:
ArrayIndexOutOfBoundsException- if the index was invalid.- Since:
- JDK1.0
- See Also:
-
removeElementAt
public final void removeElementAt(int index) Deletes the component at the specified index. Each component in this vector with an index greater or equal to the specifiedindexis 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
0and less than the current size of the vector.- Parameters:
index- the index of the long to remove.- Throws:
ArrayIndexOutOfBoundsException- if the index was invalid.- Since:
- JDK1.0
- See Also:
-
insertElementAt
public final void insertElementAt(long obj, int index) Inserts the specified long as a component in this vector at the specifiedindex. Each component in this vector with an index greater or equal to the specifiedindexis 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
0and less than or equal to the current size of the vector.- Parameters:
obj- the component to insert.index- where to insert the new component.- Throws:
ArrayIndexOutOfBoundsException- if the index was invalid.- Since:
- JDK1.0
- See Also:
-
add
public void add(long obj) Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity. wrapper for addElement(long); -
addElement
public final void addElement(long obj) Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity.- Parameters:
obj- the component to be added.- Since:
- JDK1.0
-
addAll
public boolean addAll(long[] array) -
remove
public boolean remove(long obj) Removes the first occurrence of the argument from this vector. If the long is found in this vector, each component in the vector with an index greater or equal to the long's index is shifted downward to have an index one smaller than the value it had previously. wrapper for removeElement(long) -
removeElement
public final boolean removeElement(long obj) Removes the first occurrence of the argument from this vector. If the long is found in this vector, each component in the vector with an index greater or equal to the long'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:
trueif the argument was a component of this vector;falseotherwise.- Since:
- JDK1.0
-
clear
public void clear()Removes all components from this vector and sets its size to zero. wrapper for removeAllElements(); -
removeAllElements
public final void removeAllElements()Removes all components from this vector and sets its size to zero.- Since:
- JDK1.0
-
clone
Returns a clone of this vector. -
toString
Returns a string representation of this vector. -
getFieldObject
Description copied from interface:FieldAccessorThis method allows access to java.lang.reflect.Field objects within the implementing class.- Specified by:
getFieldObjectin interfaceFieldAccessor- Parameters:
fld- The field to get.- Returns:
- The data object that is stored in the given field
-
setFieldObject
Description copied from interface:FieldAccessorThis allows access to fields withing the implementing object to set there data.- Specified by:
setFieldObjectin interfaceFieldAccessor- Parameters:
fld- The java field object representing the member field to be setfobj- The data to set in that field- Returns:
- returns true if successful
-