Skip to content

JavaUtils ​

com.jsmacrosce.jsmacros.api.library.FJavaUtils

Since1.8.4

Creates Java collections and provides array-string and raw-object helper conversions.

js
// Equal seeds and equal calls produce equal sequences.  
const random = JavaUtils.getRandom(1234);  
Chat.log(`first roll was ${random.nextInt(100)}`);

Accessible in scripts via the global JavaUtils variable.

Methods ​

arrayDeepToString ​

arrayDeepToString(Object[] array): StringSince1.8.4#
Returns the string representation of an array, recursively formatting nested arrays.

Parameters:

  • array: the array to convert
Returns: the array's recursively formatted string representation

arrayToString ​

arrayToString(Object[] array): StringSince1.8.4#
Returns the string representation of an array; nested arrays are represented as objects rather than recursively formatted.

Parameters:

  • array: the array to convert
Returns: the array's string representation

createArrayList ​

createArrayList(): ArrayList<?>Since1.8.4#
Creates an empty ArrayList.
Returns: an empty list.
createArrayList(T[] array): ArrayList<T>Since1.8.4#
Copies the elements of a Java array into a new ArrayList.

Parameters:

  • array: the Java array to copy

Type Parameters:

  • T: the type of the array
Returns: a new list containing the array elements

createHashMap ​

createHashMap(): HashMap<?, ?>Since1.8.4#
Creates an empty HashMap.
Returns: an empty map.

createHashSet ​

createHashSet(): HashSet<?>Since1.8.4#
Creates an empty HashSet.
Returns: an empty set.

getHelperFromRaw ​

getHelperFromRaw(Object raw): ObjectSince1.8.4#
Wraps raw with a registered helper for its runtime type, or returns null if no helper is registered. raw must be non-null.

Parameters:

  • raw: the non-null object to wrap
Returns: its registered helper, or null if none is registered

getRandom ​

getRandom(): SplittableRandomSince1.8.4#
Returns a SplittableRandom initialized with a nondeterministic seed.
Returns: a random number generator
getRandom(long seed): SplittableRandomSince1.8.4#
Returns a SplittableRandom initialized with seed; equal seeds and equal sequences of calls produce equal results.
// Equal seeds and equal calls produce equal sequences.
const first = JavaUtils.getRandom(1234);
const second = JavaUtils.getRandom(1234);
print(`${first.nextInt(100)}, ${first.nextInt(100)}, ${first.nextInt(100)}`);
print(`${second.nextInt(100)}, ${second.nextInt(100)}, ${second.nextInt(100)}`);

Parameters:

  • seed: the seed
Returns: a seeded random number generator