Package com.anylogic.engine
- java.lang.Object
-
- com.anylogic.engine.UtilitiesArray
public final class UtilitiesArray
extends java.lang.Object
This class provides a lot of commonly used functions for operations with arrays
- Author:
- AnyLogic North America, LLC https://anylogic.com
static boolean |
arrayContains(double[] array,
double value) |
Returns
true if the array contains the given value.The result is the same as from expression: indexOf( array, value ) >= 0 |
static boolean |
arrayContains(int[] array,
int value) |
Returns
true if the array contains the given value.The result is the same as from expression: indexOf( array, value ) >= 0 |
static boolean |
arrayContains(java.lang.Object[] array,
java.lang.Object object) |
Returns
true if the array contains the given object.Objects are compared using method.Arrays of any object type are supported, e.g.: |
static <T> T[] |
concatenateArrays(T[] a,
java.util.Collection<? extends T> b) |
Concatenates specified array with elements from the given collection.
Result is new array with contents of a followed
by all other elements (b ) |
static <T> T[] |
concatenateArrays(T[] a,
T... b) |
Concatenates specified array with the given elements.
Result is new array with contents of a followed
by all other elements (b ) |
static <T> T[] |
concatenateArrays(T[] a,
T[]... b) |
Concatenates specified array with the given elements.
Result is new array with contents of a followed
by all other elements (b ) |
static int |
indexOf(double[] array,
double value) |
Returns the index of the first occurrence of the given value in the array.
Returns -1 if value not found or if passed array is null or empty. |
static int |
indexOf(double[] array,
java.util.function.DoublePredicate test) |
Returns the index of the first occurrence of the matching value in the array.
Returns -1 if no matching value is found or if passed array is null or empty. |
static int |
indexOf(int[] array,
int value) |
Returns the index of the first occurrence of the given value in the array.
Returns -1 if value not found or if passed array is null or empty. |
static int |
indexOf(int[] array,
java.util.function.IntPredicate test) |
Returns the index of the first occurrence of the matching value in the array.
Returns -1 if no matching value is found or if passed array is null or empty. |
static int |
indexOf(java.lang.Object[] array,
java.lang.Object object) |
Returns the index of the first occurrence of the given object in the array.
Objects are compared using method.Returns -1 if value not found or if passed array is null or empty.Arrays of any object type are supported, e.g.: |
static <T> int |
indexOf(T[] array,
java.util.function.Predicate<? super T> test) |
Returns the index of the first occurrence of the matching object in the array.
Returns -1 if value not found or if passed array is null or empty.Arrays of any object type are supported, e.g.: |
static int |
indexOfMax(double[] array) |
Returns the index of the maximum value from the given array.
|
static int |
indexOfMax(int[] array) |
Returns the index of the maximum value from the given array.
|
static int |
indexOfMin(double[] array) |
Returns the index of the minimum value from the given array.
|
static int |
indexOfMin(int[] array) |
Returns the index of the minimum value from the given array.
|
static double |
max(double[] array) |
Returns the maximum value from the given array.
Returns Double.NaN if array contains only Double.NaN values.Throws error if passed array is null or empty. |
static int |
max(int[] array) |
Returns the maximum value from the given array.
Throws error if passed array is null or empty. |
static double |
min(double[] array) |
Returns the minimum value from the given array.
Returns Double.NaN if array contains only Double.NaN values.Throws error if passed array is null or empty. |
static int |
min(int[] array) |
Returns the minimum value from the given array.
Throws error if passed array is null or empty. |
static <T> T[] |
toArray(T e,
T... b) |
Creates array using concatenation of the specified element with given array/elements.
|
Modifier and Type | Method | Description |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static int min(int[] array)
Returns the minimum value from the given array.
Throws error if passed
Throws error if passed
array
is null
or empty.- Parameters:
array
- the array to scan- Returns:
- the minimum value from the
array
public static double min(double[] array)
Returns the minimum value from the given array.
Returns
Throws error if passed
Returns
Double.NaN
if array contains only Double.NaN
values.Throws error if passed
array
is null
or empty.- Parameters:
array
- the array to scan- Returns:
- the minimum value from the
array
public static int max(int[] array)
Returns the maximum value from the given array.
Throws error if passed
Throws error if passed
array
is null
or empty.- Parameters:
array
- the array to scan- Returns:
- the maximum value from the
array
public static double max(double[] array)
Returns the maximum value from the given array.
Returns
Throws error if passed
Returns
Double.NaN
if array contains only Double.NaN
values.Throws error if passed
array
is null
or empty.- Parameters:
array
- the array to scan- Returns:
- the maximum value from the
array
public static int indexOfMin(int[] array)
Returns the index of the minimum value from the given array.
If there are several such values, returns the smallest index.
Returns
Returns
-1
if passed array
is null
or empty.- Parameters:
array
- the array to scan- Returns:
- the index of the minimum value from the
array
, starting from 0
public static int indexOfMin(double[] array)
Returns the index of the minimum value from the given array.
If there are several such values, returns the smallest index.
Returns
Returns
-1
if passed array
is null
or empty or contains only NaN
values.- Parameters:
array
- the array to scan- Returns:
- the index of the minimum value from the
array
, starting from 0
public static int indexOfMax(int[] array)
Returns the index of the maximum value from the given array.
If there are several such values, returns the smallest index.
Returns
Returns
-1
if passed array
is null
or empty.- Parameters:
array
- the array to scan- Returns:
- the index of the maximum value from the
array
, starting from 0
public static int indexOfMax(double[] array)
Returns the index of the maximum value from the given array.
If there are several such values, returns the smallest index.
Returns
Returns
-1
if passed array
is null
or empty or contains only NaN
values.- Parameters:
array
- the array to scan- Returns:
- the index of the maximum value from the
array
, starting from 0
public static int indexOf(int[] array, int value)
Returns the index of the first occurrence of the given value in the array.
Returns
Returns
-1
if value not found or if passed array
is null
or empty.- Parameters:
array
- the array to scanvalue
- the value to search for- Returns:
- the index of the value in the
array
, starting from 0
public static int indexOf(int[] array, java.util.function.IntPredicate test)
Returns the index of the first occurrence of the matching value in the array.
Returns
Returns
-1
if no matching value is found or if passed array
is null
or empty.- Parameters:
array
- the array to scantest
- the text expression, e.g.v -> v > 10
- Returns:
- the index of the value in the
array
, starting from 0 - Since:
- 8.4
public static int indexOf(double[] array, double value)
Returns the index of the first occurrence of the given value in the array.
Returns
Returns
-1
if value not found or if passed array
is null
or empty.- Parameters:
array
- the array to scanvalue
- the value to search for- Returns:
- the index of the value in the
array
, starting from 0
public static int indexOf(double[] array, java.util.function.DoublePredicate test)
Returns the index of the first occurrence of the matching value in the array.
Returns
Returns
-1
if no matching value is found or if passed array
is null
or empty.- Parameters:
array
- the array to scantest
- the text expression, e.g.v -> v > 10
- Returns:
- the index of the value in the
array
, starting from 0 - Since:
- 8.4
public static int indexOf(java.lang.Object[] array, java.lang.Object object)
Returns the index of the first occurrence of the given object in the array.
Objects are compared using
Returns
Arrays of any object type are supported, e.g.:
Objects are compared using
.equals()
method.Returns
-1
if value not found or if passed array
is null
or empty.Arrays of any object type are supported, e.g.:
String[] s = new String[]{ "a", "b", "c" }; traceln( indexOf( s, "b" ) ); // will print out '1'
- Parameters:
array
- the array to scanobject
- the object to search for, may benull
- in this case the method will try to find the index ofnull
in the given array.- Returns:
- the index of the object in the
array
, starting from 0
public static <T> int indexOf(T[] array, java.util.function.Predicate<? super T> test)
Returns the index of the first occurrence of the matching object in the array.
Returns
Arrays of any object type are supported, e.g.:
Returns
-1
if value not found or if passed array
is null
or empty.Arrays of any object type are supported, e.g.:
String[] s = new String[]{ "a", "ab", "abc" }; traceln( indexOf( s, s -> s.length() > 1 ) ); // will print out '1'
- Parameters:
array
- the array to scantest
- the text expression, special behavior: ifnull
is passed instead of predicate, the method will try to find the index ofnull
in the given array, to be conforming withindexOf(Object[], Object)
- Returns:
- the index of the matching object in the
array
, starting from 0 - Since:
- 8.4
public static boolean arrayContains(int[] array, int value)
Returns
The result is the same as from expression:
true
if the array contains the given value.The result is the same as from expression:
indexOf( array, value ) >= 0
- Parameters:
array
- the array to scanvalue
- the value to search for- Returns:
true
if thearray
containsvalue
,false
otherwise
public static boolean arrayContains(double[] array, double value)
Returns
The result is the same as from expression:
true
if the array contains the given value.The result is the same as from expression:
indexOf( array, value ) >= 0
- Parameters:
array
- the array to scanvalue
- the value to search for- Returns:
true
if thearray
containsvalue
,false
otherwise
public static boolean arrayContains(java.lang.Object[] array, java.lang.Object object)
Returns
Objects are compared using
Arrays of any object type are supported, e.g.:
The result is the same as from expression:
true
if the array contains the given object.Objects are compared using
.equals()
method.Arrays of any object type are supported, e.g.:
String[] s = new String[]{ "a", "b", "c" }; traceln( contains( s, "b" ) ); // will print out 'true'
The result is the same as from expression:
indexOf( array, object ) >= 0
- Parameters:
array
- the array to scanobject
- the object to search for- Returns:
true
if thearray
containsobject
,false
otherwise
public static <T> T[] concatenateArrays(T[] a, java.util.Collection<? extends T> b)
Concatenates specified array with elements from the given collection.
Result is new array with contents of
Result is new array with contents of
a
followed
by all other elements (b
)- Parameters:
a
- array 1b
- collection of elements to be added to the resulting array- Returns:
- new array with elements from
a
followed by elements fromb
- Since:
- 7.2
@SafeVarargs public static <T> T[] concatenateArrays(T[] a, T... b)
Concatenates specified array with the given elements.
Result is new array with contents of
Result is new array with contents of
a
followed
by all other elements (b
)- Parameters:
a
- array 1b
- array 2 or comma-separated elements- Returns:
- new array with elements from
a
followed by elements fromb
@SafeVarargs public static <T> T[] concatenateArrays(T[] a, T[]... b)
Concatenates specified array with the given elements.
Result is new array with contents of
Result is new array with contents of
a
followed
by all other elements (b
)- Parameters:
a
- array 1b
- array 2 or comma-separated elements- Returns:
- new array with elements from
a
followed by elements fromb
- Since:
- 8.0
@SafeVarargs public static <T> T[] toArray(T e, T... b)
Creates array using concatenation of the specified element with given array/elements.
Result is new array with
a
followed
by all other elements (b
)- Parameters:
e
- the first elementb
- array 2 or comma-separated elements- Returns:
- new array with
a
followed by elements fromb
-
How can we improve this article?
-