Package org.drasyl.util
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 Summary
Fields Modifier and Type Field Description static UnsignedInteger
MAX_VALUE
static UnsignedInteger
MIN_VALUE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UnsignedInteger
decrement()
boolean
equals(Object o)
long
getValue()
int
hashCode()
UnsignedInteger
increment()
static UnsignedInteger
of(byte[] value)
Creates a newUnsignedInteger
.static UnsignedInteger
of(long value)
Creates a newUnsignedInteger
.UnsignedInteger
safeDecrement()
UnsignedInteger
safeIncrement()
Does increment the unsigned integer but does a modulo operation to handle overflows.byte[]
toBytes()
String
toString()
-
-
-
Field Detail
-
MIN_VALUE
public static final UnsignedInteger MIN_VALUE
-
MAX_VALUE
public static final UnsignedInteger MAX_VALUE
-
-
Method Detail
-
of
public static UnsignedInteger of(long value)
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
public static UnsignedInteger of(byte[] value)
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
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
-
-