本文整理匯總了Java中com.google.common.math.LongMath.checkedAdd方法的典型用法代碼示例。如果您正苦於以下問題:Java LongMath.checkedAdd方法的具體用法?Java LongMath.checkedAdd怎麽用?Java LongMath.checkedAdd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.math.LongMath
的用法示例。
在下文中一共展示了LongMath.checkedAdd方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: reserveEarliestAvailable
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
final long reserveEarliestAvailable(int requiredPermits, long nowMicros) {
resync(nowMicros);
long returnValue = nextFreeTicketMicros;
double storedPermitsToSpend = min(requiredPermits, this.storedPermits);
double freshPermits = requiredPermits - storedPermitsToSpend;
long waitMicros = storedPermitsToWaitTime(this.storedPermits, storedPermitsToSpend)
+ (long) (freshPermits * stableIntervalMicros);
try {
this.nextFreeTicketMicros = LongMath.checkedAdd(nextFreeTicketMicros, waitMicros);
} catch (ArithmeticException e) {
this.nextFreeTicketMicros = Long.MAX_VALUE;
}
this.storedPermits -= storedPermitsToSpend;
return returnValue;
}
示例2: ensureCapacityToWrite
import com.google.common.math.LongMath; //導入方法依賴的package包/類
private void ensureCapacityToWrite(int numBytesToWrite) throws IOException {
long minCapacity = LongMath.checkedAdd(size, numBytesToWrite);
if (minCapacity > data.length) {
long newCapacity = Math.min(Math.max(data.length * 2L, minCapacity), MAX_BUFFER_SIZE);
if (newCapacity < minCapacity) {
throw new IOException("Cannot allocate enough memory to capture all output");
}
data = Arrays.copyOf(data, Ints.checkedCast(newCapacity));
}
}
示例3: addAll
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
* Combines {@code this} filter with another compatible filter. The mutations happen to {@code
* this} instance. Callers must ensure {@code this} filter is appropriately sized to avoid
* saturating it or running out of space.
*
* @param f filter to be combined into {@code this} filter - {@code f} is not mutated
* @return {@code true} if the operation was successful, {@code false} otherwise
* @throws NullPointerException if the specified filter is null
* @throws IllegalArgumentException if {@link #isCompatible(ProbabilisticFilter)} {@code ==
* false}
* @see #add(Object)
* @see #addAll(Collection)
* @see #contains(Object)
*/
public boolean addAll(ProbabilisticFilter<E> f) {
checkNotNull(f);
checkArgument(this != f, "Cannot combine a " + this.getClass().getSimpleName() +
" with itself.");
checkArgument(f instanceof BloomFilter, "Cannot combine a " +
this.getClass().getSimpleName() + " with a " + f.getClass().getSimpleName());
checkArgument(this.isCompatible(f), "Cannot combine incompatible filters. " +
this.getClass().getSimpleName() + " instances must have equivalent funnels; the same " +
"strategy; and the same number of buckets, entries per bucket, and bits per entry.");
delegate.putAll(((BloomFilter<E>) f).delegate);
size = LongMath.checkedAdd(size, f.sizeLong());
return true;
}
示例4: up
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public static long up(long num, int factor) {
if (num <= factor) {
return factor;
} else if (num % factor == 0) {
return num;
} else {
return LongMath.checkedAdd(num / factor * factor, factor);
}
}
示例5: encryptOutputSize
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
public long encryptOutputSize(long size) {
try {
return LongMath.checkedAdd(size, MAC_SIZE_BYTES);
} catch (ArithmeticException e) {
// do nothing
}
return -1;
}
示例6: partition
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public static Iterable<Positional<Buffer>> partition(final Positional<Buffer> input, final int size) {
return () -> new Iterator<Positional<Buffer>>() {
final long position = input.getPosition();
final Buffer src = input.getValue();
private long offset = position;
private Iterator<Buffer> delegate = Buffers.partition(src, size).iterator();
@Override
public boolean hasNext() {
return delegate.hasNext();
}
@Override
public Positional<Buffer> next() {
Buffer buffer = delegate.next();
Positional<Buffer> mapped = new Positional<>(offset, buffer);
offset = LongMath.checkedAdd(offset, size);
return mapped;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
示例7: plus
import com.google.common.math.LongMath; //導入方法依賴的package包/類
private Timestamp plus(long secondsToAdd, long nanosToAdd) {
if ((secondsToAdd | nanosToAdd) == 0) {
return this;
}
long epochSec = LongMath.checkedAdd(getSeconds(), secondsToAdd);
epochSec = LongMath.checkedAdd(epochSec, nanosToAdd / NANOS_PER_SECOND);
nanosToAdd = nanosToAdd % NANOS_PER_SECOND;
long nanoAdjustment = getNanos() + nanosToAdd; // safe int + NANOS_PER_SECOND
return ofEpochSecond(epochSec, nanoAdjustment);
}
示例8: getBalance
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public Value getBalance(boolean includeReceiving) {
lock.lock();
try {
long value = 0;
for (OutPointOutput utxo : getUnspentOutputs(includeReceiving).values()) {
value = LongMath.checkedAdd(value, utxo.getValueLong());
}
return type.value(value);
} finally {
lock.unlock();
}
}
示例9: parse
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public long parse(String string) {
// string could be a floating-point number
if (units.length == 1)
{
try
{
double val = Double.parseDouble(string);
return parseLong(Math.round(val), (U)units[0]);
}
catch (NumberFormatException e)
{
// does nothing.
// Move on to the next step
}
}
boolean isNegative = (string.charAt(0) == '-');
if (isNegative)
string = string.substring(1);
string = preParse(string);
Matcher matcher = regex.matcher(string);
if (!matcher.matches())
throw new AkibanInternalException("couldn't parse string as " + onBehalfOf.name() + ": " + string);
long result = 0;
for (int i = 0, len = matcher.groupCount(); i < len; ++i) {
String group = matcher.group(i+1);
@SuppressWarnings("unchecked")
U unit = (U) units[i];
String preparsedGroup = preParseSegment(group, unit);
Long longValue = Long.parseLong(preparsedGroup);
int max = maxes[i];
if (longValue > max)
throw new AkibanInternalException("out of range: " + group + " while parsing " + onBehalfOf);
long parsed = parseLong(longValue, unit);
result = LongMath.checkedAdd(result, parsed);
}
return isNegative ? -result : result;
}
示例10: noAddOverflow
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
public boolean noAddOverflow(long a, long b) {
try {
LongMath.checkedAdd(a, b);
return true;
} catch (ArithmeticException e) {
return false;
}
}
示例11: binop
import com.google.common.math.LongMath; //導入方法依賴的package包/類
static Long binop(Kind kind, long lhs, long rhs) {
switch (kind) {
case MULTIPLY:
return LongMath.checkedMultiply(lhs, rhs);
case DIVIDE:
return lhs / rhs;
case REMAINDER:
return lhs % rhs;
case PLUS:
return LongMath.checkedAdd(lhs, rhs);
case MINUS:
return LongMath.checkedSubtract(lhs, rhs);
case LEFT_SHIFT:
return lhs << rhs;
case RIGHT_SHIFT:
return lhs >> rhs;
case UNSIGNED_RIGHT_SHIFT:
return lhs >>> rhs;
case AND:
return lhs & rhs;
case XOR:
return lhs ^ rhs;
case OR:
return lhs | rhs;
default:
return null;
}
}
示例12: sum
import com.google.common.math.LongMath; //導入方法依賴的package包/類
static <BM extends IBM, IBM> long[] sum(int[] indexes, int numBits, List<BM> answers, MiruBitmaps<BM, IBM> bitmaps) {
long[] waveform = null;
long[] rawCardinalities = new long[indexes.length - 1];
for (int i = 0; i < numBits; i++) {
BM answer = answers.get(i);
if (answer != null) {
Arrays.fill(rawCardinalities, 0);
bitmaps.boundedCardinalities(answer, new int[][] { indexes }, new long[][] { rawCardinalities });
if (waveform == null) {
waveform = new long[rawCardinalities.length];
}
long multiplier = (1L << i);
for (int j = 0; j < waveform.length; j++) {
if (rawCardinalities[j] > 0) {
long add = rawCardinalities[j] * multiplier;
try {
waveform[j] = LongMath.checkedAdd(waveform[j], add);
} catch (Exception x) {
waveform[j] = Long.MAX_VALUE;
LOG.inc("overflows");
}
}
}
}
}
return waveform;
}
示例13: add
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public <C extends AbstractCoin> C add(C value) {
checkArgument(value.currencyCode.equals(currencyCode));
this.value = LongMath.checkedAdd(this.value, value.getValue());
return (C) this;
}
示例14: add
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public Coin add(final Coin value) {
return new Coin(LongMath.checkedAdd(this.value, value.value));
}
示例15: add
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public Fiat add(final Fiat value) {
checkArgument(value.currencyCode.equals(currencyCode));
return new Fiat(currencyCode, LongMath.checkedAdd(this.value, value.value));
}