Package org.drasyl.util
Class UnsignedMediumInteger
- java.lang.Object
-
- org.drasyl.util.UnsignedMediumInteger
-
public class UnsignedMediumInteger extends Object
This class represents an unsigned integer in a rang of [0, 2^24)
-
-
Field Summary
Fields Modifier and Type Field Description static UnsignedMediumInteger
MAX_VALUE
static UnsignedMediumInteger
MIN_VALUE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UnsignedMediumInteger
decrement()
boolean
equals(Object o)
int
getValue()
int
hashCode()
UnsignedMediumInteger
increment()
static UnsignedMediumInteger
of(byte[] value)
Creates a newUnsignedMediumInteger
.static UnsignedMediumInteger
of(int value)
Creates a newUnsignedMediumInteger
.UnsignedMediumInteger
safeDecrement()
UnsignedMediumInteger
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 UnsignedMediumInteger MIN_VALUE
-
MAX_VALUE
public static final UnsignedMediumInteger MAX_VALUE
-
-
Method Detail
-
of
public static UnsignedMediumInteger of(int value)
Creates a newUnsignedMediumInteger
.- Parameters:
value
- the value as int- Returns:
- an unaligned int
- Throws:
IllegalArgumentException
- if the value is not in range of [0, 2^24).
-
of
public static UnsignedMediumInteger of(byte[] value)
Creates a newUnsignedMediumInteger
.- Parameters:
value
- the value as byte array in big-endian (BE) format- Returns:
- an unaligned int
- Throws:
IllegalArgumentException
- if the value is not in range of [0, 2^24).
-
safeIncrement
public UnsignedMediumInteger safeIncrement()
Does increment the unsigned integer but does a modulo operation to handle overflows.- Returns:
- incremented unsigned integer
-
increment
public UnsignedMediumInteger increment()
-
safeDecrement
public UnsignedMediumInteger safeDecrement()
-
decrement
public UnsignedMediumInteger decrement()
-
toBytes
public byte[] toBytes()
- Returns:
- a byte array of length 3.
-
getValue
public int getValue()
- Returns:
- the value as int
-
-