Class Util

java.lang.Object
org.apache.datasketches.Util

public final class Util
extends Object
Common utility functions.
Author:
Lee Rhodes
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int DEFAULT_NOMINAL_ENTRIES
    The default nominal entries is provided as a convenience for those cases where the nominal sketch size in number of entries is not provided.
    static long DEFAULT_UPDATE_SEED
    The seed 9001 used in the sketch update methods is a prime number that was chosen very early on in experimental testing.
    static double iGolden
    The inverse golden ratio as a fraction.
    static long iGoldenU64
    The inverse golden ratio as an unsigned long.
    static double LOG2
    The natural logarithm of 2.0.
    static double LONG_MAX_VALUE_AS_DOUBLE
    Long.MAX_VALUE as a double.
    static String LS
    The java line separator character as a String.
    static int MAX_LG_NOM_LONGS
    The largest Log2 nom entries allowed: 26.
    static int MIN_LG_ARR_LONGS
    The smallest Log2 cache size allowed: 5.
    static int MIN_LG_NOM_LONGS
    The smallest Log2 nom entries allowed: 4.
    static double REBUILD_THRESHOLD
    The hash table rebuild threshold = 15.0/16.0.
    static double RESIZE_THRESHOLD
    The resize threshold = 0.5; tuned for speed.
    static char TAB
    The tab character
  • Method Summary

    Modifier and Type Method Description
    static int bytesToInt​(byte[] arr)
    Returns an int extracted from a Little-Endian byte array.
    static long bytesToLong​(byte[] arr)
    Returns a long extracted from a Little-Endian byte array.
    static String bytesToString​(byte[] arr, boolean signed, boolean littleEndian, String sep)
    Returns a string view of a byte array
    static int ceilingPowerOf2​(int n)
    Computes the ceiling power of 2 within the range [1, 2^30].
    static double ceilingPowerOfBdouble​(double b, double n)
    Computes the ceiling power of B as a double.
    static String characterPad​(String s, int fieldLength, char padChar, boolean postpend)
    Prepend or postpend the given string with the given character to fill the given field length.
    static void checkBounds​(long reqOff, long reqLen, long allocSize)
    Check the requested offset and length against the allocated size.
    static void checkIfMultipleOf8AndGT0​(long v, String argName)
    Checks if parameter v is a multiple of 8 and greater than zero.
    static void checkIfPowerOf2​(int v, String argName)
    Checks the given parameter to make sure it is positive, an integer-power of 2 and greater than zero.
    static int checkNomLongs​(int nomLongs)
    Checks that the given nomLongs is within bounds and returns the Log2 of the ceiling power of 2 of the given nomLongs.
    static void checkProbability​(double p, String argName)
    Checks the given parameter to make sure it is positive and between 0.0 inclusive and 1.0 inclusive.
    static short checkSeedHashes​(short seedHashA, short seedHashB)
    Check if the two seed hashes are equal.
    static short computeSeedHash​(long seed)
    Computes and checks the 16-bit seed hash from the given long seed.
    static double[] evenlyLogSpaced​(double value1, double value2, int num)
    Returns a double array of values between min and max inclusive where the log of the returned values are evenly spaced.
    static double[] evenlySpaced​(double value1, double value2, int num)
    Returns a double array of evenly spaced values between value1 and value2 inclusive.
    static float[] evenlySpacedFloats​(float value1, float value2, int num)
    Returns a float array of evenly spaced values between value1 and value2 inclusive.
    static int floorPowerOf2​(int n)
    Computes the floor power of 2 given n is in therange [1, 2^31-1].
    static long floorPowerOf2​(long n)
    Computes the floor power of 2 given n is in the range [1, 2^63-1].
    static double floorPowerOfBdouble​(double b, double n)
    Computes the floor power of B as a double.
    static byte[] getResourceBytes​(String shortFileName)
    Returns a byte array of the contents of the file defined by the given resource file's shortFileName.
    static File getResourceFile​(String shortFileName)
    Gets the file defined by the given resource file's shortFileName.
    static String getResourcePath​(String shortFileName)
    Gets the absolute path of the given resource file's shortName.
    static byte[] intToBytes​(int v, byte[] arr)
    Returns a Little-Endian byte array extracted from the given int.
    static double invPow2​(int e)
    Computes the inverse integer power of 2: 1/(2^e) = 2^(-e).
    static boolean isLessThanUnsigned​(long n1, long n2)
    Unsigned compare with longs.
    static boolean isMultipleOf8AndGT0​(long v)
    Returns true if v is a multiple of 8 and greater than zero
    static boolean isPowerOf2​(int v)
    Returns true if argument is exactly a positive power of 2 and greater than zero.
    static double log2​(double value)
    The log base 2 of the value
    static double logB​(double logBase, double x)
    Returns the logarithm_logBase of x.
    static byte[] longToBytes​(long v, byte[] arr)
    Returns a Little-Endian byte array extracted from the given long.
    static String longToHexBytes​(long v)
    Returns a string of spaced hex bytes in Big-Endian order.
    static String milliSecToString​(long mS)
    Returns the given time in milliseconds formatted as Hours:Min:Sec.mSec
    static String nanoSecToString​(long nS)
    Returns the given time in nanoseconds formatted as Sec.mSec uSec nSec
    static int numberOfLeadingOnes​(long v)
    Returns the number of one bits preceding the highest-order ("leftmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.
    static int numberOfTrailingOnes​(long v)
    Returns the number of one bits following the lowest-order ("rightmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.
    static int pwr2LawNext​(int ppo, int curPoint)
    Computes the next larger integer point in the power series point = 2( i / ppo ) given the current point in the series.
    static int pwr2LawPrev​(int ppo, int curPoint)
    Computes the previous, smaller integer point in the power series point = 2( i / ppo ) given the current point in the series.
    static double pwrLawNextDouble​(int ppo, double curPoint, boolean roundToInt, double logBase)
    Computes the next larger double in the power series point = logBase( i / ppo ) given the current point in the series.
    static int simpleLog2OfLong​(long x)
    Gives the log2 of a long that is known to be a power of 2.
    static int startingSubMultiple​(int lgTarget, int lgRF, int lgMin)
    Gets the smallest allowed exponent of 2 that it is a sub-multiple of the target by zero, one or more resize factors.
    static int toLog2​(int value, String argName)
    Checks the given value if it is a power of 2.
    static void validateValues​(float[] values)
    Checks the sequential validity of the given array of float values.
    static String zeroPad​(String s, int fieldLength)
    Prepend the given string with zeros.

    Methods inherited from class java.lang.Object

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

    • MIN_LG_ARR_LONGS

      public static final int MIN_LG_ARR_LONGS
      The smallest Log2 cache size allowed: 5.
      See Also:
      Constant Field Values
    • MIN_LG_NOM_LONGS

      public static final int MIN_LG_NOM_LONGS
      The smallest Log2 nom entries allowed: 4.
      See Also:
      Constant Field Values
    • MAX_LG_NOM_LONGS

      public static final int MAX_LG_NOM_LONGS
      The largest Log2 nom entries allowed: 26.
      See Also:
      Constant Field Values
    • REBUILD_THRESHOLD

      public static final double REBUILD_THRESHOLD
      The hash table rebuild threshold = 15.0/16.0.
      See Also:
      Constant Field Values
    • RESIZE_THRESHOLD

      public static final double RESIZE_THRESHOLD
      The resize threshold = 0.5; tuned for speed.
      See Also:
      Constant Field Values
    • DEFAULT_NOMINAL_ENTRIES

      public static final int DEFAULT_NOMINAL_ENTRIES
      The default nominal entries is provided as a convenience for those cases where the nominal sketch size in number of entries is not provided. A sketch of 4096 entries has a Relative Standard Error (RSE) of +/- 1.56% at a confidence of 68%; or equivalently, a Relative Error of +/- 3.1% at a confidence of 95.4%. See Default Nominal Entries
      See Also:
      Constant Field Values
    • DEFAULT_UPDATE_SEED

      public static final long DEFAULT_UPDATE_SEED
      The seed 9001 used in the sketch update methods is a prime number that was chosen very early on in experimental testing. Choosing a seed is somewhat arbitrary, and the author cannot prove that this particular seed is somehow superior to other seeds. There was some early Internet discussion that a seed of 0 did not produce as clean avalanche diagrams as non-zero seeds, but this may have been more related to the MurmurHash2 release, which did have some issues. As far as the author can determine, MurmurHash3 does not have these problems.

      In order to perform set operations on two sketches it is critical that the same hash function and seed are identical for both sketches, otherwise the assumed 1:1 relationship between the original source key value and the hashed bit string would be violated. Once you have developed a history of stored sketches you are stuck with it.

      WARNING: This seed is used internally by library sketches in different packages and thus must be declared public. However, this seed value must not be used by library users with the MurmurHash3 function. It should be viewed as existing for exclusive, private use by the library.

      See Default Update Seed

      See Also:
      Constant Field Values
    • LS

      public static final String LS
      The java line separator character as a String.
    • TAB

      public static final char TAB
      The tab character
      See Also:
      Constant Field Values
    • LOG2

      public static final double LOG2
      The natural logarithm of 2.0.
    • iGoldenU64

      public static final long iGoldenU64
      The inverse golden ratio as an unsigned long.
      See Also:
      Constant Field Values
    • iGolden

      public static final double iGolden
      The inverse golden ratio as a fraction. This has more precision than using the formula: (Math.sqrt(5.0) - 1.0) / 2.0.
      See Also:
      Constant Field Values
    • LONG_MAX_VALUE_AS_DOUBLE

      public static final double LONG_MAX_VALUE_AS_DOUBLE
      Long.MAX_VALUE as a double.
      See Also:
      Constant Field Values
  • Method Details

    • bytesToInt

      public static int bytesToInt​(byte[] arr)
      Returns an int extracted from a Little-Endian byte array.
      Parameters:
      arr - the given byte array
      Returns:
      an int extracted from a Little-Endian byte array.
    • bytesToLong

      public static long bytesToLong​(byte[] arr)
      Returns a long extracted from a Little-Endian byte array.
      Parameters:
      arr - the given byte array
      Returns:
      a long extracted from a Little-Endian byte array.
    • intToBytes

      public static byte[] intToBytes​(int v, byte[] arr)
      Returns a Little-Endian byte array extracted from the given int.
      Parameters:
      v - the given int
      arr - a given array of 4 bytes that will be returned with the data
      Returns:
      a Little-Endian byte array extracted from the given int.
    • longToBytes

      public static byte[] longToBytes​(long v, byte[] arr)
      Returns a Little-Endian byte array extracted from the given long.
      Parameters:
      v - the given long
      arr - a given array of 8 bytes that will be returned with the data
      Returns:
      a Little-Endian byte array extracted from the given long.
    • longToHexBytes

      public static String longToHexBytes​(long v)
      Returns a string of spaced hex bytes in Big-Endian order.
      Parameters:
      v - the given long
      Returns:
      string of spaced hex bytes in Big-Endian order.
    • bytesToString

      public static String bytesToString​(byte[] arr, boolean signed, boolean littleEndian, String sep)
      Returns a string view of a byte array
      Parameters:
      arr - the given byte array
      signed - set true if you want the byte values signed.
      littleEndian - set true if you want Little-Endian order
      sep - the separator string between bytes
      Returns:
      a string view of a byte array
    • nanoSecToString

      public static String nanoSecToString​(long nS)
      Returns the given time in nanoseconds formatted as Sec.mSec uSec nSec
      Parameters:
      nS - the given nanoseconds
      Returns:
      the given time in nanoseconds formatted as Sec.mSec uSec nSec
    • milliSecToString

      public static String milliSecToString​(long mS)
      Returns the given time in milliseconds formatted as Hours:Min:Sec.mSec
      Parameters:
      mS - the given nanoseconds
      Returns:
      the given time in milliseconds formatted as Hours:Min:Sec.mSec
    • zeroPad

      public static String zeroPad​(String s, int fieldLength)
      Prepend the given string with zeros. If the given string is equal or greater than the given field length, it will be returned without modification.
      Parameters:
      s - the given string
      fieldLength - desired total field length including the given string
      Returns:
      the given string prepended with zeros.
    • characterPad

      public static String characterPad​(String s, int fieldLength, char padChar, boolean postpend)
      Prepend or postpend the given string with the given character to fill the given field length. If the given string is equal or greater than the given field length, it will be returned without modification.
      Parameters:
      s - the given string
      fieldLength - the desired field length
      padChar - the desired pad character
      postpend - if true append the pacCharacters to the end of the string.
      Returns:
      prepended or postpended given string with the given character to fill the given field length.
    • checkSeedHashes

      public static short checkSeedHashes​(short seedHashA, short seedHashB)
      Check if the two seed hashes are equal. If not, throw an SketchesArgumentException.
      Parameters:
      seedHashA - the seedHash A
      seedHashB - the seedHash B
      Returns:
      seedHashA if they are equal
    • computeSeedHash

      public static short computeSeedHash​(long seed)
      Computes and checks the 16-bit seed hash from the given long seed. The seed hash may not be zero in order to maintain compatibility with older serialized versions that did not have this concept.
      Parameters:
      seed - See Update Hash Seed
      Returns:
      the seed hash.
    • checkIfMultipleOf8AndGT0

      public static void checkIfMultipleOf8AndGT0​(long v, String argName)
      Checks if parameter v is a multiple of 8 and greater than zero.
      Parameters:
      v - The parameter to check
      argName - This name will be part of the error message if the check fails.
    • isMultipleOf8AndGT0

      public static boolean isMultipleOf8AndGT0​(long v)
      Returns true if v is a multiple of 8 and greater than zero
      Parameters:
      v - The parameter to check
      Returns:
      true if v is a multiple of 8 and greater than zero
    • numberOfTrailingOnes

      public static int numberOfTrailingOnes​(long v)
      Returns the number of one bits following the lowest-order ("rightmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.
      Parameters:
      v - the value whose number of trailing ones is to be computed.
      Returns:
      the number of one bits following the lowest-order ("rightmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.
    • numberOfLeadingOnes

      public static int numberOfLeadingOnes​(long v)
      Returns the number of one bits preceding the highest-order ("leftmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.
      Parameters:
      v - the value whose number of leading ones is to be computed.
      Returns:
      the number of one bits preceding the lowest-order ("rightmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.
    • isPowerOf2

      public static boolean isPowerOf2​(int v)
      Returns true if argument is exactly a positive power of 2 and greater than zero.
      Parameters:
      v - The input argument.
      Returns:
      true if argument is exactly a positive power of 2 and greater than zero.
    • checkIfPowerOf2

      public static void checkIfPowerOf2​(int v, String argName)
      Checks the given parameter to make sure it is positive, an integer-power of 2 and greater than zero.
      Parameters:
      v - The input argument.
      argName - Used in the thrown exception.
    • toLog2

      public static int toLog2​(int value, String argName)
      Checks the given value if it is a power of 2. If not, it throws an exception. Otherwise, returns the log-base2 of the given value.
      Parameters:
      value - must be a power of 2 and greater than zero.
      argName - the argument name used in the exception if thrown.
      Returns:
      the log-base2 of the given value
    • ceilingPowerOf2

      public static int ceilingPowerOf2​(int n)
      Computes the ceiling power of 2 within the range [1, 2^30]. This is the smallest positive power of 2 that equal to or greater than the given n and equal to a mathematical integer.

      For:

      • n ≤ 1: returns 1
      • 2^30 ≤ n ≤ 2^31 -1 : returns 2^30
      • n == a power of 2 : returns n
      • otherwise returns the smallest power of 2 greater than n and equal to a mathematical integer
      Parameters:
      n - The input argument.
      Returns:
      the ceiling power of 2.
    • evenlySpaced

      public static double[] evenlySpaced​(double value1, double value2, int num)
      Returns a double array of evenly spaced values between value1 and value2 inclusive. If value2 > value1, the resulting sequence will be increasing. If value2 < value1, the resulting sequence will be decreasing.
      Parameters:
      value1 - will be in index 0 of the returned array
      value2 - will be in the highest index of the returned array
      num - the total number of values including value1 and value2. Must be 2 or greater.
      Returns:
      a double array of evenly spaced values between value1 and value2 inclusive.
    • evenlySpacedFloats

      public static float[] evenlySpacedFloats​(float value1, float value2, int num)
      Returns a float array of evenly spaced values between value1 and value2 inclusive. If value2 > value1, the resulting sequence will be increasing. If value2 < value1, the resulting sequence will be decreasing.
      Parameters:
      value1 - will be in index 0 of the returned array
      value2 - will be in the highest index of the returned array
      num - the total number of values including value1 and value2. Must be 2 or greater.
      Returns:
      a float array of evenly spaced values between value1 and value2 inclusive.
    • evenlyLogSpaced

      public static double[] evenlyLogSpaced​(double value1, double value2, int num)
      Returns a double array of values between min and max inclusive where the log of the returned values are evenly spaced. If value2 > value1, the resulting sequence will be increasing. If value2 < value1, the resulting sequence will be decreasing.
      Parameters:
      value1 - will be in index 0 of the returned array, and must be greater than zero.
      value2 - will be in the highest index of the returned array, and must be greater than zero.
      num - the total number of values including value1 and value2. Must be 2 or greater
      Returns:
      a double array of exponentially spaced values between value1 and value2 inclusive.
    • floorPowerOf2

      public static int floorPowerOf2​(int n)
      Computes the floor power of 2 given n is in therange [1, 2^31-1]. This is the largest positive power of 2 that equal to or less than the given n and equal to a mathematical integer.

      For:

      • n ≤ 1: returns 1
      • 2^30 ≤ n ≤ 2^31 -1 : returns 2^30
      • n == a power of 2 : returns n
      • otherwise returns the largest power of 2 less than n and equal to a mathematical integer.
      Parameters:
      n - The given int argument.
      Returns:
      the floor power of 2 as an int.
    • floorPowerOf2

      public static long floorPowerOf2​(long n)
      Computes the floor power of 2 given n is in the range [1, 2^63-1]. This is the largest positive power of 2 that is equal to or less than the given n and equal to a mathematical integer.

      For:

      • n ≤ 1: returns 1
      • 2^62 ≤ n ≤ 2^63 -1 : returns 2^62
      • n == a power of 2 : returns n
      • otherwise returns the largest power of 2 less than n and equal to a mathematical integer.
      Parameters:
      n - The given long argument.
      Returns:
      the floor power of 2 as a long
    • invPow2

      public static double invPow2​(int e)
      Computes the inverse integer power of 2: 1/(2^e) = 2^(-e).
      Parameters:
      e - a positive value between 0 and 1023 inclusive
      Returns:
      the inverse integer power of 2: 1/(2^e) = 2^(-e)
    • pwr2LawNext

      public static int pwr2LawNext​(int ppo, int curPoint)
      Computes the next larger integer point in the power series point = 2( i / ppo ) given the current point in the series. For illustration, this can be used in a loop as follows:
      
           int maxP = 1024;
           int minP = 1;
           int ppo = 2;
      
           for (int p = minP; p <= maxP; p = pwr2LawNext(ppo, p)) {
             System.out.print(p + " ");
           }
           //generates the following series:
           //1 2 3 4 6 8 11 16 23 32 45 64 91 128 181 256 362 512 724 1024
       
      Parameters:
      ppo - Points-Per-Octave, or the number of points per integer powers of 2 in the series.
      curPoint - the current point of the series. Must be ≥ 1.
      Returns:
      the next point in the power series.
    • pwr2LawPrev

      public static int pwr2LawPrev​(int ppo, int curPoint)
      Computes the previous, smaller integer point in the power series point = 2( i / ppo ) given the current point in the series. For illustration, this can be used in a loop as follows:
      
           int maxP = 1024;
           int minP = 1;
           int ppo = 2;
      
           for (int p = maxP; p >= minP; p = pwr2LawPrev(ppo, p)) {
             System.out.print(p + " ");
           }
           //generates the following series:
           //1024 724 512 362 256 181 128 91 64 45 32 23 16 11 8 6 4 3 2 1
       
      Parameters:
      ppo - Points-Per-Octave, or the number of points per integer powers of 2 in the series.
      curPoint - the current point of the series. Must be ≥ 1.
      Returns:
      the previous, smaller point in the power series. A returned value of zero terminates the series.
    • log2

      public static double log2​(double value)
      The log base 2 of the value
      Parameters:
      value - the given value
      Returns:
      The log base 2 of the value
    • simpleLog2OfLong

      public static int simpleLog2OfLong​(long x)
      Gives the log2 of a long that is known to be a power of 2.
      Parameters:
      x - number that is greater than zero
      Returns:
      the log2 of a long that is known to be a power of 2.
    • startingSubMultiple

      public static int startingSubMultiple​(int lgTarget, int lgRF, int lgMin)
      Gets the smallest allowed exponent of 2 that it is a sub-multiple of the target by zero, one or more resize factors.
      Parameters:
      lgTarget - Log2 of the target size
      lgRF - Log_base2 of Resize Factor. See Resize Factor
      lgMin - Log2 of the minimum allowed starting size
      Returns:
      The Log2 of the starting size
    • ceilingPowerOfBdouble

      public static double ceilingPowerOfBdouble​(double b, double n)
      Computes the ceiling power of B as a double. This is the smallest positive power of B that equal to or greater than the given n and equal to a mathematical integer. The result of this function is consistent with ceilingPowerOf2(int) for values less than one. I.e., if n < 1, the result is 1.
      Parameters:
      b - The base in the expression ⌈bn⌉.
      n - The input argument.
      Returns:
      the ceiling power of B as a double and equal to a mathematical integer.
    • floorPowerOfBdouble

      public static double floorPowerOfBdouble​(double b, double n)
      Computes the floor power of B as a double. This is the largest positive power of B that equal to or less than the given n and equal to a mathematical integer. The result of this function is consistent with floorPowerOf2(int) for values less than one. I.e., if n < 1, the result is 1.
      Parameters:
      b - The base in the expression ⌊bn⌋.
      n - The input argument.
      Returns:
      the floor power of 2 and equal to a mathematical integer.
    • logB

      public static double logB​(double logBase, double x)
      Returns the logarithm_logBase of x. Example: logB(2.0, x) = log(x) / log(2.0).
      Parameters:
      logBase - the base of the logarithm used
      x - the given value
      Returns:
      the logarithm_logBase of x: Example: logB(2.0, x) = log(x) / log(2.0).
    • pwrLawNextDouble

      public static double pwrLawNextDouble​(int ppo, double curPoint, boolean roundToInt, double logBase)
      Computes the next larger double in the power series point = logBase( i / ppo ) given the current point in the series. For illustration, this can be used in a loop as follows:
      
           double maxP = 1024.0;
           double minP = 1.0;
           int ppo = 2;
           double logBase = 2.0;
      
           for (double p = minP; p <= maxP; p = pwr2LawNextDouble(ppo, p, true, logBase)) {
             System.out.print(Math.round(p) + " ");
           }
           //generates the following series:
           //1 2 3 4 6 8 11 16 23 32 45 64 91 128 181 256 362 512 724 1024
       
      Parameters:
      ppo - Points-Per-Octave, or the number of points per integer powers of 2 in the series.
      curPoint - the current point of the series. Must be ≥ 1.0.
      roundToInt - if true the output will be rounded to the nearest integer.
      logBase - the desired base of the logarithms
      Returns:
      the next point in the power series.
    • checkBounds

      public static void checkBounds​(long reqOff, long reqLen, long allocSize)
      Check the requested offset and length against the allocated size. The invariants equation is: 0 <= reqOff <= reqLen <= reqOff + reqLen <= allocSize. If this equation is violated an SketchesArgumentException will be thrown.
      Parameters:
      reqOff - the requested offset
      reqLen - the requested length
      allocSize - the allocated size.
    • checkNomLongs

      public static int checkNomLongs​(int nomLongs)
      Checks that the given nomLongs is within bounds and returns the Log2 of the ceiling power of 2 of the given nomLongs.
      Parameters:
      nomLongs - the given number of nominal longs. This can be any value from 16 to 67108864, inclusive.
      Returns:
      The Log2 of the ceiling power of 2 of the given nomLongs.
    • checkProbability

      public static void checkProbability​(double p, String argName)
      Checks the given parameter to make sure it is positive and between 0.0 inclusive and 1.0 inclusive.
      Parameters:
      p - See Sampling Probability, p
      argName - Used in the thrown exception.
    • isLessThanUnsigned

      public static boolean isLessThanUnsigned​(long n1, long n2)
      Unsigned compare with longs.
      Parameters:
      n1 - A long to be treated as if unsigned.
      n2 - A long to be treated as if unsigned.
      Returns:
      true if n1 > n2.
    • getResourcePath

      public static String getResourcePath​(String shortFileName)
      Gets the absolute path of the given resource file's shortName.

      Note that the ClassLoader.getResource(shortName) returns a URL, which can have special characters, e.g., "%20" for spaces. This method obtains the URL, converts it to a URI, then does a uri.getPath(), which decodes any special characters in the URI path. This is required to make obtaining resources operating-system independent.

      Parameters:
      shortFileName - the last name in the pathname's name sequence.
      Returns:
      the absolute path of the given resource file's shortName.
    • getResourceFile

      public static File getResourceFile​(String shortFileName)
      Gets the file defined by the given resource file's shortFileName.
      Parameters:
      shortFileName - the last name in the pathname's name sequence.
      Returns:
      the file defined by the given resource file's shortFileName.
    • getResourceBytes

      public static byte[] getResourceBytes​(String shortFileName)
      Returns a byte array of the contents of the file defined by the given resource file's shortFileName.
      Parameters:
      shortFileName - the last name in the pathname's name sequence.
      Returns:
      a byte array of the contents of the file defined by the given resource file's shortFileName.
    • validateValues

      public static void validateValues​(float[] values)
      Checks the sequential validity of the given array of float values. They must be unique, monotonically increasing and not NaN.
      Parameters:
      values - the given array of values