本文整理汇总了Java中com.clearspring.analytics.stream.StreamSummary.offer方法的典型用法代码示例。如果您正苦于以下问题:Java StreamSummary.offer方法的具体用法?Java StreamSummary.offer怎么用?Java StreamSummary.offer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.clearspring.analytics.stream.StreamSummary
的用法示例。
在下文中一共展示了StreamSummary.offer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStreamSummaryAccuracy
import com.clearspring.analytics.stream.StreamSummary; //导入方法依赖的package包/类
@Test
public void testStreamSummaryAccuracy() {
StreamSummary<Integer> vs = new StreamSummary<Integer>(5);
Random random = new Random();
random.setSeed(3128);
int maxItems = 5;
for (int i = 0; i < maxItems; i++) {
vs.offer(i, random.nextInt(2000));
}
int fetchTopK = 5;
List<Counter<Integer>> topK = vs.topK(fetchTopK);
for (Counter<Integer> c : topK) {
// System.out.println(c.toString());
}
}
示例2: resortTopN
import com.clearspring.analytics.stream.StreamSummary; //导入方法依赖的package包/类
private List<String> resortTopN(DruidSpecs druidSpecs, String dimension,
List<Map<String, Object>> listOfResult) {
StreamSummary<String> topN = new StreamSummary<String>(TOPN_MAX);
for (Map<String, Object> map : listOfResult) {
@SuppressWarnings("unchecked")
List<Map<String, Object>> resultList = (List<Map<String, Object>>) map
.get(RESULT);
if (resultList != null) {
for (Map<String, Object> result : resultList) {
Number metricNum = (Number) result.get(druidSpecs.getSort());
;
String dimStr = (String) result.get(dimension);
if (dimStr == null) {
dimStr = "";
}
topN.offer(dimStr, metricNum.intValue());
}
}
}
return FluentIterable.from(topN.topK(druidSpecs.getLimit()))
.transform(new Function<Counter<String>, String>() {
@Override
public String apply(Counter<String> input) {
return input.getItem();
}
}).toList();
}
示例3: testStringBuckets
import com.clearspring.analytics.stream.StreamSummary; //导入方法依赖的package包/类
@Test
public void testStringBuckets() {
StreamSummary<String> vs = new StreamSummary<String>(3);
String[] stream = {"X", "X", "Y", "Z", "A", "B", "C", "X", "X", "A", "C", "A", "A"};
for (String i : stream) {
vs.offer(i, 10);
}
List<Counter<String>> topK = vs.topK(3);
for (Counter<String> c : topK) {
// assertTrue(Arrays.asList("A", "C", "X").contains(c.getItem()));
// System.out.println(c.toString());
}
}