下面列出了com.google.common.collect.EvictingQueue#peek ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void sendTimings(CommandSender sender) {
EvictingQueue<TimingHistory> history = Reflection.getField(TimingsManager.class, "HISTORY", EvictingQueue.class)
.get(null);
TimingHistory lastHistory = history.peek();
if (lastHistory == null) {
sendError(sender, "Not enough data collected yet");
return;
}
List<BaseComponent[]> lines = new ArrayList<>();
printTimings(lines, lastHistory);
Pages pagination = new Pages("Paper Timings", lines);
pagination.send(sender);
plugin.getPageManager().setPagination(sender.getName(), pagination);
}
@Override
protected void sendTimings(CommandSender sender) {
EvictingQueue<TimingHistory> history = Reflection.getField(TimingsManager.class, "HISTORY", EvictingQueue.class)
.get(null);
TimingHistory lastHistory = history.peek();
if (lastHistory == null) {
sendError(sender, "Not enough data collected yet");
return;
}
List<BaseComponent[]> lines = new ArrayList<>();
printTimings(lines, lastHistory);
Pages pagination = new Pages("Paper Timings", lines);
pagination.send(sender);
plugin.getPageManager().setPagination(sender.getName(), pagination);
}
@Override
public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) {
InternalHistogram histo = (InternalHistogram) aggregation;
List<? extends InternalHistogram.Bucket> buckets = histo.getBuckets();
InternalHistogram.Factory<? extends InternalHistogram.Bucket> factory = histo.getFactory();
List newBuckets = new ArrayList<>();
EvictingQueue<Double> lagWindow = EvictingQueue.create(lag);
int counter = 0;
for (InternalHistogram.Bucket bucket : buckets) {
Double thisBucketValue = resolveBucketValue(histo, bucket, bucketsPaths()[0], gapPolicy);
InternalHistogram.Bucket newBucket = bucket;
counter += 1;
// Still under the initial lag period, add nothing and move on
Double lagValue;
if (counter <= lag) {
lagValue = Double.NaN;
} else {
lagValue = lagWindow.peek(); // Peek here, because we rely on add'ing to always move the window
}
// Normalize null's to NaN
if (thisBucketValue == null) {
thisBucketValue = Double.NaN;
}
// Both have values, calculate diff and replace the "empty" bucket
if (!Double.isNaN(thisBucketValue) && !Double.isNaN(lagValue)) {
double diff = thisBucketValue - lagValue;
List<InternalAggregation> aggs = new ArrayList<>(eagerTransform(bucket.getAggregations().asList(), AGGREGATION_TRANFORM_FUNCTION));
aggs.add(new InternalSimpleValue(name(), diff, formatter, new ArrayList<PipelineAggregator>(), metaData()));
newBucket = factory.createBucket(bucket.getKey(), bucket.getDocCount(), new InternalAggregations(
aggs), bucket.getKeyed(), bucket.getFormatter());
}
newBuckets.add(newBucket);
lagWindow.add(thisBucketValue);
}
return factory.create(newBuckets, histo);
}