Class UnsignedInteger

java.lang.Object
org.drasyl.util.UnsignedInteger

public final class UnsignedInteger extends Object
This class represents an unsigned integer in a rang of [0, 2^32)
  • Field Details

  • Method Details

    • of

      public static UnsignedInteger of(long value)
      Creates a new UnsignedInteger.
      Parameters:
      value - the value as long
      Returns:
      an unsigned int
      Throws:
      IllegalArgumentException - if the value is not in range of [0, 2^32).
    • of

      public static UnsignedInteger of(byte[] value)
      Creates a new UnsignedInteger.
      Parameters:
      value - the value as byte array in big-endian (BE) format
      Returns:
      an unsigned int
      Throws:
      IllegalArgumentException - if the value is not in range of [0, 2^32).
    • safeIncrement

      public UnsignedInteger safeIncrement()
      Does increment the unsigned integer but does a modulo operation to handle overflows.
      Returns:
      incremented unsigned integer
    • increment

      public UnsignedInteger increment()
    • safeDecrement

      public UnsignedInteger safeDecrement()
    • decrement

      public UnsignedInteger decrement()
    • toBytes

      public byte[] toBytes()
      Returns:
      a byte array of length 4.
    • getValue

      public long getValue()
      Returns:
      the value as long
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object