本文整理汇总了Java中com.google.common.math.DoubleMath.roundToLong方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMath.roundToLong方法的具体用法?Java DoubleMath.roundToLong怎么用?Java DoubleMath.roundToLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.math.DoubleMath
的用法示例。
在下文中一共展示了DoubleMath.roundToLong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInterval
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* recalculate interval if total number of partitions greater than maximum number of allowed partitions
*
* @param low watermark value
* @param high watermark value
* @param partition interval
* @param Maximum number of allowed partitions
* @return calculated interval
*/
private long getInterval(long lowWatermarkValue, long highWatermarkValue, long partitionInterval, int maxIntervals) {
if (lowWatermarkValue > highWatermarkValue) {
LOG.info("lowWatermarkValue: " + lowWatermarkValue + " is greater than highWatermarkValue: "
+ highWatermarkValue);
return 0;
}
long outputInterval = partitionInterval;
boolean longOverflow = false;
long totalIntervals = Long.MAX_VALUE;
try {
totalIntervals = DoubleMath.roundToLong((double) highWatermarkValue / partitionInterval
- (double) lowWatermarkValue / partitionInterval, RoundingMode.CEILING);
} catch (java.lang.ArithmeticException e) {
longOverflow = true;
}
if (longOverflow || totalIntervals > maxIntervals) {
outputInterval = DoubleMath.roundToLong((double) highWatermarkValue / maxIntervals
- (double) lowWatermarkValue / maxIntervals, RoundingMode.CEILING);
}
return outputInterval;
}
示例2: getInterval
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* recalculate interval if total number of partitions greater than maximum number of allowed partitions
*
* @param low watermark value
* @param high watermark value
* @param partition interval
* @param Maximum number of allowed partitions
* @return calculated interval
*/
private static long getInterval(long lowWatermarkValue, long highWatermarkValue, long partitionInterval,
int maxIntervals) {
if (lowWatermarkValue > highWatermarkValue) {
LOG.info(
"lowWatermarkValue: " + lowWatermarkValue + " is greater than highWatermarkValue: " + highWatermarkValue);
return 0;
}
long outputInterval = partitionInterval;
boolean longOverflow = false;
long totalIntervals = Long.MAX_VALUE;
try {
totalIntervals = DoubleMath.roundToLong(
(double) highWatermarkValue / partitionInterval - (double) lowWatermarkValue / partitionInterval,
RoundingMode.CEILING);
} catch (java.lang.ArithmeticException e) {
longOverflow = true;
}
if (longOverflow || totalIntervals > maxIntervals) {
outputInterval = DoubleMath.roundToLong(
(double) highWatermarkValue / maxIntervals - (double) lowWatermarkValue / maxIntervals, RoundingMode.CEILING);
}
return outputInterval;
}
示例3: startPublishingTimer
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
synchronized void startPublishingTimer() {
if (state.get() == State.Closed) return;
lifetimeCounter--;
if (lifetimeCounter < 1) {
logger.debug("[id={}] lifetime expired.", subscriptionId);
setState(State.Closing);
} else {
long interval = DoubleMath.roundToLong(publishingInterval, RoundingMode.UP);
subscriptionManager.getServer().getScheduledExecutorService().schedule(
this::onPublishingTimer,
interval,
TimeUnit.MILLISECONDS
);
}
}
示例4: approximateElementCount
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Returns an estimate for the total number of distinct elements that have been added to this
* Bloom filter. This approximation is reasonably accurate if it does not exceed the value of
* {@code expectedInsertions} that was used when constructing the filter.
*
* @since 22.0
*/
public long approximateElementCount() {
long bitSize = bits.bitSize();
long bitCount = bits.bitCount();
/**
* Each insertion is expected to reduce the # of clear bits by a factor of
* `numHashFunctions/bitSize`. So, after n insertions, expected bitCount is `bitSize * (1 - (1 -
* numHashFunctions/bitSize)^n)`. Solving that for n, and approximating `ln x` as `x - 1` when x
* is close to 1 (why?), gives the following formula.
*/
double fractionOfBitsSet = (double) bitCount / bitSize;
return DoubleMath.roundToLong(
-Math.log1p(-fractionOfBitsSet) * bitSize / numHashFunctions, RoundingMode.HALF_UP);
}
示例5: getBucketsNeeded
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Calculates how many buckets are needed to hold the chosen number of keys,
* taking the standard load factor into account.
*
* @param maxKeys
* the number of keys the filter is expected to hold before
* insertion failure.
* @return The number of buckets needed
*/
static long getBucketsNeeded(long maxKeys,double loadFactor,int bucketSize) {
/*
* force a power-of-two bucket count so hash functions for bucket index
* can hashBits%numBuckets and get randomly distributed index. See wiki
* "Modulo Bias". Only time we can get perfectly distributed index is
* when numBuckets is a power of 2.
*/
long bucketsNeeded = DoubleMath.roundToLong((1.0 / loadFactor) * maxKeys / bucketSize, RoundingMode.UP);
// get next biggest power of 2
long bitPos = Long.highestOneBit(bucketsNeeded);
if (bucketsNeeded > bitPos)
bitPos = bitPos << 1;
return bitPos;
}
示例6: onPublishingTimer
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* The publishing timer has elapsed.
*/
synchronized void onPublishingTimer() {
State state = this.state.get();
logger.trace("[id={}] onPublishingTimer(), state={}, keep-alive={}, lifetime={}",
subscriptionId, state, keepAliveCounter, lifetimeCounter);
long startNanos = System.nanoTime();
if (state == State.Normal) {
timerHandler.whenNormal();
} else if (state == State.KeepAlive) {
timerHandler.whenKeepAlive();
} else if (state == State.Late) {
timerHandler.whenLate();
} else if (state == State.Closed) {
logger.debug("[id={}] onPublish(), state={}", subscriptionId, state); // No-op.
} else {
throw new RuntimeException("unhandled subscription state: " + state);
}
long elapsedNanos = System.nanoTime() - startNanos;
long elapsedMillis = TimeUnit.MILLISECONDS.convert(elapsedNanos, TimeUnit.NANOSECONDS);
long adjustedInterval = DoubleMath.roundToLong(publishingInterval - elapsedMillis, RoundingMode.UP);
startPublishingTimer(adjustedInterval);
}
示例7: roundToLong
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Benchmark long roundToLong(int reps) {
long tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
tmp += DoubleMath.roundToLong(doubleInLongRange[j], mode);
}
return tmp;
}
示例8: init
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
void init() {
if (simulator.isPresent() && rm.isPresent()) {
int max = 0;
for (final List<Point> ps : points) {
max = Math.max(max, ps.size());
}
final int num = max;
for (int i = 0; i < num; i++) {
final long duration = DoubleMath.roundToLong(
(FactoryExample.SERVICE_DURATION / 2d)
+ (rng.nextDouble() * FactoryExample.SERVICE_DURATION),
RoundingMode.CEILING);
final Point rnd = rndBorder();
Point dest;
if (i >= points.get(0).size()) {
dest = rndBorder();
} else {
dest = points.get(0).get(i);
occupiedPositions.add(dest);
}
final BoxHandle bh = new BoxHandle(i);
final Box b = new Box(rnd, dest, duration, bh);
bh.box = b;
boxes.add(bh);
simulator.get().register(boxes.get(boxes.size() - 1).box);
}
}
}
示例9: handleEvent
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
public void handleEvent(Event e) {
if (e.getEventType() == SimulatorEventType.CONFIGURED) {
init();
} else {
final PDPModelEvent event = (PDPModelEvent) e;
if (e.getEventType() == PDPModelEventType.END_PICKUP) {
occupiedPositions.remove(((Box) event.parcel).origin);
}
if (e.getEventType() == PDPModelEventType.END_DELIVERY) {
final long duration = DoubleMath.roundToLong(
(FactoryExample.SERVICE_DURATION / 2d)
+ (rng.nextDouble() * FactoryExample.SERVICE_DURATION),
RoundingMode.CEILING);
simulator.get().unregister(event.parcel);
final BoxHandle bh = ((Box) event.parcel).boxHandle;
bh.wordIndex = (bh.wordIndex + 1) % points.size();
Point dest;
if (bh.index >= points.get(bh.wordIndex).size()) {
dest = rndBorder();
} else {
dest = points.get(bh.wordIndex).get(bh.index);
occupiedPositions.add(dest);
}
final Box b = new Box(event.parcel.getDestination(), dest, duration, bh);
bh.box = b;
simulator.get().register(b);
}
}
}
示例10: computeTravelTime
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
public long computeTravelTime(Point from, Point to) {
final double speedKMH = vehicle.getDto().getSpeed();
final double distKM = Point.distance(from, to);
final double travelTimeH = distKM / speedKMH;
// convert to nanoseconds
return DoubleMath.roundToLong(travelTimeH * H_TO_NS,
RoundingMode.HALF_DOWN);
}
示例11: startPublishingTimer
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
synchronized void startPublishingTimer() {
long interval = DoubleMath.roundToLong(publishingInterval, RoundingMode.UP);
startPublishingTimer(interval);
}
示例12: ScheduledUpdate
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private ScheduledUpdate(double samplingInterval, List<DataItem> items) {
this.samplingInterval = DoubleMath.roundToLong(samplingInterval, RoundingMode.UP);
this.items = items;
}
示例13: coerceDoubleToLongComparison
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private static Expression coerceDoubleToLongComparison(NormalizedSimpleComparison normalized)
{
checkArgument(normalized.getValue().getType().equals(DOUBLE), "Value should be of DOUBLE type");
checkArgument(!normalized.getValue().isNull(), "Value should not be null");
QualifiedNameReference reference = normalized.getNameReference();
Double value = (Double) normalized.getValue().getValue();
switch (normalized.getComparisonType()) {
case GREATER_THAN_OR_EQUAL:
case LESS_THAN:
return new ComparisonExpression(normalized.getComparisonType(), reference, toExpression(DoubleMath.roundToLong(value, CEILING), BIGINT));
case GREATER_THAN:
case LESS_THAN_OR_EQUAL:
return new ComparisonExpression(normalized.getComparisonType(), reference, toExpression(DoubleMath.roundToLong(value, FLOOR), BIGINT));
case EQUAL:
Long equalValue = DoubleMath.roundToLong(value, FLOOR);
if (equalValue.doubleValue() != value) {
// Return something that is false for all non-null values
return and(new ComparisonExpression(EQUAL, reference, new LongLiteral("0")),
new ComparisonExpression(NOT_EQUAL, reference, new LongLiteral("0")));
}
return new ComparisonExpression(normalized.getComparisonType(), reference, toExpression(equalValue, BIGINT));
case NOT_EQUAL:
Long notEqualValue = DoubleMath.roundToLong(value, FLOOR);
if (notEqualValue.doubleValue() != value) {
// Return something that is true for all non-null values
return or(new ComparisonExpression(EQUAL, reference, new LongLiteral("0")),
new ComparisonExpression(NOT_EQUAL, reference, new LongLiteral("0")));
}
return new ComparisonExpression(normalized.getComparisonType(), reference, toExpression(notEqualValue, BIGINT));
case IS_DISTINCT_FROM:
Long distinctValue = DoubleMath.roundToLong(value, FLOOR);
if (distinctValue.doubleValue() != value) {
return TRUE_LITERAL;
}
return new ComparisonExpression(normalized.getComparisonType(), reference, toExpression(distinctValue, BIGINT));
default:
throw new AssertionError("Unhandled type: " + normalized.getComparisonType());
}
}
示例14: generate
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
public void generate(long seed, Parcel.Builder parcelBuilder,
TravelTimes travelTimes, long endTime) {
rng.setSeed(seed);
final long orderAnnounceTime = parcelBuilder.getOrderAnnounceTime();
final Point pickup = parcelBuilder.getPickupLocation();
final Point delivery = parcelBuilder.getDeliveryLocation();
final long pickupToDeliveryTT = travelTimes.getShortestTravelTime(pickup,
delivery);
final long deliveryToDepotTT = travelTimes
.getTravelTimeToNearestDepot(delivery);
// compute range of possible openings
long pickupOpening;
if (urgency > MINIMAL_PICKUP_TW_LENGTH) {
// possible values range from 0 .. n
// where n = urgency - MINIMAL_PICKUP_TW_LENGTH
pickupOpening = orderAnnounceTime + DoubleMath.roundToLong(
pickupTWopening.get(rng.nextLong())
* (urgency - MINIMAL_PICKUP_TW_LENGTH),
RoundingMode.HALF_UP);
} else {
pickupOpening = orderAnnounceTime;
}
final TimeWindow pickupTW = TimeWindow.create(pickupOpening,
orderAnnounceTime + urgency);
parcelBuilder.pickupTimeWindow(pickupTW);
// find boundaries
final long minDeliveryOpening = pickupTW.begin()
+ parcelBuilder.getPickupDuration() + pickupToDeliveryTT;
final long maxDeliveryClosing = endTime - deliveryToDepotTT
- parcelBuilder.getDeliveryDuration();
long maxDeliveryOpening = maxDeliveryClosing - MINIMAL_DELIVERY_TW_LENGTH;
if (maxDeliveryOpening < minDeliveryOpening) {
maxDeliveryOpening = minDeliveryOpening;
}
final double openingRange = maxDeliveryOpening - minDeliveryOpening;
final long deliveryOpening = minDeliveryOpening
+ DoubleMath.roundToLong(deliveryTWopening.get(rng.nextLong())
* openingRange,
RoundingMode.HALF_DOWN);
final long minDeliveryClosing = Math.min(Math.max(pickupTW.end()
+ parcelBuilder.getPickupDuration() + pickupToDeliveryTT,
deliveryOpening + MINIMAL_DELIVERY_TW_LENGTH), maxDeliveryClosing);
final double closingRange = maxDeliveryClosing - minDeliveryClosing;
final long deliveryClosing = minDeliveryClosing
+ DoubleMath.roundToLong(deliveryTWlength.get(rng.nextLong())
* closingRange,
RoundingMode.HALF_DOWN);
final long latestDelivery = endTime - deliveryToDepotTT
- parcelBuilder.getDeliveryDuration();
final TimeWindow deliveryTW = TimeWindow.create(deliveryOpening,
deliveryClosing);
checkArgument(deliveryOpening >= minDeliveryOpening);
checkArgument(deliveryOpening + deliveryTW.length() <= latestDelivery);
checkArgument(pickupTW.end() + parcelBuilder.getPickupDuration()
+ pickupToDeliveryTT <= deliveryOpening + deliveryTW.length());
parcelBuilder.deliveryTimeWindow(deliveryTW);
}
示例15: roundDoubleToLong
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@SuppressWarnings("SameParameterValue")
public static long roundDoubleToLong(double value, RoundingMode roundingMode) {
return DoubleMath.roundToLong(value, roundingMode);
}