|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.geotools.resources.XArray
public final class XArray
Simple operations on arrays. This class provides a central place for
inserting and deleting elements in an array, as well as resizing the array.
This class may be removed if JavaSoft provide some language construct
functionally equivalent to C/C++'s realloc
.
Method Summary | ||
---|---|---|
static boolean |
allEquals(double[] array,
double value)
Returns true if all values in the specified array are equals to the specified
value, which may be Double.NaN . |
|
static boolean |
allEquals(float[] array,
float value)
Returns true if all values in the specified array are equals to the specified
value, which may be Float.NaN . |
|
static boolean |
contains(java.lang.Object[] array,
java.lang.Object value)
Returns true if the specified array contains the specified value. |
|
static boolean |
containsIgnoreCase(java.lang.String[] array,
java.lang.String value)
Returns true if the specified array contains the specified value, ignoring case. |
|
static boolean |
hasNaN(double[] array)
Returns true if the specified array contains at least one
NaN value. |
|
static boolean |
hasNaN(float[] array)
Returns true if the specified array contains at least one
NaN value. |
|
static boolean[] |
insert(boolean[] src,
int src_pos,
boolean[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static boolean[] |
insert(boolean[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static byte[] |
insert(byte[] src,
int src_pos,
byte[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static byte[] |
insert(byte[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static char[] |
insert(char[] src,
int src_pos,
char[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static char[] |
insert(char[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static double[] |
insert(double[] src,
int src_pos,
double[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static double[] |
insert(double[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static
|
insert(E[] src,
int src_pos,
E[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static
|
insert(E[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static float[] |
insert(float[] src,
int src_pos,
float[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static float[] |
insert(float[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static int[] |
insert(int[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static int[] |
insert(int[] src,
int src_pos,
int[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static long[] |
insert(long[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static long[] |
insert(long[] src,
int src_pos,
long[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static short[] |
insert(short[] array,
int index,
int length)
Inserts spaces into the middle of an array. |
|
static short[] |
insert(short[] src,
int src_pos,
short[] dst,
int dst_pos,
int length)
Inserts a table slice into another table. |
|
static boolean |
intersects(java.lang.Object[] array1,
java.lang.Object[] array2)
Returns true if at least one element in the first array is equals to an element in the second array. |
|
static boolean |
isSorted(byte[] array)
Returns true if all elements in the specified array are in increasing order. |
|
static boolean |
isSorted(char[] array)
Returns true if all elements in the specified array are in increasing order. |
|
static boolean |
isSorted(double[] array)
Returns true if all elements in the specified array are in increasing order. |
|
static boolean |
isSorted(float[] array)
Returns true if all elements in the specified array are in increasing order. |
|
static boolean |
isSorted(int[] array)
Returns true if all elements in the specified array are in increasing order. |
|
static boolean |
isSorted(long[] array)
Returns true if all elements in the specified array are in increasing order. |
|
static boolean |
isSorted(short[] array)
Returns true if all elements in the specified array are in increasing order. |
|
static
|
isSorted(T[] array,
java.util.Comparator<T> comparator)
Returns true if all elements in the specified array are in increasing order. |
|
static boolean |
isStrictlySorted(int[] array)
Returns true if all elements in the specified array are in strictly increasing order. |
|
static boolean[] |
remove(boolean[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static byte[] |
remove(byte[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static char[] |
remove(char[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static double[] |
remove(double[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static
|
remove(E[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static float[] |
remove(float[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static int[] |
remove(int[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static long[] |
remove(long[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static short[] |
remove(short[] array,
int index,
int length)
Removes elements from the middle of an array. |
|
static boolean[] |
resize(boolean[] array,
int length)
Returns an array containing the same elements as the given array but
specified length , truncating or padding with zeros if necessary. |
|
static byte[] |
resize(byte[] array,
int length)
Returns an array containing the same elements as the given array but
specified length , truncating or padding with zeros if necessary. |
|
static char[] |
resize(char[] array,
int length)
Returns an array containing the same elements as the given array but
specified length , truncating or padding with zeros if necessary. |
|
static double[] |
resize(double[] array,
int length)
Returns an array containing the same elements as the given array but
specified length , truncating or padding with zeros if necessary. |
|
static
|
resize(E[] array,
int length)
Returns an array containing the same elements as the given array but with the
specified length , truncating or padding with null if necessary. |
|
static float[] |
resize(float[] array,
int length)
Returns an array containing the same elements as the given array but
specified length , truncating or padding with zeros if necessary. |
|
static int[] |
resize(int[] array,
int length)
Returns an array containing the same elements as the given array but
specified length , truncating or padding with zeros if necessary. |
|
static long[] |
resize(long[] array,
int length)
Returns an array containing the same elements as the given array but
specified length , truncating or padding with zeros if necessary. |
|
static short[] |
resize(short[] array,
int length)
Returns an array containing the same elements as the given array but
specified length , truncating or padding with zeros if necessary. |
|
static java.lang.String |
toString(java.lang.Object array,
java.util.Locale locale)
Returns a string representation of an array of numbers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <E> E[] resize(E[] array, int length)
array
but with the
specified length
, truncating or padding with null
if necessary.
If the given length
is longer than the length of the given array
,
then the returned array will contain all the elements of array
at index
i < array.length
. Elements at index i >=
array.length
are initialized to null
.
If the given length
is shorter than the length of the given array
,
then the returned array will contain only the elements of array
at index
i < length
. Remainding elements are not copied.
If the given length
is equals to the length of the given array
,
then array
is returned unchanged. No copy is performed.
This behavior is what make this method different than Arrays#copyOf
.
E
- The array elements.array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.Arrays#copyOf(Object[],int)
public static double[] resize(double[] array, int length)
array
but
specified length
, truncating or padding with zeros if necessary.
array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.public static float[] resize(float[] array, int length)
array
but
specified length
, truncating or padding with zeros if necessary.
array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.public static long[] resize(long[] array, int length)
array
but
specified length
, truncating or padding with zeros if necessary.
array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.public static int[] resize(int[] array, int length)
array
but
specified length
, truncating or padding with zeros if necessary.
array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.public static short[] resize(short[] array, int length)
array
but
specified length
, truncating or padding with zeros if necessary.
array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.public static byte[] resize(byte[] array, int length)
array
but
specified length
, truncating or padding with zeros if necessary.
array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.public static char[] resize(char[] array, int length)
array
but
specified length
, truncating or padding with zeros if necessary.
array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.public static boolean[] resize(boolean[] array, int length)
array
but
specified length
, truncating or padding with zeros if necessary.
array
- Array to copy.length
- Length of the desired array.
array
if the original
array already have the requested length.public static <E> E[] remove(E[] array, int index, int length)
E
- The type of array elements.array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static double[] remove(double[] array, int index, int length)
array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static float[] remove(float[] array, int index, int length)
array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static long[] remove(long[] array, int index, int length)
array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static int[] remove(int[] array, int index, int length)
array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static short[] remove(short[] array, int index, int length)
array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static byte[] remove(byte[] array, int index, int length)
array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static char[] remove(char[] array, int index, int length)
array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static boolean[] remove(boolean[] array, int index, int length)
array
- Array from which to remove elements.index
- Index of the first element to remove from the given array
.length
- Number of elements to remove.
array
except for the
removed elements, or array
if length
is 0.public static <E> E[] insert(E[] array, int index, int length)
null
.
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static double[] insert(double[] array, int index, int length)
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static float[] insert(float[] array, int index, int length)
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static long[] insert(long[] array, int index, int length)
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static int[] insert(int[] array, int index, int length)
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static short[] insert(short[] array, int index, int length)
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static byte[] insert(byte[] array, int index, int length)
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static char[] insert(char[] array, int index, int length)
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static boolean[] insert(boolean[] array, int index, int length)
false
.
array
- Array in which to insert spaces.index
- Index where the first space should be inserted. All array
elements
having an index equal to or higher than index
will be moved forward.length
- Number of spaces to insert.
array
elements with the additional space
inserted, or array
if length
is 0.public static <E> E[] insert(E[] src, int src_pos, E[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static double[] insert(double[] src, int src_pos, double[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static float[] insert(float[] src, int src_pos, float[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static long[] insert(long[] src, int src_pos, long[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static int[] insert(int[] src, int src_pos, int[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static short[] insert(short[] src, int src_pos, short[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static byte[] insert(byte[] src, int src_pos, byte[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to
insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static char[] insert(char[] src, int src_pos, char[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static boolean[] insert(boolean[] src, int src_pos, boolean[] dst, int dst_pos, int length)
src
table
will be entirely or partially inserted into the dst
table.
src
- Tablea to insert into dst
.src_pos
- Index of the first data item of src
to insert into dst
.dst
- Table in which to insert src
data.dst_pos
- dst
index in which to insert src
data. All elements of
dst
whose index is equal to or greater than dst_pos
will
be moved forward.length
- Number of src
data items to insert.
src
and dst
. This
method can directly return dst
, but never src
. It most
often returns a newly created table.public static <T> boolean isSorted(T[] array, java.util.Comparator<T> comparator)
true
if all elements in the specified array are in increasing order.
This method is usefull in assertions.
public static boolean isSorted(char[] array)
true
if all elements in the specified array are in increasing order.
This method is usefull in assertions.
public static boolean isSorted(byte[] array)
true
if all elements in the specified array are in increasing order.
This method is usefull in assertions.
public static boolean isSorted(short[] array)
true
if all elements in the specified array are in increasing order.
This method is usefull in assertions.
public static boolean isSorted(int[] array)
true
if all elements in the specified array are in increasing order.
This method is usefull in assertions.
public static boolean isSorted(long[] array)
true
if all elements in the specified array are in increasing order.
This method is usefull in assertions.
public static boolean isSorted(float[] array)
true
if all elements in the specified array are in increasing order.
Since NaN
values are unordered, they may appears anywhere in the array; they
will be ignored. This method is usefull in assertions.
public static boolean isSorted(double[] array)
true
if all elements in the specified array are in increasing order.
Since NaN
values are unordered, they may appears anywhere in the array; they
will be ignored. This method is usefull in assertions.
public static boolean isStrictlySorted(int[] array)
true
if all elements in the specified array are in strictly increasing order.
This method is usefull in assertions.
public static boolean allEquals(float[] array, float value)
true
if all values in the specified array are equals to the specified
value, which may be Float.NaN
.
public static boolean allEquals(double[] array, double value)
true
if all values in the specified array are equals to the specified
value, which may be Double.NaN
.
public static boolean hasNaN(float[] array)
true
if the specified array contains at least one
NaN
value.
public static boolean hasNaN(double[] array)
true
if the specified array contains at least one
NaN
value.
public static boolean containsIgnoreCase(java.lang.String[] array, java.lang.String value)
true
if the specified array contains the specified value, ignoring case.
This method should be used only for very small arrays.
array
- The array to search in. May be null
.value
- The value to search.
true
if the array contains the value.public static boolean contains(java.lang.Object[] array, java.lang.Object value)
true
if the specified array contains the specified value. This method
should be used only for very small arrays, or for search to be performed only once,
because it performs a linear search. If more than one search need to be done on the
same array, consider using HashSet
instead.
array
- The array to search in. May be null
and may contains null elements.value
- The value to search. May be null
.
true
if the array contains the value.public static boolean intersects(java.lang.Object[] array1, java.lang.Object[] array2)
true
if at least one element in the first array is equals to an element in the second array. The element doesn't need to be at the same index
in both array.
This method should be used only for very small arrays since it may be very slow. If the
arrays are large or if an array will be involved in more than one search, consider using
HashSet
instead.
public static java.lang.String toString(java.lang.Object array, java.util.Locale locale)
Number
.
array
- The array to format.locale
- The locale for formatting.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |