本文整理匯總了Java中com.google.common.math.LongMath.divide方法的典型用法代碼示例。如果您正苦於以下問題:Java LongMath.divide方法的具體用法?Java LongMath.divide怎麽用?Java LongMath.divide使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.math.LongMath
的用法示例。
在下文中一共展示了LongMath.divide方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public static void run() throws Exception {
Job job = new JobDetail(); // 創建Job
executorService = Executors.newFixedThreadPool(N_THRESHOLDS); // 新建固定大小線程的池子
for (int i = 0; i < N_THRESHOLDS; i++) {
executorService.submit(new Worker(job)); // 提交線程到池子中
}
// 還需要一個線程,用於周期檢查執行時間是否到達
final ScheduledExecutorService scheduledExcutor = Executors.newSingleThreadScheduledExecutor();
scheduledExcutor.scheduleAtFixedRate(new Runnable() {
public void run() {
if (totalTime.decrementAndGet() == 0) { // 執行時間遞減到0
runnning = false; // 告訴線程,時間到了,所有線程不再執行
scheduledExcutor.shutdownNow();
}
}
}, 1L, 1L, TimeUnit.SECONDS);
// 主線程等到所有的線程都退出,則開始統計
countDownLatch.await();
long totalExeCount = totalExecCount.get();
System.out.println(N_THRESHOLDS + " 個線程," + TIME_THRESHOLDS + " 秒內總共執行的事物數量:" + totalExeCount);
long tps = LongMath.divide(totalExeCount, TIME_THRESHOLDS, RoundingMode.HALF_EVEN);
System.out.println("OKHttp執行的TPS: " + tps);
executorService.shutdownNow(); // 關閉線程池
}
示例2: evaluate
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
public Long evaluate(Input<Integer>... args) {
long millis = DateTimeUtils.currentTimeMillis();
if (args.length == 1) {
Integer precision = args[0].value();
if (precision == null) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH,
"NULL precision not supported for %s", NAME));
}
int factor;
switch (precision) {
case 0:
factor = 1000;
break;
case 1:
factor = 100;
break;
case 2:
factor = 10;
break;
case 3:
factor = 1;
break;
default:
throw new IllegalArgumentException("Precision must be between 0 and 3");
}
millis = LongMath.divide(millis, factor, RoundingMode.DOWN) * factor;
}
return millis;
}
示例3: PaginationLinks
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
* Creates Pagination Links for the given Uri.
*
* @param uriInfo
* uriInfo representing the current request URI.
* @param page
* the current page.
* @param pageSize
* the page size.
* @param totalCount
* the total count of items being paginated.
*/
public PaginationLinks(UriInfo uriInfo, int page, int pageSize, long totalCount) {
ImmutableMap.Builder<String, Href> linksBuilder = ImmutableMap.builder();
linksBuilder.put("first", new Href(getLinkUri(uriInfo, 1, pageSize).toString()));
long pages = 1;
if (totalCount > pageSize) {
pages = LongMath.divide(totalCount, pageSize, RoundingMode.CEILING);
}
if (pages > 1) {
linksBuilder.put("last", new Href(getLinkUri(uriInfo, pages, pageSize).toString()));
}
if (page > 1) {
int prev = page - 1;
if (prev < pages) {
linksBuilder.put("prev", new Href(getLinkUri(uriInfo, prev, pageSize).toString()));
}
}
int next = page + 1;
if (next <= pages) {
linksBuilder.put("next", new Href(getLinkUri(uriInfo, next, pageSize).toString()));
}
this.links = linksBuilder.build();
this.totalPages = pages;
}
示例4: calculatePercentCompletion
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
* Given a low watermark (starting point) and a high watermark (target), returns the percentage
* of events pulled.
*
* @return a percentage value between 0 and 100.
*/
@Override
public short calculatePercentCompletion(Watermark lowWatermark, Watermark highWatermark) {
Preconditions.checkArgument(
lowWatermark instanceof MultiLongWatermark && highWatermark instanceof MultiLongWatermark,
String.format("Arguments of %s.%s must be of type %s", MultiLongWatermark.class.getSimpleName(),
Thread.currentThread().getStackTrace()[1].getMethodName(), MultiLongWatermark.class.getSimpleName()));
long pulled = ((MultiLongWatermark) lowWatermark).getGap(this);
long all = ((MultiLongWatermark) lowWatermark).getGap((MultiLongWatermark) highWatermark);
Preconditions.checkState(all > 0);
long percent = LongMath.divide(pulled * 100, all, RoundingMode.HALF_UP);
return Shorts.checkedCast(percent);
}
示例5: divide
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Benchmark int divide(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
tmp += LongMath.divide(longs[j], nonzero[j], mode);
}
return tmp;
}
示例6: floorDiv
import com.google.common.math.LongMath; //導入方法依賴的package包/類
private static long floorDiv(long x, long y) {
return LongMath.divide(x, y, RoundingMode.FLOOR);
}
示例7: getDifferenceWithRate
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public long getDifferenceWithRate(String key, long value) {
return LongMath.divide(getDifference(key, value), REPORT_PERIOD, RoundingMode.HALF_EVEN);
}
示例8: numberOfChunks
import com.google.common.math.LongMath; //導入方法依賴的package包/類
public static long numberOfChunks(long bytes) {
return LongMath.divide(bytes, FlowManager.CHUNK_SIZE, RoundingMode.UP);
}
示例9: toKB
import com.google.common.math.LongMath; //導入方法依賴的package包/類
protected long toKB(long bytes) {
return LongMath.divide(bytes, 1024, RoundingMode.HALF_UP);
}
示例10: toBlockCount
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/** Returns the nearest multiple of {@code blockSize} that is <= {@code size}. */
private static int toBlockCount(long size, int blockSize) {
return (int) LongMath.divide(size, blockSize, RoundingMode.FLOOR);
}
示例11: divide
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
* 能控製rounding方向的相除
*
* jdk的'/'運算符,直接向下取整
*/
public static long divide(long p, long q, RoundingMode mode) {
return LongMath.divide(p, q, mode);
}