|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.javasoft.util.LongArray
public class LongArray
The LongArray is an dynamic size array for longs. Values can be
added causing the array to grow dynamically.
| Constructor Summary | |
|---|---|
LongArray()
Constructor for LongArray with default capacity |
|
LongArray(int capacity)
Constructor for LongArray with default capacity |
|
LongArray(long[] initialValues)
Constructor for LongArray with specified values. |
|
LongArray(long[] original,
int from,
int to)
Constructor for LongArray with specified values. |
|
| Method Summary | |
|---|---|
boolean |
add(int index,
long value)
Adds the specified value at the given position of the array. |
void |
add(long value)
Adds the specified value to the end of this long array |
void |
addAll(int from,
int to,
long... values)
Adds the specified values to the end of this long array |
void |
addAll(int from,
int to,
LongArray array)
Adds the values from array to the end of this int array |
void |
addAll(long... values)
Adds the specified values to the end of this long array |
void |
addAll(LongArray array)
Adds the values from array to the end of this long array |
int |
addToSorted(long value)
Adds the given value at the position where the value fits according to binarySearch(long). |
int |
binarySearch(long key)
Searches this int array for the specified value using the binary search algorithm. |
int |
binarySearch(long key,
int fromIndex,
int toIndex)
Searches this int array for the specified value using the binary search algorithm. |
void |
clear()
Removes all elements, but does not shrink the underlying array (that is, the capacity is kept as it is). |
LongArray |
clone()
Returns a clone of this long array |
static long[][] |
clone(long[][] arr)
Returns a deep clone of the given array |
protected void |
ensureCapacity(int size)
Internal method, called to ensure capacity size |
boolean |
equals(Object obj)
|
long |
first()
Returns the first element, or throws an IndexOutOfBoundsException
if the array is empty |
long |
get(int index)
Returns the value at the specified position |
int |
hashCode()
|
int |
indexOf(int fromIndex,
long value)
Returns the first index containing a value equal to the specified value starting at position fromIndex. |
int |
indexOf(long value)
Returns the first index containing a value equal to the specified value. |
protected long |
initialValue()
This method can be overriden to define an alternate initial value. |
boolean |
isEmpty()
Returns true if the array length is zero |
Iterator<Long> |
iterator()
Returns an immutable iterator with the long values of this array |
long |
last()
Returns the last element, or throws an IndexOutOfBoundsException
if the array is empty |
int |
length()
Returns the current length of this array, that is, the number of elements in the array. |
long |
remove(int index)
Removes the specified value and moves all values on the right one position leftwards. |
long |
removeLast()
Removes the last value, or throws an IndexOutOfBoundsException if
the array is empty. |
long |
set(int index,
long value)
Sets the value at the specified position. |
void |
sort(boolean ascending)
Sort the array ascending or descending. |
void |
sort(boolean ascending,
int start,
int end)
Sort the specified array range ascending or descending. |
LongArray |
subRange(int from)
Returns a new array instance containing a copy of a range of this array. |
LongArray |
subRange(int from,
int to)
Returns a new array instance containing a copy of a range of this array. |
void |
swap(int indexA,
int indexB)
Interchange the values at the specified positions |
static void |
swap(long[] arr,
int indexA,
int indexB)
Interchange the values at the specified array positions |
long[] |
toArray()
Clones the underlying array (trimmed to length) and returns it |
static long[][] |
toMatrix(Collection<long[]> mx,
boolean cloneArrays)
Converts the given collection of long arrays to a two dimensional long array. |
static long[][] |
toMatrix(Collection<LongArray> mx)
Converts the given collection of LongArray instances to a
two dimensional long array |
static long[][] |
toMatrix(LongArray[] mx)
Converts the given array of LongArray instances to a two
dimensional long array |
String |
toString()
Returns a string representation of the contents of this array. |
void |
trimToLength()
Fixes the capacity of the underlying array to the current length of this array. |
long[] |
yieldArray()
Returns the internal array after trimming it to the current length and returns it. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public LongArray()
LongArray with default capacity
public LongArray(int capacity)
LongArray with default capacity
public LongArray(long[] initialValues)
LongArray with specified values. The given
array is not cloned, thus, changes to the array are also reflected in
the state this LongArray.
public LongArray(long[] original,
int from,
int to)
LongArray with specified values. The given
array is cloned.
Copies the specified range of the specified array into this new array. The initial index of the range (from) must lie between zero and original.length, inclusive. The value at original[from] is placed into the initial element of the copy (unless from == original.length or from == to). Values from subsequent elements in the original array are placed into subsequent elements in the copy. The final index of the range (to), which must be greater than or equal to from, may be greater than original.length, in which case 0d is placed in all elements of the copy whose index is greater than or equal to original.length - from. The length of the this array will be to - from.
original - the array from which a range is to be copiedfrom - the initial index of the range to be copied, inclusiveto - the final index of the range to be copied, exclusive.
(This index may lie outside the array.)| Method Detail |
|---|
public int length()
public boolean isEmpty()
length is zero
public long get(int index)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic int indexOf(long value)
value. If no such value is found, -1 is
returned.
value - the value to search for
value, or
-1 if no such value is found
public int indexOf(int fromIndex,
long value)
value starting at position fromIndex. If no
such value is found, -1 is returned.
fromIndex - the index (inclusive) at which the search is startedvalue - the value to search for
value, or
-1 if no such value is found
public long set(int index,
long value)
throws IndexOutOfBoundsException
index is
smaller than the current length(), the value at the specified
position is replaced by value. If index equal
to the length of this array, the value is appended. If it
is larger than length, it is also appended after filling the
gap positions with initial values.
index - the index at which value will be storedvalue - the new value to be set
IndexOutOfBoundsExceptionpublic void add(long value)
public void addAll(LongArray array)
array to the end of this long array
public void addAll(int from,
int to,
LongArray array)
array to the end of this int array
public void addAll(long... values)
public void addAll(int from,
int to,
long... values)
public boolean add(int index,
long value)
index is negative or larger than the current
length of this array, an
IndexOutOfBoundsException is thrown.
public long removeLast()
IndexOutOfBoundsException if
the array is empty.
public long remove(int index)
IndexOutOfBoundsException - if index is negative or
larger or equal to
lengthpublic void clear()
public long first()
IndexOutOfBoundsException
if the array is empty
public long last()
IndexOutOfBoundsException
if the array is empty
public void swap(int indexA,
int indexB)
protected void ensureCapacity(int size)
size
size - the desired capacityprotected long initialValue()
set(int, long) is used with an index
larger than the length of the array.
Default initial value is 0
public long[] toArray()
public long[] yieldArray()
LongArray will be empty after this
operation.
public LongArray clone()
clone in class Objectpublic LongArray subRange(int from)
from (inclusive) to the end of this
array.
from - the start index of the range, inclusive
public LongArray subRange(int from,
int to)
from (inclusive) to to
(exclusive).
from - the start index of the range, inclusiveto - the end index of the range, exclusive
public Iterator<Long> iterator()
iterator in interface Iterable<Long>public static long[][] toMatrix(LongArray[] mx)
LongArray instances to a two
dimensional long array
mx - the array of LongArray instances to convert to
a 2-dim array
public static long[][] toMatrix(Collection<LongArray> mx)
LongArray instances to a
two dimensional long array
mx - the collection of arrays to convert to a 2-dim array
public static long[][] toMatrix(Collection<long[]> mx,
boolean cloneArrays)
mx - the collection of arrays to convert to a 2-dim arraycloneArrays - if true, the source arrays are cloned
public static void swap(long[] arr,
int indexA,
int indexB)
public static long[][] clone(long[][] arr)
public void trimToLength()
length of this array. Note that this operation might
be expensive due to array copying.
public int binarySearch(long key)
throws IllegalStateException
sort(boolean) method) prior to making this
call. If it is not sorted, the results are undefined. If the array
contains multiple elements with the specified value, there is no
guarantee which one will be found.
key - the value to be searched for.
IllegalStateExceptionArrays.binarySearch(int[], int, int, int)
public int binarySearch(long key,
int fromIndex,
int toIndex)
throws IllegalStateException
sort(boolean) method) prior to making this
call. If it is not sorted, the results are undefined. If the array
contains multiple elements with the specified value, there is no
guarantee which one will be found.
key - the value to be searched for.fromIndex - the index of the first element (inclusive) to be
searchedtoIndex - the index of the last element (exclusive) to be searched
IllegalStateExceptionArrays.binarySearch(int[], int, int, int)public int addToSorted(long value)
binarySearch(long). If this int array is not sorted
ascending, the result is undefined.
value - the value to insert
public void sort(boolean ascending)
binarySearch(long) and
addToSorted(long) methods can be used
ascending - true for ascending sort order
public void sort(boolean ascending,
int start,
int end)
binarySearch(long) and
addToSorted(long) methods can be used.
This method should only be used if one knows that only the defined
interval needs sorting. Otherwise, sort(boolean) should be used
instead.
ascending - true for ascending sort orderstart - the index where the sorting starts (inclusive)end - the index where the sorting ends (exclusive)public int hashCode()
hashCode in class Objectpublic boolean equals(Object obj)
equals in class Objectpublic String toString()
toString in class ObjectArrays.toString(long[])
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||