Java Code Examples for com.google.common.primitives.UnsignedLong#fromLongBits()

The following examples show how to use com.google.common.primitives.UnsignedLong#fromLongBits() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueType.java    From newts with Apache License 2.0 6 votes vote down vote up
public static ValueType<?> compose(ByteBuffer data) {

        ByteBuffer buffer = data.duplicate();
        MetricType type = MetricType.fromCode(buffer.get());

        switch (type) {
            case ABSOLUTE:
                return new Absolute(UnsignedLong.fromLongBits(buffer.getLong()));
            case COUNTER:
                return new Counter(UnsignedLong.fromLongBits(buffer.getLong()));
            case DERIVE:
                return new Derive(UnsignedLong.fromLongBits(buffer.getLong()));
            case GAUGE:
                return new Gauge(buffer.getDouble());
            default:
                throw new IllegalArgumentException(String.format("Unknown metric type: %s", type));
        }
    }
 
Example 2
Source File: AsnUint64Codec.java    From quilt with Apache License 2.0 5 votes vote down vote up
@Override
public UnsignedLong decode() {
  byte[] bytes = getBytes();
  long value = 0;
  for (int i = 0; i <= 7; i++) {
    value <<= Byte.SIZE;
    value |= (bytes[i] & 0xFF);
  }

  return UnsignedLong.fromLongBits(value);
}
 
Example 3
Source File: ValueTypeTest.java    From newts with Apache License 2.0 5 votes vote down vote up
@Test
public void testCounterSerialization() {
    Counter c0 = new Counter(UnsignedLong.fromLongBits(50L));
    ValueType<?> c1 = ValueType.compose(ValueType.decompose(c0));
    assertTrue(c1 instanceof Counter);
    assertEquals(c0, c1);
}
 
Example 4
Source File: BinaryReaderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadQWord() throws IOException {
    UnsignedLong longValue = UnsignedLong.fromLongBits(Long.MAX_VALUE + 500);
    BinaryReader binaryReader = testBinaryReaderBuilder.putQWord(longValue).build();

    assertEquals(longValue, binaryReader.readQWord());
    assertEquals(8, binaryReader.getPosition());
}
 
Example 5
Source File: ValueType.java    From newts with Apache License 2.0 5 votes vote down vote up
public static ValueType<?> compose(Number number, MetricType type) {
    switch (type) {
        case ABSOLUTE:
            return new Absolute(UnsignedLong.fromLongBits(number.longValue()));
        case COUNTER:
            return new Counter(UnsignedLong.fromLongBits(number.longValue()));
        case DERIVE:
            return new Derive(UnsignedLong.fromLongBits(number.longValue()));
        case GAUGE:
            return new Gauge(number.doubleValue());
        default:
            throw new IllegalArgumentException(String.format("Unknown metric type: %s", type));
    }
}
 
Example 6
Source File: RandomForestConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
static
UnsignedLong toUnsignedLong(double value){

	if(!DoubleMath.isMathematicalInteger(value)){
		throw new IllegalArgumentException();
	}

	return UnsignedLong.fromLongBits((long)value);
}
 
Example 7
Source File: ValueTypeTest.java    From newts with Apache License 2.0 5 votes vote down vote up
@Test
public void testAbsoluteSerialization() {
    Absolute c0 = new Absolute(UnsignedLong.fromLongBits(50L));
    ValueType<?> c1 = ValueType.compose(ValueType.decompose(c0));
    assertTrue(c1 instanceof Absolute);
    assertEquals(c0, c1);
}
 
Example 8
Source File: ServiceUtil.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public static double convertFromUint64(byte[] array, UnsignedLong divider) {

		array = normalisate(array, 8);
		UnsignedLong unLong = UnsignedLong.fromLongBits(Longs.fromByteArray(array));

		UnsignedLong div = unLong.dividedBy(divider);
		UnsignedLong mod =  unLong.mod(divider);

		double result = mod.doubleValue() / divider.longValue();
		return result + div.longValue();
	}
 
