Package org.drasyl.util
Class UnsignedMediumInteger
java.lang.Object
org.drasyl.util.UnsignedMediumInteger
This class represents an unsigned integer in a rang of [0, 2^24)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UnsignedMediumIntegerstatic final UnsignedMediumInteger -
Method Summary
Modifier and TypeMethodDescriptionbooleanintgetValue()inthashCode()static UnsignedMediumIntegerof(byte[] value) Creates a newUnsignedMediumInteger.static UnsignedMediumIntegerof(int value) Creates a newUnsignedMediumInteger.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 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
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
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 3.
-
getValue
public int getValue()- Returns:
- the value as int
-
equals
-
hashCode
public int hashCode() -
toString
-