public void testMinus() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned.bigIntegerValue().subtract(bUnsigned.bigIntegerValue()).longValue(); UnsignedLong unsignedSub = aUnsigned.minus(bUnsigned); assertEquals(expected, unsignedSub.longValue()); } } }
throw new IOException("Invalid data checksum " + this); recordNumber = fileFirstRecordNumber.minus(UnsignedLong.ONE);
/** * Returns the result of subtracting this and {@code val}. If the result would be negative, * returns the low 64 bits of the result. * * @deprecated Use {@link #minus(UnsignedLong)}. This method is scheduled to be removed in Guava * release 15.0. */ @Deprecated @Beta public UnsignedLong subtract(UnsignedLong val) { return minus(val); }
@Override public ValueType<UnsignedLong> delta(Number value) { return new Derive(getValue().minus(toUnsignedLong(value))); }
@Override public Counter minus(Number value) { return new Counter(getValue().minus(toUnsignedLong(value))); }
/** * Checks whatever extending a file from this offset with to a given length * will overflow NFS4_UINT64_MAX. * * @param length to verify * @param msg included into exception * @throws InvalException if offset + length will overflow * {@link Long.MAX_VALUE} */ public void checkOverflow(long length, String msg) throws InvalException { if (length == nfs4_prot.NFS4_UINT64_MAX) { // special case - up-to-the-end return; } if (MAX_UINT64.minus(UnsignedLong.fromLongBits(value)).compareTo(UnsignedLong.fromLongBits(length)) < 0) { throw new InvalException(msg); } } }
protected void addWordNGrams(List<Integer> line, List<Long> hashes, int n) { if (pruneIdxSize == 0) { return; } for (int i = 0; i < hashes.size(); i++) { UnsignedLong h = toUnsignedLong64(hashes.get(i)); for (int j = i + 1; j < hashes.size() && j < i + n; j++) { long h2 = (long) hashes.get(j).intValue(); long coeff = 116049371L; if (h2 >= 0) { h = h.times(UnsignedLong.valueOf(coeff)).plus(UnsignedLong.valueOf(h2)); } else { h = h.times(UnsignedLong.valueOf(coeff)).minus(UnsignedLong.valueOf(-h2)); } int id = h.mod(UnsignedLong.valueOf(args.getBucketNumber())).intValue(); if (pruneIdxSize > 0) { int pruneId = getPruning(id); if (pruneId >= 0) { id = pruneId; } else { continue; } } line.add(nWords + id); } } }
@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) { if (NAN_ON_COUNTER_WRAP) { throw new ArithmeticException(); } 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)); } // 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)); } }
public void testMinus() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned .bigIntegerValue() .subtract(bUnsigned.bigIntegerValue()) .longValue(); UnsignedLong unsignedSub = aUnsigned.minus(bUnsigned); assertEquals(expected, unsignedSub.longValue()); } } }