Class SerialNumberArithmetic

java.lang.Object
org.drasyl.util.SerialNumberArithmetic

public class SerialNumberArithmetic extends Object
Utility class for serial number arithmetic.
  • Method Details

    • add

      public static long add(long s, long n, int serialBits)
      Parameters:
      s - sequence number we want increment. Must be non-negative.
      n - number to add. Must be within range [0, (2^(serialBits - 1) - 1)]
      serialBits - size of the serial number space
      Returns:
      resulting sequence number of the addition
    • lessThan

      public static boolean lessThan(long i1, long i2, int serialBits)
      Parameters:
      i1 - first non-negative number
      i2 - second non-negative number
      serialBits - size of the serial number space
      Returns:
      true if i1 is less than i2. Otherwise false
    • lessThanOrEqualTo

      public static boolean lessThanOrEqualTo(long i1, long i2, int serialBits)
      Parameters:
      i1 - first non-negative number
      i2 - second non-negative number
      serialBits - size of the serial number space
      Returns:
      true if i1 is less than or equal to i2. Otherwise false
    • greaterThan

      public static boolean greaterThan(long i1, long i2, int serialBits)
      Parameters:
      i1 - first non-negative number
      i2 - second non-negative number
      serialBits - size of the serial number space
      Returns:
      true if i1 is greater than i2. Otherwise false
    • greaterThanOrEqualTo

      public static boolean greaterThanOrEqualTo(long i1, long i2, int serialBits)
      Parameters:
      i1 - first non-negative number
      i2 - second non-negative number
      serialBits - size of the serial number space
      Returns:
      true if i1 is greater than or equal to i2. Otherwise false