AnyLogic AnyLogic
Expand
Font size
  • 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

Method Summary

All Methods Static Methods Concrete Methods 
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 .equals() 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 .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
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

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail

min

public static int min​(int[] array)
Returns the minimum value from the given array.
Throws error if passed array is null or empty.
Parameters:
array - the array to scan
Returns:
the minimum value from the array

min

public 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.
Parameters:
array - the array to scan
Returns:
the minimum value from the array

max

public static int max​(int[] array)
Returns the maximum value from the given array.
Throws error if passed array is null or empty.
Parameters:
array - the array to scan
Returns:
the maximum value from the array

max

public 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.
Parameters:
array - the array to scan
Returns:
the maximum value from the array

indexOfMin

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 -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

indexOfMin

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 -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

indexOfMax

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 -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

indexOfMax

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 -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

indexOf

public 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.
Parameters:
array - the array to scan
value - the value to search for
Returns:
the index of the value in the array, starting from 0

indexOf

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 -1 if no matching value is found or if passed array is null or empty.
Parameters:
array - the array to scan
test - the text expression, e.g. v -> v > 10
Returns:
the index of the value in the array, starting from 0
Since:
8.4

indexOf

public 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.
Parameters:
array - the array to scan
value - the value to search for
Returns:
the index of the value in the array, starting from 0

indexOf

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 -1 if no matching value is found or if passed array is null or empty.
Parameters:
array - the array to scan
test - the text expression, e.g. v -> v > 10
Returns:
the index of the value in the array, starting from 0
Since:
8.4

indexOf

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 .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 scan
object - the object to search for, may be null - in this case the method will try to find the index of null in the given array.
Returns:
the index of the object in the array, starting from 0

indexOf

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 -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 scan
test - the text expression, special behavior: if null is passed instead of predicate, the method will try to find the index of null in the given array, to be conforming with indexOf(Object[], Object)
Returns:
the index of the matching object in the array, starting from 0
Since:
8.4

arrayContains

public 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
Parameters:
array - the array to scan
value - the value to search for
Returns:
true if the array contains value, false otherwise

arrayContains

public 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
Parameters:
array - the array to scan
value - the value to search for
Returns:
true if the array contains value, false otherwise

arrayContains

public static boolean arrayContains​(java.lang.Object[] array,
                                    java.lang.Object object)
Returns 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 scan
object - the object to search for
Returns:
true if the array contains object, false otherwise

concatenateArrays

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 a followed by all other elements (b)
Parameters:
a - array 1
b - collection of elements to be added to the resulting array
Returns:
new array with elements from a followed by elements from b
Since:
7.2

concatenateArrays

@SafeVarargs
public 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)
Parameters:
a - array 1
b - array 2 or comma-separated elements
Returns:
new array with elements from a followed by elements from b

concatenateArrays

@SafeVarargs
public 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)
Parameters:
a - array 1
b - array 2 or comma-separated elements
Returns:
new array with elements from a followed by elements from b
Since:
8.0

toArray

@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 element
b - array 2 or comma-separated elements
Returns:
new array with a followed by elements from b
How can we improve this article?