Java UnsignedByteArray Example

说明

java unsignedbytearray示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Java

类/类型: UnsignedByteArray

示例#1
文件: UnsignedByteArrays.java项目: yandex/yoctodb

  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);
  }

示例#2
文件: UnsignedByteArrays.java项目: yandex/yoctodb

  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);
  }

示例#3
文件: UnsignedByteArrays.java项目: yandex/yoctodb

  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;
  }

示例#4
文件: UnsignedByteArrays.java项目: yandex/yoctodb

  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;
  }

示例#5
文件: UnsignedByteArrays.java项目: yandex/yoctodb

 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");
 }

展开阅读全文