Example usage for com.google.common.primitives UnsignedInts toLong

List of usage examples for com.google.common.primitives UnsignedInts toLong

Introduction

In this page you can find the example usage for com.google.common.primitives UnsignedInts toLong.

Prototype

@CheckReturnValue
public static long toLong(int value) 

Source Link

Document

Returns the value of the given int as a long , when treated as unsigned.

Usage

From source file:org.opendaylight.protocol.bgp.flowspec.Util.java

/**
 * Given the integer values, this method instead of writing the value
 * in 4B field, compresses the value to lowest required byte field
 * depending on the value.//from  w w  w.ja va 2  s.  c  om
 *
 * @param value integer to be written
 * @param buffer ByteBuf where the value will be written
 */
protected static void writeShortest(final int value, final ByteBuf buffer) {
    if (value <= Values.UNSIGNED_BYTE_MAX_VALUE) {
        buffer.writeByte(UnsignedBytes.checkedCast(value));
    } else if (value <= Values.UNSIGNED_SHORT_MAX_VALUE) {
        ByteBufWriteUtil.writeUnsignedShort(value, buffer);
    } else if (value <= Values.UNSIGNED_INT_MAX_VALUE) {
        ByteBufWriteUtil.writeUnsignedInt(UnsignedInts.toLong(value), buffer);
    } else {
        buffer.writeLong(value);
    }
}

From source file:org.opendaylight.protocol.bgp.flowspec.handlers.Util.java

/**
 * Given the integer values, this method instead of writing the value
 * in 4B field, compresses the value to lowest required byte field
 * depending on the value.//ww w. j  a v a 2 s  .c  om
 *
 * @param value integer to be written
 * @param buffer ByteBuf where the value will be written
 */
public static void writeShortest(final int value, final ByteBuf buffer) {
    if (value <= Values.UNSIGNED_BYTE_MAX_VALUE) {
        buffer.writeByte(UnsignedBytes.checkedCast(value));
    } else if (value <= Values.UNSIGNED_SHORT_MAX_VALUE) {
        ByteBufWriteUtil.writeUnsignedShort(value, buffer);
    } else if (value <= Values.UNSIGNED_INT_MAX_VALUE) {
        ByteBufWriteUtil.writeUnsignedInt(UnsignedInts.toLong(value), buffer);
    } else {
        buffer.writeLong(value);
    }
}

From source file:org.apache.giraph.partition.HashRangeWorkerPartitioner.java

@Override
public PartitionOwner getPartitionOwner(I vertexId) {
    long unsignedHashCode = UnsignedInts.toLong(vertexId.hashCode());
    // The reader can verify that unsignedHashCode of HASH_LIMIT - 1 yields
    // index of size - 1, and unsignedHashCode of 0 yields index of 0.
    int index = (int) ((unsignedHashCode * getPartitionOwners().size()) / HASH_LIMIT);
    return partitionOwnerList.get(index);
}

From source file:org.apache.giraph.partition.HashRangePartitionerFactory.java

@Override
public int getPartition(I id, int partitionCount, int workerCount) {
    long unsignedHashCode = UnsignedInts.toLong(id.hashCode());
    // The reader can verify that unsignedHashCode of HASH_LIMIT - 1 yields
    // index of size - 1, and unsignedHashCode of 0 yields index of 0.
    return (int) ((unsignedHashCode * partitionCount) / HASH_LIMIT);
}

From source file:org.apache.directory.server.dhcp.options.IntOption.java

@Nonnegative
public long getIntValue() {
    return UnsignedInts.toLong(Ints.fromByteArray(getData()));
}

From source file:io.druid.java.util.emitter.core.ConcurrentTimeCounter.java

private void updateMax(int time) {
    long max;//from  w  w  w  . j a v a2s  .  c om
    do {
        max = this.max.get();
        if (max >= 0 && ((int) max) >= time) {
            return;
        }
    } while (!this.max.compareAndSet(max, UnsignedInts.toLong(time)));
}

From source file:org.glukit.dexcom.sync.responses.PageRangeResponse.java

@Override
public void fromBytes(byte[] responseAsBytes) {
    super.fromBytes(responseAsBytes);
    try {//from  w w  w  .j  a  va 2 s  .c o m
        DataInput dataInput = dataInputFactory.create(new ByteArrayInputStream(responseAsBytes));
        this.firstPage = UnsignedInts.toLong(dataInput.readInt());
        this.lastPage = UnsignedInts.toLong(dataInput.readInt());

    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:io.druid.java.util.emitter.core.ConcurrentTimeCounter.java

private void updateMin(int time) {
    long min;//from w  w  w .  j ava  2s .c  o m
    do {
        min = this.min.get();
        if (min >= 0 && ((int) min) <= time) {
            return;
        }
    } while (!this.min.compareAndSet(min, UnsignedInts.toLong(time)));
}

From source file:org.glukit.dexcom.sync.responses.ManufacturingDataDatabasePagesResponse.java

public List<ManufacturingParameters> getManufacturingParameters() {
    List<ManufacturingParameters> manufacturingParameters = newArrayList();
    try {/*from   ww  w.j a v  a  2 s.com*/
        for (DatabasePage page : getPages()) {
            ByteArrayInputStream inputStream = new ByteArrayInputStream(page.getPageData());
            DataInput input = this.dataInputFactory.create(inputStream);
            // TODO: something better than ignoring the data?
            long systemSeconds = UnsignedInts.toLong(input.readInt());
            long displaySeconds = UnsignedInts.toLong(input.readInt());

            byte[] xmlBytes = new byte[inputStream.available() - 2];
            input.readFully(xmlBytes);

            validateCrc(input.readUnsignedShort(), page.getPageData());

            XmlMapper xmlMapper = new XmlMapper();
            ManufacturingParameters parameterPage = xmlMapper.readValue(new String(xmlBytes, "UTF-8"),
                    ManufacturingParameters.class);
            manufacturingParameters.add(parameterPage);
        }
        return manufacturingParameters;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.glukit.dexcom.sync.responses.GlucoseReadsDatabasePagesResponse.java

protected GlucoseReadRecord parseRecord(byte[] recordBytes, DatabasePageHeader header, long recordNumber)
        throws IOException {
    DataInput input = this.dataInputFactory.create(new ByteArrayInputStream(recordBytes));
    LOGGER.debug(format("Parsing glucose record from bytes [%s]", toHexString(recordBytes)));

    long systemSeconds = UnsignedInts.toLong(input.readInt());
    long displaySeconds = UnsignedInts.toLong(input.readInt());
    int glucoseValueWithFlags = input.readUnsignedShort();
    byte trendAndArrowNoise = input.readByte();
    int actualReceiverCrc = input.readUnsignedShort();

    validateCrc(actualReceiverCrc, recordBytes);

    GlucoseReadRecord glucoseReadRecord = new GlucoseReadRecord(systemSeconds, displaySeconds,
            glucoseValueWithFlags, trendAndArrowNoise, recordNumber, header.getPageNumber());
    LOGGER.debug(format("Parsed GlucoseRead: [%s]", glucoseReadRecord));

    return glucoseReadRecord;
}