private static MessageIntegerOverflowException overflowU8(byte u8) { BigInteger bi = BigInteger.valueOf((long) (u8 & 0xff)); return new MessageIntegerOverflowException(bi); }
private static MessageIntegerOverflowException overflowU16(short u16) { BigInteger bi = BigInteger.valueOf((long) (u16 & 0xffff)); return new MessageIntegerOverflowException(bi); }
private static MessageIntegerOverflowException overflowU32(int u32) { BigInteger bi = BigInteger.valueOf((long) (u32 & 0x7fffffff) + 0x80000000L); return new MessageIntegerOverflowException(bi); }
private static MessageIntegerOverflowException overflowI16(short i16) { BigInteger bi = BigInteger.valueOf((long) i16); return new MessageIntegerOverflowException(bi); }
private static MessageIntegerOverflowException overflowI32(int i32) { BigInteger bi = BigInteger.valueOf((long) i32); return new MessageIntegerOverflowException(bi); }
private static MessageIntegerOverflowException overflowI64(long i64) { BigInteger bi = BigInteger.valueOf(i64); return new MessageIntegerOverflowException(bi); }
@Override public long asLong() { if (!isInLongRange()) { throw new MessageIntegerOverflowException(value); } return value.longValue(); }
@Override public int asInt() { if (!isInIntRange()) { throw new MessageIntegerOverflowException(longValue); } return (int) longValue; }
private static MessageIntegerOverflowException overflowU64(long u64) { BigInteger bi = BigInteger.valueOf(u64 + Long.MAX_VALUE + 1L).setBit(63); return new MessageIntegerOverflowException(bi); }
@Override public int asInt() { if (!isInIntRange()) { throw new MessageIntegerOverflowException(value); } return value.intValue(); }
@Override public short asShort() { if (!isInByteRange()) { throw new MessageIntegerOverflowException(longValue); } return (short) longValue; }
@Override public byte asByte() { if (!isInByteRange()) { throw new MessageIntegerOverflowException(value); } return (byte) value; }
@Override public int asInt() { if (!isInIntRange()) { throw new MessageIntegerOverflowException(value); } return (int) value; }
@Override public byte asByte() { if (!isInByteRange()) { throw new MessageIntegerOverflowException(longValue); } return (byte) longValue; }
@Override public long asLong() { if (!isInLongRange()) { throw new MessageIntegerOverflowException(longValue); } return longValue; }
@Override public short asShort() { if (!isInShortRange()) { throw new MessageIntegerOverflowException(value); } return (short) value; }
@Override public byte asByte() { if (!isInByteRange()) { throw new MessageIntegerOverflowException(value); } return value.byteValue(); }
@Override public short asShort() { if (!isInShortRange()) { throw new MessageIntegerOverflowException(value); } return value.shortValue(); }