Package convex.core.util
Class Utils
java.lang.Object
convex.core.util.Utils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendHexByte
(BlobBuilder bb, byte b) static boolean
arrayEquals
(byte[] a, int aOffset, byte[] b, int bOffset, int length) Tests if two byte array regions are identicalstatic <R> void
awaitAll
(Collection<CompletableFuture<R>> cfutures) static <T extends ACell,
U>
longbinarySearch
(ASequence<T> L, Function<T, U> value, Comparator<U> comparator, U target) Binary Search for an exact or approximate (leftmost) value.static <T extends ACell,
U>
TbinarySearchLeftmost
(ASequence<T> L, Function<T, U> value, Comparator<U> comparator, U target) Leftmost Binary Search.static int
bitCount
(short mask) static int
bitLength
(long x) Returns the minimal number of bits to represent the signed twos complement long value.static boolean
static int
byteLength
(long x) Returns the minimal number of bytes to represent the signed twos complement long value.static byte
checkedByte
(long a) Converts a long to a byte, throws error if out of allowable range.static int
checkedInt
(long a) Converts a long to an int, throws error if out of allowable range.static short
checkedShort
(long a) Converts a long to a short, throws error if out of allowable range.static int
compareByteArrays
(byte[] a, int aOffset, byte[] b, int bOffset, int length) Compares two byte arrays on an unsigned basis.static <T> CompletableFuture<List<T>>
completeAll
(List<CompletableFuture<T>> futures) static <T> short
computeMask
(T[] set, T[] subset) Computes a bit mask of up to 16 bits by scanning a full array for which elements are included in the subset, comparing using object identity Subset must be an ordered subset of of the full arraystatic <T> T[]
copyOfRangeExcludeNulls
(T[] entries, int offset, int length) static boolean
Equality method allowing for nullsstatic boolean
Equality method allowing for nullsstatic int
extractBits
(byte[] bs, int numBits, int shift) Extract a number of bits (up to 32) from a big-endian byte array, shifting right by the specified amount.static <T> T[]
filterArray
(T[] arr, Predicate<T> predicate) Filters the array, returning an array containing only the elements where the predicate returns true.static <T> T[]
filterSmallArray
(T[] arr, int mask) static boolean
firstDigitMatch
(byte a, byte b) Test if the first hex digits of two bytes matchstatic <R,
T> ArrayList<CompletableFuture<R>> futureMap
(Function<T, R> func, Collection<T> items) Executes functions on a thread pool for each element of a collectionstatic Class<?>
Gets the class of an Object, or null if the value is nullstatic String
Gets the class name of an Object, or "null" if the value is nullstatic long
Gets the current system timestamp.static long
Gets a millisecond accurate time suitable for use in timing.static int
Gets the Java hashCode of any value.static BigInteger
hexToBigInt
(String hex) Converts a hex string to an unsigned big Integerstatic byte[]
hexToBytes
(String hex) Converts a hex string to a byte array.static byte[]
hexToBytes
(String hex, int stringLength) Converts a hex string to a byte array.static int
hexVal
(char c) Gets the value of a single hex car e.g.static <K> void
histogramAdd
(HashMap<K, Integer> hm, K value) static boolean
isOdd
(long x) static String
joinStrings
(List<String> strings, String separator) static <T> List<T>
listOf
(T... values) static long
memoryAdd
(long a, long b) static Long
Parses a value as a Longstatic String
Prints an Object in readable String representation.static void
print
(StringBuilder sb, Object v) Prints an Object in readable String representation to a Java StringBuilderstatic AArrayBlob
Reads data from the Byte Buffer buffer, up to the limit.static byte[]
readBytes
(InputStream is) Reads the full contents of an input stream into a new byte array.static int
readInt
(byte[] data, int offset) Reads an int from a specified location in a byte array Assumes 4-byte big-endian representationstatic int
readIntZeroExtend
(byte[] data, int offset) Reads an int from a specified location in a byte array.static long
readLong
(byte[] data, int offset) static String
readResourceAsString
(String path) Gets a resource as a String.static short
readShort
(byte[] data, int offset) Reads a short from a specified location in a byte array Assumes 2-byte big-endian representationstatic String
readString
(InputStream inputStream) Reads an InputStream as a String.static BigInteger
Reads an unsigned BigInteger as 32 bytes from a ByteBufferstatic int
Gets the number of Refs directly contained in a Cell (will be zero if the Cell is not a Ref container)static <T> void
reverse
(T[] arr) Reverse an array in placestatic <T> void
reverse
(T[] arr, int n) Reverse the first n elements of an array in placestatic void
setBits
(byte[] bs, int numBits, int shift, int bits) Sets a number of bits (up to 32) in a big-endian byte array, shifting by the specified amount Ignores bits set outside the byte arraystatic <T> void
static <T> void
static <T extends Throwable>
THack to convert a checked exception into an unchecked exception.static <T> ArrayList<T>
sortListBy
(Function<T, Long> scorer, Collection<T> coll) Return a list of values, sorted according to the score computed using the provided function, in ascending order.static State
statesAsOfRange
(AVector<State> states, CVMLong timestamp, long interval, int count) static String
Removes all spaces from a Stringstatic <R,
T> ArrayList<CompletableFuture<R>> threadMap
(Function<T, R> func, Collection<T> items) Executes functions on a new thread for each element of a collectionstatic boolean
Runs test repeatedly, until it returns true or the timeout has elapsedstatic BigInteger
toBigInteger
(byte[] data) Converts an array of bytes into an unsigned BigInteger Assumes big-endian format as per new BigInteger(int, byte[]);static byte[]
Converts a String to a byte array using UTF-8 encodingstatic byte[]
Reads ByteBuffer contents into a new byte arraystatic ACell[]
toCellArray
(Object anyArray) Converts any array to an ACell[] array.static AArrayBlob
toData
(ByteBuffer bb) Reads ByteBuffer contents into a new Data objectstatic String
toFriendlyHexString
(String hexString, int size) Converts a hex string to a friendly version ( first x chars).static char
toHexChar
(int i) Converts an int value in the range 0..15 to a hexadecimal characterstatic String
toHexString
(byte value) Converts a byte to a two-character hex stringstatic String
toHexString
(byte[] data) Converts a byte array of length N to a hex string of length 2Nstatic String
toHexString
(byte[] data, int offset, int length) Converts a slice of a byte array to a hex string of length 2Nstatic String
toHexString
(int val) Converts an int to a hex string e.g.static String
toHexString
(long x) Converts a long value to a 16 character hex stringstatic String
toHexString
(short val) static String
toHexString
(BigInteger a, int digits) Converts an unsigned BigInteger to a hex string with the given number of digits Truncates any high bytes beyond the given digits.static InetSocketAddress
Converts a Object to an InetSocketAddressstatic InetSocketAddress
Converts a String to an InetSocketAddressstatic InetSocketAddress
toInetSocketAddress
(URL url) Converts a URL to an InetSocketAddress.static int
Converts an object to an int value, handling Strings and arbitrary numbers.static Object[]
toObjectArray
(Object anyArray) Converts any array to an Object[] arraystatic BigInteger
toSignedBigInteger
(byte[] data) Converts an array of bytes into a signed BigInteger Assumes two's-complement big-endian binary representation format as per new BigInteger(byte[]);static String
Displays a String representing the given Object, printing null as "nil" SECURITY: should *not* be used in Actor code, use RT.str(...) instead.static byte[]
trimBigIntegerLeadingBytes
(byte[] bs) Trims unnecessary leading bytes from a BigInteger representation.static int
writeChar
(byte[] data, int offset, char value) Writes an char to a byte array in 2 byte big-endian representationstatic int
writeInt
(byte[] data, int offset, int value) Writes an int to a byte array in 4 byte big-endian representationstatic int
writeLong
(byte[] data, int offset, long value) Writes a long to a byte array in 8 byte big-endian representation.static int
writeShort
(byte[] data, int offset, short value) Writes an char to a byte array in 2 byte big-endian representationstatic void
writeUInt
(BigInteger a, byte[] dest, int offset, int length) Writes an unsigned big integer to a specific segment of a byte[] array.static ByteBuffer
writeUInt256
(ByteBuffer b, BigInteger v) Writes an unsigned BigInteger as 32 bytes into a ByteBuffer
-
Field Details
-
EMPTY_BYTES
public static final byte[] EMPTY_BYTES -
EMPTY_OBJECTS
-
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
toBigInteger
Converts an array of bytes into an unsigned BigInteger Assumes big-endian format as per new BigInteger(int, byte[]);- Parameters:
data
- Array of bytes containing an unsigned integer (big-endian)- Returns:
- A new non-negative BigInteger
-
toSignedBigInteger
Converts an array of bytes into a signed BigInteger Assumes two's-complement big-endian binary representation format as per new BigInteger(byte[]);- Parameters:
data
- Byte array to convert to BigInteger- Returns:
- A signed BigInteger
-
toHexString
Converts an int to a hex string e.g. "80cafe80"- Parameters:
val
- Value to convert- Returns:
- Lowercase hex string
-
toHexString
-
toHexString
Converts a byte to a two-character hex string- Parameters:
value
- Value to convert- Returns:
- Lowercase hex string
-
appendHexByte
-
toHexString
Converts a long value to a 16 character hex string- Parameters:
x
- Value to convert- Returns:
- Hex string for the given long
-
toFriendlyHexString
Converts a hex string to a friendly version ( first x chars). SECURITY; do not use this output for any comparison.- Parameters:
hexString
- String to show in friendly format.size
- Number of hex chars to output.- Returns:
- Hex String
-
readInt
public static int readInt(byte[] data, int offset) Reads an int from a specified location in a byte array Assumes 4-byte big-endian representation- Parameters:
data
- Byte array from which to read the 4-byte int representationoffset
- Offset into byte array to read- Returns:
- int value from array
-
readIntZeroExtend
public static int readIntZeroExtend(byte[] data, int offset) Reads an int from a specified location in a byte array. Assumes 4-byte big-endian representation. Assumes zeros beyong end of array- Parameters:
data
- Byte array from which to read the 4-byte int representationoffset
- Offset into byte array to read- Returns:
- int value from array
-
readLong
public static long readLong(byte[] data, int offset) -
readShort
public static short readShort(byte[] data, int offset) Reads a short from a specified location in a byte array Assumes 2-byte big-endian representation- Parameters:
data
- Byte array from which to read the 2-byte short representationoffset
- Offset into byte array to read- Returns:
- short value from array
-
writeChar
public static int writeChar(byte[] data, int offset, char value) Writes an char to a byte array in 2 byte big-endian representation- Parameters:
value
- int value to write to the arraydata
- Byte array into which to write the given intoffset
- Offset into the array at which the int will be written- Returns:
- Offset after writing
-
writeShort
public static int writeShort(byte[] data, int offset, short value) Writes an char to a byte array in 2 byte big-endian representation- Parameters:
value
- int value to write to the arraydata
- Byte array into which to write the given intoffset
- Offset into the array at which the int will be written- Returns:
- Offset after writing
-
writeInt
public static int writeInt(byte[] data, int offset, int value) Writes an int to a byte array in 4 byte big-endian representation- Parameters:
value
- int value to write to the arraydata
- Byte array into which to write the given intoffset
- Offset into the array at which the int will be written- Returns:
- Offset after writing
-
writeLong
public static int writeLong(byte[] data, int offset, long value) Writes a long to a byte array in 8 byte big-endian representation.- Parameters:
value
- long value to write to the arraydata
- Byte array into which to write the given longoffset
- Offset into the array at which the long will be written- Returns:
- Offset after writing 8 bytes
- Throws:
IndexOutOfBoundsException
- If long reaches outside the destination byte array
-
toByteArray
Reads ByteBuffer contents into a new byte array- Parameters:
bb
- ByteBuffer- Returns:
- New byte array
-
toData
Reads ByteBuffer contents into a new Data object- Parameters:
bb
- ByteBuffer- Returns:
- Blob extracted from ByteBuffer
-
toHexChar
public static char toHexChar(int i) Converts an int value in the range 0..15 to a hexadecimal character- Parameters:
i
- Value to convert- Returns:
- Hex digit value (lowercase)
-
hexToBytes
Converts a hex string to a byte array. Must contain an even number of hex digits, or else null will be returned- Parameters:
hex
- String containing Hex digits- Returns:
- byte array with the given hex value, or null if string is not valid
-
hexToBytes
Converts a hex string to a byte array. Must contain an the expected number of hex digits, or else null will be returned- Parameters:
hex
- String containing Hex digitsstringLength
- number of hex digits in the string to use- Returns:
- byte array with the given hex value, or null if not valud
-
hexToBigInt
Converts a hex string to an unsigned big Integer- Parameters:
hex
- Value to convert- Returns:
- BigInteger
-
hexVal
public static int hexVal(char c) Gets the value of a single hex car e.g. hexVal('c') => 12- Parameters:
c
- Character representing a hex digit- Returns:
- int in the range 0..15 inclusive, or -1 if not a hex char
-
toHexString
Converts a byte array of length N to a hex string of length 2N- Parameters:
data
- Array of bytes- Returns:
- Hex String
-
toHexString
Converts a slice of a byte array to a hex string of length 2N- Parameters:
data
- Array of bytesoffset
- Start offset to read from byte arraylength
- Length in bytes to read from byte array- Returns:
- Hex String
-
hashCode
Gets the Java hashCode of any value. The hashCode of null is defined as zero- Parameters:
a
- Any Java Object, may be null- Returns:
- hash code
-
arrayEquals
public static boolean arrayEquals(byte[] a, int aOffset, byte[] b, int bOffset, int length) Tests if two byte array regions are identical- Parameters:
a
- First arrayaOffset
- Offset into first arrayb
- Second arraybOffset
- Offset into second arraylength
- Number of bytes to compare- Returns:
- true if array regions are equal, false otherwise
-
compareByteArrays
public static int compareByteArrays(byte[] a, int aOffset, byte[] b, int bOffset, int length) Compares two byte arrays on an unsigned basis. Shorter arrays will be considered "smaller" if they match in all other positions.- Parameters:
a
- First arrayaOffset
- Offset into first arrayb
- Second arraybOffset
- Offset into second arraylength
- The maximum size for comparison. If arrays are equal up to this length, will return 0- Returns:
- Negative if a is 'smaller', 0 if a 'equals' b, positive if a is 'larger'.
-
toHexString
Converts an unsigned BigInteger to a hex string with the given number of digits Truncates any high bytes beyond the given digits.- Parameters:
a
- Value to convertdigits
- Number of hex digits to produce- Returns:
- String containing the hex representation
-
writeUInt
Writes an unsigned big integer to a specific segment of a byte[] array. Pads with zeros if necessary to fill the specified length.- Parameters:
a
- Value to writedest
- Destination arrayoffset
- Offset into destination arraylength
- Length to write
-
toByteArray
Converts a String to a byte array using UTF-8 encoding- Parameters:
s
- Any String- Returns:
- Byte array
-
toObjectArray
Converts any array to an Object[] array- Parameters:
anyArray
- Array to convert- Returns:
- Object[] array
-
toCellArray
Converts any array to an ACell[] array. Elements must be Cells.- Parameters:
anyArray
- Array to convert- Returns:
- ACell[] array
-
equals
Equality method allowing for nulls- Parameters:
a
- First valueb
- Second value- Returns:
- true if arguments are equal, false otherwise
-
equals
Equality method allowing for nulls- Parameters:
a
- First valueb
- Second value- Returns:
- true if arguments are equal, false otherwise
-
getClass
Gets the class of an Object, or null if the value is null- Parameters:
o
- Object to examine- Returns:
- Class of the Object
-
getClassName
Gets the class name of an Object, or "null" if the value is null- Parameters:
o
- Object to examine- Returns:
- Class name of the Object
-
checkedInt
public static int checkedInt(long a) Converts a long to an int, throws error if out of allowable range.- Parameters:
a
- Long value to convert- Returns:
- Value of the long if in valid Integer range
-
checkedShort
public static short checkedShort(long a) Converts a long to a short, throws error if out of allowable range.- Parameters:
a
- Value to convert- Returns:
- short value of the long if in valid Short range
- Throws:
IllegalArgumentException
- if out of legal range
-
checkedByte
public static byte checkedByte(long a) Converts a long to a byte, throws error if out of allowable range.- Parameters:
a
- Value to convert- Returns:
- byte value of the long if in valid Byte range
- Throws:
IllegalArgumentException
- if out of legal range
-
writeUInt256
Writes an unsigned BigInteger as 32 bytes into a ByteBuffer- Parameters:
b
- A ByteBuffer with at least 32 bytes capacityv
- A BigInteger in the unsigned 256 bit integer range- Returns:
- The ByteBuffer with 32 bytes written
-
readUInt256
Reads an unsigned BigInteger as 32 bytes from a ByteBuffer- Parameters:
b
- ByteBuffer from which to extract 32 bytes- Returns:
- A non-negative BigInteger containing the unsigned big-endian value from the 32 bytes read
-
bitLength
public static int bitLength(long x) Returns the minimal number of bits to represent the signed twos complement long value. Return value will be at least 1, max 64- Parameters:
x
- Long value- Returns:
- Number of bits required for representation, in the range 1..64 inclusive
-
byteLength
public static int byteLength(long x) Returns the minimal number of bytes to represent the signed twos complement long value. Return value will be at 1-8- Parameters:
x
- Long value- Returns:
- Number of bytes required for representation, in the range 1-8 inclusive
-
toInt
Converts an object to an int value, handling Strings and arbitrary numbers.- Parameters:
v
- An object representing a valid int value- Returns:
- The converted int value of the object
- Throws:
IllegalArgumentException
- If the argument cannot be converted to an int
-
readResourceAsString
Gets a resource as a String.- Parameters:
path
- Path to resource, e.g "actors/token.con"- Returns:
- String content of resource file
- Throws:
IOException
- If an IO error occurs
-
readString
Reads an InputStream as a String.- Parameters:
inputStream
- Stream of data to read as UTF-8 string- Returns:
- String content of stream, or null on failure
-
extractBits
public static int extractBits(byte[] bs, int numBits, int shift) Extract a number of bits (up to 32) from a big-endian byte array, shifting right by the specified amount. Sign extends for bits beyond range of array.- Parameters:
bs
- Source byte arraynumBits
- Number of bits to extract (0-32)shift
- Number of bits to shift- Returns:
- Bits returned
-
setBits
public static void setBits(byte[] bs, int numBits, int shift, int bits) Sets a number of bits (up to 32) in a big-endian byte array, shifting by the specified amount Ignores bits set outside the byte array- Parameters:
bs
- Target byte arraynumBits
- Number of bits to set (0-32)shift
- Number of bits to shift (from LSB position)bits
- Bits to set
-
readBufferData
Reads data from the Byte Buffer buffer, up to the limit.- Parameters:
bb
- ByteBuffer to read from- Returns:
- Blob containing bytes read from buffer
-
print
Prints an Object in readable String representation. Maybe not efficient.- Parameters:
v
- Object to print- Returns:
- String representation of value
-
print
Prints an Object in readable String representation to a Java StringBuilder- Parameters:
sb
- StringBuilder to append tov
- Object to print
-
toInetSocketAddress
Converts a Object to an InetSocketAddress- Parameters:
o
- An Object to convert to a socket address. May be a String or existing InetSocketAddress- Returns:
- A valid InetSocketAddress, or null if not in valid format
-
toInetSocketAddress
Converts a String to an InetSocketAddress- Parameters:
s
- A string in the format of a valid URL or "myhost.com:17888"- Returns:
- A valid InetSocketAddress, or null if not in valid format
-
toInetSocketAddress
Converts a URL to an InetSocketAddress. Will assume default port if not specified.- Parameters:
url
- A valid URL- Returns:
- A valid InetSocketAddress for the URL
-
filterArray
Filters the array, returning an array containing only the elements where the predicate returns true. May return the same array if all elements are included.- Parameters:
arr
- Array to filterpredicate
- Predicate to test array elements- Returns:
- Filtered array.
-
sortListBy
Return a list of values, sorted according to the score computed using the provided function, in ascending order. Ignores elements where score is null (will not be included in the resulting list)- Parameters:
scorer
- a Function mapping collection elements to Long valuescoll
- Collection of values to compare- Returns:
- The sorted collection values as an ArrayList, in ascending score order.
-
filterSmallArray
public static <T> T[] filterSmallArray(T[] arr, int mask) -
computeMask
public static <T> short computeMask(T[] set, T[] subset) Computes a bit mask of up to 16 bits by scanning a full array for which elements are included in the subset, comparing using object identity Subset must be an ordered subset of of the full array- Parameters:
set
- Array of elementssubset
- Array of element subset (must be identical)- Returns:
- Bit mask as a short
-
sneakyThrow
Hack to convert a checked exception into an unchecked exception.- Type Parameters:
T
- Type of exception to return- Parameters:
t
- Any Throwable instance- Returns:
- Throwable instance
- Throws:
T
- In all cases
-
copyOfRangeExcludeNulls
public static <T> T[] copyOfRangeExcludeNulls(T[] entries, int offset, int length) -
reverse
public static <T> void reverse(T[] arr) Reverse an array in place- Parameters:
arr
- Array to reverse
-
reverse
public static <T> void reverse(T[] arr, int n) Reverse the first n elements of an array in place- Parameters:
arr
- Array to reversen
- Number of elements to reverse
-
readBytes
Reads the full contents of an input stream into a new byte array.- Parameters:
is
- An arbitrary InputStream- Returns:
- A byte array containing the full contents of the given InputStream
- Throws:
IOException
- If IO error occurs
-
isOdd
public static boolean isOdd(long x) -
toString
Displays a String representing the given Object, printing null as "nil" SECURITY: should *not* be used in Actor code, use RT.str(...) instead.- Parameters:
o
- Object to convert- Returns:
- String representation of object
-
stripWhiteSpace
Removes all spaces from a String- Parameters:
s
- String to strip- Returns:
- String without spaces
-
refCount
Gets the number of Refs directly contained in a Cell (will be zero if the Cell is not a Ref container)- Parameters:
a
- Cell to check (may be null)- Returns:
- Number of Refs in the object.
-
getRef
-
bitCount
public static int bitCount(short mask) -
timeout
Runs test repeatedly, until it returns true or the timeout has elapsed- Parameters:
timeoutMillis
- Timeout intervaltest
- Test to run until true- Returns:
- True if the operation timed out, false otherwise
-
getCurrentTimestamp
public static long getCurrentTimestamp()Gets the current system timestamp. Guaranteed monotonic within this JVM. Should be used for timestamps that need to be persisted or communicated Should not be used for timing - use Utils.getTimeMillis() instead- Returns:
- Long representation of Timestamp
-
getTimeMillis
public static long getTimeMillis()Gets a millisecond accurate time suitable for use in timing. Should not be used for timestamps- Returns:
- long
-
firstDigitMatch
public static boolean firstDigitMatch(byte a, byte b) Test if the first hex digits of two bytes match- Parameters:
a
- Any byte valueb
- Any byte value- Returns:
- true if the first hex digit (high nibble) of the two bytes is equal, false otherwise.
-
binarySearchLeftmost
public static <T extends ACell,U> T binarySearchLeftmost(ASequence<T> L, Function<T, U> value, Comparator<U> comparator, U target) Leftmost Binary Search. Generic method to search for an exact or approximate (leftmost) value. Examples: Given a vector [1, 2, 3] and target 2: returns 2. Given a vector [1, 2, 3] and target 5: returns 3. Given a vector [1, 2, 3] and target 0: returns null.- Type Parameters:
T
- Type of the elements in L.U
- Type of the target value.- Parameters:
L
- Items.value
- Function to get the value for comparison with target.comparator
- How to compare value with target.target
- Value being searched for.- Returns:
- Target, or leftmost value, or null if there isn't a match.
-
binarySearch
public static <T extends ACell,U> long binarySearch(ASequence<T> L, Function<T, U> value, Comparator<U> comparator, U target) Binary Search for an exact or approximate (leftmost) value. Returns the position where the target value would be inserted if in order Examples: Given a vector [1, 2, 3] and target 2: returns 1 (index of exact match 2) Given a vector [1, 2, 3] and target 5: returns 3 (end index) Given a vector [1, 2, 3] and target 0: returns 0 (start index).- Type Parameters:
T
- Type of the elements in L.U
- Type of the target value.- Parameters:
L
- Items.value
- Function to get the value for comparison with target.comparator
- How to compare value with target.target
- Value being searched for.- Returns:
- Position of target in sequence.
-
completeAll
-
stateAsOf
-
statesAsOfRange
-
bool
-
listOf
-
futureMap
public static <R,T> ArrayList<CompletableFuture<R>> futureMap(Function<T, R> func, Collection<T> items) Executes functions on a thread pool for each element of a collection- Type Parameters:
R
- Result type of functionT
- Argument type- Parameters:
func
- Function to runitems
- Collection of items to run futures on- Returns:
- List of futures for each item
-
threadMap
public static <R,T> ArrayList<CompletableFuture<R>> threadMap(Function<T, R> func, Collection<T> items) Executes functions on a new thread for each element of a collection- Type Parameters:
R
- Result type of functionT
- Argument type- Parameters:
func
- Function to runitems
- Collection of items to run futures on- Returns:
- List of futures for each item
-
awaitAll
public static <R> void awaitAll(Collection<CompletableFuture<R>> cfutures) throws InterruptedException, ExecutionException -
trimBigIntegerLeadingBytes
public static byte[] trimBigIntegerLeadingBytes(byte[] bs) Trims unnecessary leading bytes from a BigInteger representation.- Parameters:
bs
- Big endian twos complement representation of Big Integer- Returns:
- trimmed bytes (may be same array)
-
memoryAdd
public static long memoryAdd(long a, long b) -
histogramAdd
-
shuffle
-
shuffle
-
parseLong
Parses a value as a Long- Parameters:
o
- A numeric value or String containing a number- Returns:
- Long value, or null if not parseable
-
joinStrings
-