Class Utils

java.lang.Object
convex.core.util.Utils

public class Utils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static byte[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 identical
    static <T extends ACell,​ U>
    T
    binarySearchLeftmost​(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
    bool​(Object a)
     
    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>>
     
    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
    static <T> T[]
    copyOfRangeExcludeNulls​(T[] entries, int offset, int length)
     
    static boolean
    equals​(ACell a, ACell b)
    Equality method allowing for nulls
    static boolean
    equals​(Object a, Object b)
    Equality method allowing for nulls
    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.
    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 match
    static <R,​ T> ArrayList<Future<R>>
    futureMap​(Function<T,​R> func, Collection<T> items)
    Executes functions on a thread pool for each element of a collection
    static Class<?>
    Gets the class of an Object, or null if the value is null
    static String
    Gets the class name of an Object, or "null" if the value is null
    static long
    Gets the current system timestamp.
    static <R extends ACell>
    Ref<R>
    getRef​(ACell o, int i)
     
    static long
    Gets the a millisecond accurate time suitable for use in timing.
    static int
    Gets the Java hashCode of any value.
    static BigInteger
    Converts a hex string to an unsigned big Integer
    static byte[]
    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 boolean
    isOdd​(long x)
     
    static <T> List<T>
    listOf​(T... values)
     
    static String
    print​(Object v)
    Prints an Object in readable String representation.
    static void
    Prints an Object in readable String representation to a Java StringBuilder
    static AArrayBlob
    Reads data from the Byte Buffer buffer, up to the limit.
    static byte[]
    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 representation
    static 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
    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 representation
    static BigInteger
    Reads an unsigned BigInteger as 32 bytes from a ByteBuffer
    static 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 place
    static <T> void
    reverse​(T[] arr, int n)
    Reverse the first n elements of an array in place
    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
    static <T extends Throwable>
    T
    Hack 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
    stateAsOf​(AVector<State> states, CVMLong timestamp)
     
    static AVector<State>
    statesAsOfRange​(AVector<State> states, CVMLong timestamp, long interval, int count)
     
    static String
    Removes all spaces from a String
    static boolean
    timeout​(int timeoutMillis, Supplier<Boolean> test)
    Runs test repeatedly, until it returns true or the timeout has elapsed
    static 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 encoding
    static byte[]
    Reads ByteBuffer contents into a new byte array
    static ACell[]
    toCellArray​(Object anyArray)
    Converts any array to an ACell[] array.
    static AArrayBlob
    Reads ByteBuffer contents into a new Data object
    static 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 character
    static String
    toHexString​(byte value)
    Converts a byte to a two-character hex string
    static String
    toHexString​(byte[] data)
    Converts a byte array of length N to a hex string of length 2N
    static String
    toHexString​(byte[] data, int offset, int length)
    Converts a slice of a byte array to a hex string of length 2N
    static 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 string
    static 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.
    Converts a Object to an InetSocketAddress
    Converts a String to an InetSocketAddress
    Converts a URL to an InetSocketAddress.
    static int
    toInt​(Object v)
    Converts an object to an int value, handling Strings and arbitrary numbers.
    static Object[]
    toObjectArray​(Object anyArray)
    Converts any array to an Object[] array
    static 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 long
    Counts the total number of Refs contained in a data object recursively.
    static <T extends ACell>
    T
    updateRefs​(T o, IRefFunction func)
     
    static int
    writeChar​(byte[] data, int offset, char value)
    Writes an char to a byte array in 2 byte big-endian representation
    static int
    writeInt​(byte[] data, int offset, int value)
    Writes an int to a byte array in 4 byte big-endian representation
    static 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 representation
    static 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
    Writes an unsigned BigInteger as 32 bytes into a ByteBuffer

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY_BYTES

      public static final byte[] EMPTY_BYTES
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • toBigInteger

      public static BigInteger toBigInteger(byte[] data)
      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

      public static 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[]);
      Parameters:
      data - Byte array to convert to BigInteger
      Returns:
      A signed BigInteger
    • toHexString

      public static String toHexString(int val)
      Converts an int to a hex string e.g. "80cafe80"
      Parameters:
      val - Value to convert
      Returns:
      Lowercase hex string
    • toHexString

      public static String toHexString(short val)
    • toHexString

      public static String toHexString(byte value)
      Converts a byte to a two-character hex string
      Parameters:
      value - Value to convert
      Returns:
      Lowercase hex string
    • appendHexByte

      public static void appendHexByte(BlobBuilder bb, byte b)
    • toHexString

      public static String toHexString(long x)
      Converts a long value to a 16 character hex string
      Parameters:
      x - Value to convert
      Returns:
      Hex string for the given long
    • toFriendlyHexString

      public static String toFriendlyHexString(String hexString, int size)
      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 representation
      offset - 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 representation
      offset - 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 representation
      offset - 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 array
      data - Byte array into which to write the given int
      offset - 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 array
      data - Byte array into which to write the given int
      offset - 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 array
      data - Byte array into which to write the given int
      offset - 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 array
      data - Byte array into which to write the given long
      offset - 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

      public static byte[] toByteArray(ByteBuffer bb)
      Reads ByteBuffer contents into a new byte array
      Parameters:
      bb - ByteBuffer
      Returns:
      New byte array
    • toData

      public static AArrayBlob toData(ByteBuffer bb)
      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

      public static byte[] hexToBytes(String hex)
      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

      public static byte[] hexToBytes(String hex, int stringLength)
      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 digits
      stringLength - number of hex digits in the string to use
      Returns:
      byte array with the given hex value, or null if not valud
    • hexToBigInt

      public static BigInteger hexToBigInt(String hex)
      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

      public static String toHexString(byte[] data)
      Converts a byte array of length N to a hex string of length 2N
      Parameters:
      data - Array of bytes
      Returns:
      Hex String
    • toHexString

      public static String toHexString(byte[] data, int offset, int length)
      Converts a slice of a byte array to a hex string of length 2N
      Parameters:
      data - Array of bytes
      offset - Start offset to read from byte array
      length - Length in bytes to read from byte array
      Returns:
      Hex String
    • hashCode

      public static int hashCode(Object a)
      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 array
      aOffset - Offset into first array
      b - Second array
      bOffset - Offset into second array
      length - 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 array
      aOffset - Offset into first array
      b - Second array
      bOffset - Offset into second array
      length - 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

      public 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.
      Parameters:
      a - Value to convert
      digits - Number of hex digits to produce
      Returns:
      String containing the hex representation
    • writeUInt

      public static void writeUInt(BigInteger a, byte[] dest, int offset, int length)
      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 write
      dest - Destination array
      offset - Offset into destination array
      length - Length to write
    • toByteArray

      public static byte[] toByteArray(String s)
      Converts a String to a byte array using UTF-8 encoding
      Parameters:
      s - Any String
      Returns:
      Byte array
    • toObjectArray

      public static Object[] toObjectArray(Object anyArray)
      Converts any array to an Object[] array
      Parameters:
      anyArray - Array to convert
      Returns:
      Object[] array
    • toCellArray

      public static ACell[] toCellArray(Object anyArray)
      Converts any array to an ACell[] array. Elements must be Cells.
      Parameters:
      anyArray - Array to convert
      Returns:
      ACell[] array
    • equals

      public static boolean equals(Object a, Object b)
      Equality method allowing for nulls
      Parameters:
      a - First value
      b - Second value
      Returns:
      true if arguments are equal, false otherwise
    • equals

      public static boolean equals(ACell a, ACell b)
      Equality method allowing for nulls
      Parameters:
      a - First value
      b - Second value
      Returns:
      true if arguments are equal, false otherwise
    • getClass

      public static Class<?> getClass(Object o)
      Gets the class of an Object, or null if the value is null
      Parameters:
      o - Object to examine
      Returns:
      Class of the Object
    • getClassName

      public static String getClassName(Object o)
      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

      public static ByteBuffer writeUInt256(ByteBuffer b, BigInteger v)
      Writes an unsigned BigInteger as 32 bytes into a ByteBuffer
      Parameters:
      b - A ByteBuffer with at least 32 bytes capacity
      v - A BigInteger in the unsigned 256 bit integer range
      Returns:
      The ByteBuffer with 32 bytes written
    • readUInt256

      public static BigInteger readUInt256(ByteBuffer b)
      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
    • toInt

      public static int toInt(Object v)
      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

      public static String readResourceAsString(String path) throws IOException
      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
    • 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 array
      numBits - 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 array
      numBits - Number of bits to set (0-32)
      shift - Number of bits to shift (from LSB position)
      bits - Bits to set
    • readBufferData

      public static AArrayBlob readBufferData(ByteBuffer bb)
      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

      public static String print(Object v)
      Prints an Object in readable String representation. Maybe not efficient.
      Parameters:
      v - Object to print
      Returns:
      String representation of value
    • print

      public static void print(StringBuilder sb, Object v)
      Prints an Object in readable String representation to a Java StringBuilder
      Parameters:
      sb - StringBuilder to append to
      v - Object to print
    • toInetSocketAddress

      public static InetSocketAddress toInetSocketAddress(Object o)
      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

      public static InetSocketAddress toInetSocketAddress(String s)
      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

      public static InetSocketAddress toInetSocketAddress(URL url)
      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

      public static <T> T[] filterArray(T[] arr, Predicate<T> predicate)
      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 filter
      predicate - Predicate to test array elements
      Returns:
      Filtered array.
    • sortListBy

      public 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. Ignores elements where score is null (will not be included in the resulting list)
      Parameters:
      scorer - a Function mapping collection elements to Long values
      coll - 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 elements
      subset - Array of element subset (must be identical)
      Returns:
      Bit mask as a short
    • sneakyThrow

      public static <T extends Throwable> T sneakyThrow(Throwable t) throws T
      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 reverse
      n - Number of elements to reverse
    • readBytes

      public static byte[] readBytes(InputStream is) throws IOException
      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

      public static String toString(Object o)
      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

      public static String stripWhiteSpace(String s)
      Removes all spaces from a String
      Parameters:
      s - String to strip
      Returns:
      String without spaces
    • refCount

      public static int refCount(ACell a)
      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.
    • totalRefCount

      public static long totalRefCount(Object a)
      Counts the total number of Refs contained in a data object recursively. Will count duplicate children multiple times.
      Parameters:
      a - Object to count Refs in
      Returns:
      Total number of Refs found
    • getRef

      public static <R extends ACell> Ref<R> getRef(ACell o, int i)
    • updateRefs

      public static <T extends ACell> T updateRefs(T o, IRefFunction func)
    • bitCount

      public static int bitCount(short mask)
    • timeout

      public static boolean timeout(int timeoutMillis, Supplier<Boolean> test)
      Runs test repeatedly, until it returns true or the timeout has elapsed
      Parameters:
      timeoutMillis - Timeout interval
      test - 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 the 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 value
      b - 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.
    • completeAll

      public static <T> CompletableFuture<List<T>> completeAll(List<CompletableFuture<T>> futures)
    • stateAsOf

      public static State stateAsOf(AVector<State> states, CVMLong timestamp)
    • statesAsOfRange

      public static AVector<State> statesAsOfRange(AVector<State> states, CVMLong timestamp, long interval, int count)
    • bool

      public static boolean bool(Object a)
    • listOf

      @SafeVarargs public static <T> List<T> listOf(T... values)
    • futureMap

      public static <R,​ T> ArrayList<Future<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 function
      T - Argument type
      Parameters:
      func - Function to run
      items - Collection of items to run futures on
      Returns:
      List of futures for each item