本文整理了Java中org.apache.edgent.function.Functions.identity()
方法的一些代码示例,展示了Functions.identity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Functions.identity()
方法的具体详情如下:
包路径:org.apache.edgent.function.Functions
类名称:Functions
方法名:identity
[英]Returns the identity function that returns its single argument.
[中]返回返回其单个参数的标识函数。
代码示例来源:origin: apache/incubator-edgent
@Test
public void testIdentity() {
String s = "hello";
assertSame(s, identity().apply(s));
Integer i = 42;
assertSame(i, identity().apply(i));
Object o = new Object();
assertSame(o, identity().apply(o));
}
代码示例来源:origin: apache/incubator-edgent
@Test
public void testKeyedWindowSum() throws Exception {
Topology t = newTopology();
TStream<Integer> integers = t.collection(Arrays.asList(1,2,3,4,4,3,4,4,3));
TWindow<Integer, Integer> window = integers.last(9, identity());
assertSame(identity(), window.getKeyFunction());
assertSame(t, window.topology());
assertSame(integers, window.feeder());
TStream<Integer> sums = window.aggregate((tuples, key) -> {
// All tuples in a partition are equal due to identity
assertEquals(1, new HashSet<>(tuples).size());
int sum = 0;
for(Integer tuple : tuples)
sum+=tuple;
return sum;
});
Condition<Long> tc = t.getTester().tupleCount(sums, 9);
Condition<List<Integer>> contents = t.getTester().streamContents(sums,
1, 2, 3, 4, 8, 6, 12, 16, 9);
complete(t, tc);
assertTrue(contents.valid());
}
代码示例来源:origin: apache/incubator-edgent
@Test
public void testDeadbandMaxSuppression() throws Exception {
Topology topology = newTopology("testDeadbandMaxSuppression");
TStream<Double> values = topology.of(12.9, 3.4, 12.3, 15.6, 18.4, -3.7, -4.5, 15.0, 16.0, 30.0, 42.0 );
// 18.4 will be included as it is delayed since the last inband value.
values = values.modify(tuple -> {if (tuple == 18.4)
try {
Thread.sleep(5000);
} catch (Exception e) {
throw new RuntimeException(e);
} return tuple;});
TStream<Double> filtered = Filters.deadband(values, identity(),
v -> v >= 10.0 && v <= 30.0, 3, TimeUnit.SECONDS);
Condition<Long> count = topology.getTester().tupleCount(filtered, 8);
Condition<List<Double>> contents = topology.getTester().streamContents(filtered, 12.9, 3.4, 12.3, 18.4, -3.7, -4.5, 15.0, 42.0 );
complete(topology, count);
assertTrue(count.valid());
assertTrue(contents.valid());
}
代码示例来源:origin: apache/incubator-edgent
@Test
public void testDeadbandIdentity() throws Exception {
Topology topology = newTopology("testDeadband");
TStream<Double> values = topology.of(12.9, 3.4, 12.3, 15.6, 18.4, -3.7, -4.5, 15.0, 16.0, 30.0, 42.0 );
TStream<Double> filtered = Filters.deadband(values, identity(),
v -> v >= 10.0 && v <= 30.0);
Condition<Long> count = topology.getTester().tupleCount(filtered, 7);
Condition<List<Double>> contents = topology.getTester().streamContents(filtered, 12.9, 3.4, 12.3, -3.7, -4.5, 15.0, 42.0 );
complete(topology, count);
assertTrue(count.valid());
assertTrue(contents.valid());
}
@Test
内容来源于网络,如有侵权,请联系作者删除!