Example usage for com.google.common.primitives UnsignedLong ONE

List of usage examples for com.google.common.primitives UnsignedLong ONE

Introduction

In this page you can find the example usage for com.google.common.primitives UnsignedLong ONE.

Prototype

UnsignedLong ONE

To view the source code for com.google.common.primitives UnsignedLong ONE.

Click Source Link

Usage

From source file:org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreUtils.java

public static final UnsignedLong increase(final UnsignedLong original) {
    return original.plus(UnsignedLong.ONE);
}

From source file:org.opennms.newts.api.Counter.java

@Override
public ValueType<UnsignedLong> delta(Number value) {

    UnsignedLong previous = toUnsignedLong(value);

    // If previous value is greater-than this one, we've wrapped
    if (previous.compareTo(getValue()) > 0) {
        UnsignedLong count32 = getValue().plus(MAX32).plus(UnsignedLong.ONE);

        // Still smaller, this is a 64-bit counter wrap
        if (previous.compareTo(count32) > 0) {
            return new Counter(MAX64.minus(previous).plus(getValue()).plus(UnsignedLong.ONE));
        }/*w ww .  jav a  2s . c o  m*/
        // Process as 32-bit counter wrap
        else {
            return new Counter(MAX32.minus(previous).plus(getValue())).plus(UnsignedLong.ONE);
        }
    }
    // ...no counter wrap has occurred.
    else {
        return new Counter(getValue().minus(previous));
    }
}

From source file:org.opendaylight.controller.cluster.datastore.utils.UnsignedLongRangeSet.java

public void add(final UnsignedLong value) {
    rangeset.add(Range.closedOpen(value, UnsignedLong.ONE.plus(value)));
}

From source file:org.apache.nifi.processors.evtx.parser.ChunkHeader.java

public ChunkHeader(BinaryReader binaryReader, ComponentLog log, long headerOffset, int chunkNumber)
        throws IOException {
    super(binaryReader, headerOffset);
    this.log = log;
    this.chunkNumber = chunkNumber;
    CRC32 crc32 = new CRC32();
    crc32.update(binaryReader.peekBytes(120));

    magicString = binaryReader.readString(8);
    fileFirstRecordNumber = binaryReader.readQWord();
    fileLastRecordNumber = binaryReader.readQWord();
    logFirstRecordNumber = binaryReader.readQWord();
    logLastRecordNumber = binaryReader.readQWord();
    headerSize = binaryReader.readDWord();
    lastRecordOffset = binaryReader.readDWord();
    nextRecordOffset = NumberUtil.intValueMax(binaryReader.readDWord(), Integer.MAX_VALUE,
            "Invalid next record offset.");
    dataChecksum = binaryReader.readDWord();
    unused = binaryReader.readString(68);

    if (!ELF_CHNK.equals(magicString)) {
        throw new IOException("Invalid magic string " + this);
    }/*from  w w w  .ja  va  2s .c  om*/

    headerChecksum = binaryReader.readDWord();

    // These are included into the checksum
    crc32.update(binaryReader.peekBytes(384));

    if (crc32.getValue() != headerChecksum.longValue()) {
        throw new IOException("Invalid checksum " + this);
    }
    if (lastRecordOffset.compareTo(UnsignedInteger.valueOf(Integer.MAX_VALUE)) > 0) {
        throw new IOException("Last record offset too big to fit into signed integer");
    }

    nameStrings = new HashMap<>();
    for (int i = 0; i < 64; i++) {
        int offset = NumberUtil.intValueMax(binaryReader.readDWord(), Integer.MAX_VALUE, "Invalid offset.");
        while (offset > 0) {
            NameStringNode nameStringNode = new NameStringNode(new BinaryReader(binaryReader, offset), this);
            nameStrings.put(offset, nameStringNode);
            offset = NumberUtil.intValueMax(nameStringNode.getNextOffset(), Integer.MAX_VALUE,
                    "Invalid offset.");
        }
    }

    templateNodes = new HashMap<>();
    for (int i = 0; i < 32; i++) {
        int offset = NumberUtil.intValueMax(binaryReader.readDWord(), Integer.MAX_VALUE, "Invalid offset.");
        while (offset > 0) {
            int token = new BinaryReader(binaryReader, offset - 10).read();
            if (token != 0x0c) {
                log.warn("Unexpected token when parsing template at offset " + offset);
                break;
            }
            BinaryReader templateReader = new BinaryReader(binaryReader, offset - 4);
            int pointer = NumberUtil.intValueMax(templateReader.readDWord(), Integer.MAX_VALUE,
                    "Invalid pointer.");
            if (offset != pointer) {
                log.warn("Invalid pointer when parsing template at offset " + offset);
                break;
            }
            TemplateNode templateNode = new TemplateNode(templateReader, this);
            templateNodes.put(offset, templateNode);
            offset = templateNode.getNextOffset();
        }
    }
    crc32 = new CRC32();
    crc32.update(binaryReader.peekBytes(nextRecordOffset - 512));
    if (crc32.getValue() != dataChecksum.longValue()) {
        throw new IOException("Invalid data checksum " + this);
    }
    recordNumber = fileFirstRecordNumber.minus(UnsignedLong.ONE);
}

