public final class arrays extends StaticObject
| Modifier and Type | Method and Description |
|---|---|
static boolean |
equals(Seq<?> seq,
Object obj)
Unified method for compare to sequences for equality.
|
static <T,R> void |
foreach(Iterable<? extends T> values,
Function<? super T,? extends R> f)
Deprecated.
Align the naming with the upcoming JDK 1.8 release. Use
forEach(Iterable, Function) instead. |
static <T,R> void |
forEach(Iterable<? extends T> values,
Function<? super T,? extends R> f)
Iterates over all elements of the given
values |
static <T,R> void |
foreach(T[] array,
Function<? super T,? extends R> f)
Deprecated.
Align the naming with the upcomming JDK 1.8 release. Use
forEach(Object[], Function) instead. |
static <T,R> void |
forEach(T[] array,
Function<? super T,? extends R> f)
Iterates over all elements of the given
array as long as the
predicate returns true (which means continue) and
returns the index the iteration has been interrupted. |
static int |
hashCode(Seq<?> seq)
Unified method for calculating the hash code of every
Seq
implementation. |
static int |
indexOf(Object[] array,
int start,
int end,
Object element)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static int |
indexOf(Object[] array,
Object element)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> int |
indexWhere(Iterable<? extends T> values,
Function<? super T,Boolean> predicate)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> int |
indexWhere(T[] array,
Function<? super T,Boolean> predicate)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T extends Object & Comparable<? super T>> |
isSorted(Seq<T> seq)
Test whether the given array is sorted in ascending order.
|
static <T> boolean |
isSorted(Seq<T> seq,
Comparator<? super T> comparator)
Test whether the given array is sorted in ascending order.
|
static <A,B> B[] |
map(A[] a,
B[] b,
Function<? super A,? extends B> converter)
Map the array from type A to an other array of type B.
|
static int[] |
partition(int size,
int parts)
Return a array with the indexes of the partitions of an array with the
given size.
|
static int[] |
permutation(int[] p)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static int[] |
permutation(int[] p,
long rank)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static int[] |
permutation(int[] p,
Random random)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> T[] |
reverse(T[] array)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> T[] |
reverse(T[] array,
int from,
int to)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static void |
shuffle(int[] array)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static void |
shuffle(int[] array,
Random random)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> void |
shuffle(List<T> list)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> void |
shuffle(List<T> list,
Random random)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> MSeq<T> |
shuffle(MSeq<T> array)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> MSeq<T> |
shuffle(MSeq<T> array,
Random random)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> T[] |
shuffle(T[] array)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> T[] |
shuffle(T[] array,
Random random)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T extends Object & Comparable<? super T>> |
sort(MSeq<T> array)
Calls the sort method on the
Arrays class. |
static int[] |
subset(int n,
int k)
Deprecated.
Use
math.subset(int, int) instead. |
static void |
subset(int n,
int[] sub)
Deprecated.
Use
math.subset(int, int[]) instead. |
static int[] |
subset(int n,
int[] sub,
Random random)
Deprecated.
Use
math.subset(int, int[], Random) instead. |
static int[] |
subset(int n,
int k,
Random random)
Deprecated.
Use
math.subset(int, int, Random) instead. |
static void |
swap(byte[] array,
int i,
int j)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static void |
swap(int[] array,
int i,
int j)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> void |
swap(List<T> list,
int i,
int j)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
static <T> void |
swap(T[] array,
int i,
int j)
Deprecated.
Not used in the Jenetics library. Will be removed.
|
public static int hashCode(Seq<?> seq)
Seq
implementation. The hash code is defined as followed:
int hashCode = 1;
final Iterator<E> it = seq.iterator();
while (it.hasNext()) {
final E obj = it.next();
hashCode = 31*hashCode + (obj == null ? 0 : obj.hashCode());
}seq - the sequence to calculate the hash code for.Seq.hashCode(),
List.hashCode()public static boolean equals(Seq<?> seq, Object obj)
seq - the sequence to test for equality.obj - the object to test for equality with the sequence.true if the given objects are sequences and contain the
same objects in the same order, false otherwise.Seq.equals(Object)@Deprecated public static <T> void swap(List<T> list, int i, int j)
T - the list type.list - the arrayi - index of the first list element.j - index of the second list element.IndexOutOfBoundsException - if i < 0 or
j < 0 or i > a.length or
j > a.lengthNullPointerException - if the give list is null.@Deprecated public static <T> void swap(T[] array, int i, int j)
T - the array type.array - the arrayi - index of the first array element.j - index of the second array element.IndexOutOfBoundsException - if i < 0 or
j < 0 or i > a.length or
j > a.lengthNullPointerException - if the give array is null.@Deprecated public static void swap(byte[] array, int i, int j)
array - the arrayi - index of the first array element.j - index of the second array element.IndexOutOfBoundsException - if i < 0 or
j < 0 or i > a.length or
j > a.lengthNullPointerException - if the give array is null.@Deprecated public static void swap(int[] array, int i, int j)
array - the arrayi - index of the first array element.j - index of the second array element.IndexOutOfBoundsException - if i < 0 or
j < 0 or i > a.length or
j > a.lengthNullPointerException - if the give array is null.public static <T extends Object & Comparable<? super T>> MSeq<T> sort(MSeq<T> array)
Arrays class.NullPointerException - if the give array is null.UnsupportedOperationException - if the array is sealed
(array.isSealed() == true).public static <T extends Object & Comparable<? super T>> boolean isSorted(Seq<T> seq)
seq - the array to test.true if the given array is sorted in ascending
order, false otherwise.NullPointerException - if the given array or one of it's element is
null.public static <T> boolean isSorted(Seq<T> seq, Comparator<? super T> comparator)
seq - the array to test.comparator - the comparator which defines the order.true if the given array is sorted in ascending
order, false otherwise.NullPointerException - if the given array or one of it's element or
the comparator is null.@Deprecated public static <T> T[] shuffle(T[] array)
array using the given Random object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).array - the array to randomize.NullPointerException - if the give array is null.@Deprecated public static <T> T[] shuffle(T[] array, Random random)
array using the given Random object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).T - the component type of the array to randomize.array - the array to randomize.random - the Random object to use for randomize.NullPointerException - if the give array or the random object is
null.@Deprecated public static <T> MSeq<T> shuffle(MSeq<T> array)
array using the given Random object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).array - the array to randomize.NullPointerException - if the give array is null.@Deprecated public static <T> MSeq<T> shuffle(MSeq<T> array, Random random)
array using the given Random object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).T - the component type of the array to randomize.array - the array to randomize.random - the Random object to use for randomize.NullPointerException - if the give array or the random object is
null.@Deprecated public static <T> void shuffle(List<T> list)
list using the given Random object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).T - the component type of the array to randomize.list - the array to randomize.NullPointerException - if the give list is null.@Deprecated public static <T> void shuffle(List<T> list, Random random)
list using the given Random object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).T - the component type of the array to randomize.list - the array to randomize.random - the Random object to use for randomize.NullPointerException - if the give list or the random object is
null.@Deprecated public static void shuffle(int[] array)
array using the given Random object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).array - the array to randomize.NullPointerException - if the give array is null.@Deprecated public static void shuffle(int[] array, Random random)
array using the given Random object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).array - the array to randomize.random - the Random object to use for randomize.NullPointerException - if the give array or the random object is
null.@Deprecated public static <T> T[] reverse(T[] array, int from, int to)
T - the array type.array - the array to reversefrom - the first index (inclusive)to - the second index (exclusive)IllegalArgumentException - if from > toIndexOutOfBoundsException - if from < 0 or
to > a.lengthNullPointerException - if the give array is null.@Deprecated public static <T> T[] reverse(T[] array)
T - the array type.array - the array to reverse.NullPointerException - if the give array is null.public static int[] partition(int size, int parts)
min(size, prts) + 1.
Some examples:
partition(10, 3): [0, 3, 6, 10]
partition(15, 6): [0, 2, 4, 6, 9, 12, 15]
partition(5, 10): [0, 1, 2, 3, 4, 5]
The following examples prints the start index (inclusive) and the end
index (exclusive) of the partition(15, 6).
int[] parts = partition(15, 6);
for (int i = 0; i < parts.length - 1; ++i) {
System.out.println(i + ": " + parts[i] + "\t" + parts[i + 1]);
}
0: 0 2
1: 2 4
2: 4 6
3: 6 9
4: 9 12
5: 12 15
This example shows how this can be used in an concurrent environment:
try (final Concurrency c = Concurrency.start()) {
final int[] parts = arrays.partition(population.size(), _maxThreads);
for (int i = 0; i < parts.length - 1; ++i) {
final int part = i;
c.execute(new Runnable() { @Override public void run() {
for (int j = parts[part + 1]; --j >= parts[part];) {
population.get(j).evaluate();
}
}});
}
}size - the size of the array to partition.parts - the number of parts the (virtual) array should be partitioned.min(size, parts) + 1.IllegalArgumentException - if size or p is less than one.@Deprecated public static int[] subset(int n, int k)
math.subset(int, int) instead.k from a set of size n.n - the size of the set.k - the size of the subset.IllegalArgumentException - if n < k, k == 0 or if
n*k will cause an integer overflow.subset(int, int[])@Deprecated public static int[] subset(int n, int k, Random random)
math.subset(int, int, Random) instead.k from a set of size n.n - the size of the set.k - the size of the subset.random - the random number generator used.NullPointerException - if random is null.IllegalArgumentException - if n < k, k == 0 or if
n*k will cause an integer overflow.subset(int, int[], Random)@Deprecated public static void subset(int n, int[] sub)
math.subset(int, int[]) instead.
Selects a random subset of size sub.length from a set of size
n.
Authors: FORTRAN77 original version by Albert Nijenhuis, Herbert Wilf. This version based on the C++ version by John Burkardt.
Reference: Albert Nijenhuis, Herbert Wilf, Combinatorial Algorithms for Computers and Calculators, Second Edition, Academic Press, 1978, ISBN: 0-12-519260-6, LC: QA164.N54.
n - the size of the set.sub - the sub set array.NullPointerException - if sub is null.IllegalArgumentException - if n < sub.length,
sub.length == 0 or n*sub.length will cause an
integer overflow.@Deprecated public static int[] subset(int n, int[] sub, Random random)
math.subset(int, int[], Random) instead.
Selects a random subset of size sub.length from a set of size
n.
Authors: FORTRAN77 original version by Albert Nijenhuis, Herbert Wilf. This version based on the C++ version by John Burkardt.
Reference: Albert Nijenhuis, Herbert Wilf, Combinatorial Algorithms for Computers and Calculators, Second Edition, Academic Press, 1978, ISBN: 0-12-519260-6, LC: QA164.N54.
n - the size of the set.sub - the sub set array.random - the random number generator used.NullPointerException - if sub or random is
null.IllegalArgumentException - if n < sub.length,
sub.length == 0 or n*sub.length will cause an
integer overflow.@Deprecated public static int[] permutation(int[] p)
p - the permutation array.NullPointerException - if the permutation array is null.@Deprecated public static int[] permutation(int[] p, Random random)
p - the permutation array.random - the random number generator.NullPointerException - if the permutation array or the random number
generator is null.@Deprecated public static int[] permutation(int[] p, long rank)
rank.
Authors: FORTRAN77 original version by Albert Nijenhuis, Herbert Wilf. This version based on the C++ version by John Burkardt.
Reference: Albert Nijenhuis, Herbert Wilf, Combinatorial Algorithms for Computers and Calculators, Second Edition, Academic Press, 1978, ISBN: 0-12-519260-6, LC: QA164.N54.
p - the permutation array.rank - the permutation rank.NullPointerException - it the permutation array is null.IllegalArgumentException - if rank < 1.@Deprecated public static int indexOf(Object[] array, int start, int end, Object element)
array, or -1 if the array does not contain the element.array - the array to search.start - the start index of the search.element - the element to search for.array, of -1 if the array does not contain
the element.NullPointerException - if the given array is null.IndexOutOfBoundsException - for an illegal end point index value
(start < 0 || end > length || start > end)@Deprecated public static int indexOf(Object[] array, Object element)
array, or -1 if the array does not contain the element.array - the array to search.element - the element to search for.array, of -1 if the array does not contain
the element.NullPointerException - if the given array is null.@Deprecated public static <T> int indexWhere(T[] array, Function<? super T,Boolean> predicate)
indexOf(Object[], Object)@Deprecated public static <T> int indexWhere(Iterable<? extends T> values, Function<? super T,Boolean> predicate)
indexOf(Object[], Object)@Deprecated public static <T,R> void foreach(T[] array, Function<? super T,? extends R> f)
forEach(Object[], Function) instead.public static <T,R> void forEach(T[] array, Function<? super T,? extends R> f)
array as long as the
predicate returns true (which means continue) and
returns the index the iteration has been interrupted. -1 is returned if
all elements were visited.
Can be used to check all array elements for nullness.
public void foo(final Integer[] values) {
arrays.forEach(values, new Validator.NonNull());
...
}array - the array to iterate.f - the function to apply to every element.NullPointerException - if one of the elements are null.@Deprecated public static <T,R> void foreach(Iterable<? extends T> values, Function<? super T,? extends R> f)
forEach(Iterable, Function) instead.public static <T,R> void forEach(Iterable<? extends T> values, Function<? super T,? extends R> f)
valuesvalues - the values to iterate.f - the function to apply to each element.NullPointerException - if one of the elements are null.public static <A,B> B[] map(A[] a, B[] b, Function<? super A,? extends B> converter)
A - the source type.B - the target type.a - the source array.b - the target array. If the given array is to short a new array
with the right size is created, mapped and returned. If the given
array is long enough this array is returned.converter - the converter needed for mapping from type A to type B.b is long enough b is
returned otherwise a new created array.NullPointerException - if one of the arguments is null.© 2007-2013 Franz Wilhelmstötter (2013-12-18 20:17)