Package org.drasyl.util
Class UnsignedInteger
java.lang.Object
org.drasyl.util.UnsignedInteger
This class represents an unsigned integer in a rang of [0, 2^32)
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
long
getValue()
int
hashCode()
static UnsignedInteger
of
(byte[] value) Creates a newUnsignedInteger
.static UnsignedInteger
of
(long value) Creates a newUnsignedInteger
.Does increment the unsigned integer but does a modulo operation to handle overflows.byte[]
toBytes()
toString()
-
Field Details
-
MIN_VALUE
-
MAX_VALUE
-
-
Method Details
-
of
Creates a newUnsignedInteger
.- Parameters:
value
- the value as long- Returns:
- an unsigned int
- Throws:
IllegalArgumentException
- if the value is not in range of [0, 2^32).
-
of
Creates a newUnsignedInteger
.- 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
Does increment the unsigned integer but does a modulo operation to handle overflows.- Returns:
- incremented unsigned integer
-
increment
-
safeDecrement
-
decrement
-
toBytes
public byte[] toBytes()- Returns:
- a byte array of length 4.
-
getValue
public long getValue()- Returns:
- the value as long
-
equals
-
hashCode
public int hashCode() -
toString
-