From source file:org.opendaylight.controller.cluster.datastore.AbstractFrontendHistory.java

private TransactionSuccess<?> handleTransactionPurgeRequest(final TransactionRequest<?> request,
        final RequestEnvelope envelope, final long now) {
    final TransactionIdentifier id = request.getTarget();
    final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId());
    if (purgedTransactions.contains(ul)) {
        // Retransmitted purge request: nothing to do
        LOG.debug("{}: transaction {} already purged", persistenceId, id);
        return new TransactionPurgeResponse(id, request.getSequence());
    }//w  ww.  ja  v a 2s. c  om

    // We perform two lookups instead of a straight remove, because once the map becomes empty we switch it
    // to an ImmutableMap, which does not allow remove().
    if (closedTransactions.containsKey(ul)) {
        tree.purgeTransaction(id, () -> {
            closedTransactions.remove(ul);
            if (closedTransactions.isEmpty()) {
                closedTransactions = ImmutableMap.of();
            }

            purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul)));
            LOG.debug("{}: finished purging inherited transaction {}", persistenceId(), id);
            envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now);
        });
        return null;
    }

    final FrontendTransaction tx = transactions.get(id);
    if (tx == null) {
        // This should never happen because the purge callback removes the transaction and puts it into
        // purged transactions in one go. If it does, we warn about the situation and
        LOG.warn("{}: transaction {} not tracked in {}, but not present in active transactions", persistenceId,
                id, purgedTransactions);
        purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul)));
        return new TransactionPurgeResponse(id, request.getSequence());
    }

    tree.purgeTransaction(id, () -> {
        purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul)));
        transactions.remove(id);
        LOG.debug("{}: finished purging transaction {}", persistenceId(), id);
        envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now);
    });

    return null;
}

From source file:org.jpmml.rexp.RandomForestConverter.java

static <E> List<E> selectValues(List<E> values, Double split, boolean left) {
    UnsignedLong bits = toUnsignedLong(split.doubleValue());

    List<E> result = new ArrayList<>();

    for (int i = 0; i < values.size(); i++) {
        E value = values.get(i);/*from w  w w.j  a va2s. c  o  m*/

        boolean append;

        // Send "true" categories to the left
        if (left) {
            // Test if the least significant bit (LSB) is 1
            append = (bits.mod(RandomForestConverter.TWO)).equals(UnsignedLong.ONE);
        } else

        // Send all other categories to the right
        {
            // Test if the LSB is 0
            append = (bits.mod(RandomForestConverter.TWO)).equals(UnsignedLong.ZERO);
        } // End if

        if (append) {
            result.add(value);
        }

        bits = bits.dividedBy(RandomForestConverter.TWO);
    }

    return result;
}