Beispiel #1
0
  public static byte toByte(@NotNull final UnsignedByteArray bytes) {
    if (bytes.length() != 1) throw new IllegalArgumentException("Wrong length");

    return (byte) (bytes.data[0] ^ Byte.MIN_VALUE);
  }
Beispiel #2
0
  public static short toShort(@NotNull final UnsignedByteArray bytes) {
    if (bytes.length() != Shorts.BYTES) throw new IllegalArgumentException("Wrong length");

    return (short) (Shorts.fromByteArray(bytes.data) ^ Short.MIN_VALUE);
  }
Beispiel #3
0
  public static long toLong(@NotNull final UnsignedByteArray bytes) {
    if (bytes.length() != Longs.BYTES) throw new IllegalArgumentException("Wrong length");

    return Longs.fromByteArray(bytes.data) ^ Long.MIN_VALUE;
  }
Beispiel #4
0
  public static int toInt(@NotNull final UnsignedByteArray bytes) {
    if (bytes.length() != Ints.BYTES) throw new IllegalArgumentException("Wrong length");

    return Ints.fromByteArray(bytes.data) ^ Integer.MIN_VALUE;
  }
Beispiel #5
0
 public static boolean toBoolean(@NotNull final UnsignedByteArray bytes) {
   if (bytes.equals(TRUE)) return true;
   else if (bytes.equals(FALSE)) return false;
   else throw new IllegalArgumentException("Unexpected value");
 }