Example 9
Source File: BinaryReaderTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadQWord() throws IOException {
    UnsignedLong longValue = UnsignedLong.fromLongBits(Long.MAX_VALUE + 500);
    BinaryReader binaryReader = testBinaryReaderBuilder.putQWord(longValue).build();

    assertEquals(longValue, binaryReader.readQWord());
    assertEquals(8, binaryReader.getPosition());
}
 
Example 10
Source File: Hex64TypeNodeTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testHex64TypeNode() throws IOException {
    UnsignedLong value = UnsignedLong.fromLongBits(Long.MAX_VALUE + 1234);
    String hex = value.toString(16);
    assertEquals(hex, new Hex64TypeNode(testBinaryReaderBuilder.putQWord(value).build(), chunkHeader, parent, -1).getValue().substring(2));
}
 
Example 11
Source File: BinaryReader.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Reads 8 bytes in litte endian order and returns the UnsignedLong value
 *
 * @return the value
 */
public UnsignedLong readQWord() {
    ByteBuffer byteBuffer = ByteBuffer.wrap(bytes, position, 8);
    position += 8;
    return UnsignedLong.fromLongBits(byteBuffer.order(ByteOrder.LITTLE_ENDIAN).getLong());
}
 
Example 12
Source File: ClickHouseRowBinaryInputStream.java    From clickhouse-jdbc with Apache License 2.0 4 votes vote down vote up
public UnsignedLong readUInt64AsUnsignedLong() throws IOException {
	return UnsignedLong.fromLongBits(in.readLong());
}
 
Example 13
Source File: BinaryReader.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Reads 8 bytes in litte endian order and returns the UnsignedLong value
 *
 * @return the value
 */
public UnsignedLong readQWord() {
    ByteBuffer byteBuffer = ByteBuffer.wrap(bytes, position, 8);
    position += 8;
    return UnsignedLong.fromLongBits(byteBuffer.order(ByteOrder.LITTLE_ENDIAN).getLong());
}
 
Example 14
Source File: Counter.java    From newts with Apache License 2.0 4 votes vote down vote up
public Counter(long value) {
    this(UnsignedLong.fromLongBits(value));
}
 
Example 15
Source File: Counter.java    From newts with Apache License 2.0 4 votes vote down vote up
protected static UnsignedLong toUnsignedLong(Number value) {
    if (value instanceof UnsignedLong) return (UnsignedLong) value;
    return UnsignedLong.fromLongBits(value.longValue());
}
 
Example 16
Source File: BasicViews.java    From teku with Apache License 2.0 4 votes vote down vote up
public static UInt64View fromLong(long val) {
  return new UInt64View(UnsignedLong.fromLongBits(val));
}
 
Example 17
Source File: UnsignedLongSerializer.java    From teku with Apache License 2.0 4 votes vote down vote up
@Override
public UnsignedLong deserialize(final byte[] data) {
  return UnsignedLong.fromLongBits(Longs.fromByteArray(data));
}
 
Example 18
Source File: TestDataUtils.java    From teku with Apache License 2.0 4 votes vote down vote up
public static UnsignedLong loadUnsignedLongFromYaml(
    final TestDefinition testDefinition, final String fileName) throws IOException {
  return UnsignedLong.fromLongBits(loadYaml(testDefinition, fileName, Long.class));
}
 
Example 19
Source File: DataStructureUtil.java    From teku with Apache License 2.0 4 votes vote down vote up
public UnsignedLong randomUnsignedLong() {
  return UnsignedLong.fromLongBits(randomLong());
}
 
Example 20
Source File: Uint64.java    From yangtools with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Convert this value to an {@link UnsignedLong}.
 *
 * @return An UnsignedLong instance
 */
public final UnsignedLong toGuava() {
    return UnsignedLong.fromLongBits(value);
}