本文整理了Java中org.apache.edgent.function.Functions
类的一些代码示例,展示了Functions
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Functions
类的具体详情如下:
包路径:org.apache.edgent.function.Functions
类名称:Functions
[英]Common functions and functional utilities.
[中]通用函数和功能实用程序。
代码示例来源:origin: org.apache.edgent/edgent-runtime-etiao
/**
* Create with the destination set to {@link Functions#discard()}.
*/
public SettableForwarder() {
this.destination = Functions.discard();
}
代码示例来源:origin: org.apache.edgent/edgent-api-function
/**
* Returns a constant function that returns zero (0).
* This is identical to {@link #zero()} but is more
* readable when applied as a key function.
* @param <T> tuple type
* @return Constant function that returns zero (0).
*/
public static <T> Function<T,Integer> unpartitioned() {
return zero();
}
代码示例来源:origin: org.apache.edgent/edgent-spi-topology
@Override
public TStream<T> peek(Consumer<T> peeker) {
peeker = Functions.synchronizedConsumer(peeker);
connector.peek(new Peek<T>(peeker));
return this;
}
代码示例来源:origin: apache/incubator-edgent
@Test
public void testUnpartitioned() {
String s = "hello";
assertEquals(Integer.valueOf(0), unpartitioned().apply(s));
Integer i = 42;
assertEquals(Integer.valueOf(0), unpartitioned().apply(i));
Object o = new Object();
assertEquals(Integer.valueOf(0), unpartitioned().apply(o));
}
@Test
代码示例来源:origin: apache/incubator-edgent
}, 1, TimeUnit.MILLISECONDS);
TWindow<Long, Integer> window = times.last(1, TimeUnit.SECONDS, unpartitioned());
assertSame(zero(), window.getKeyFunction());
TStream<Long> diffStream = window.aggregate((tuples, key) -> {
assertEquals(Integer.valueOf(0), key);
代码示例来源: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: org.apache.edgent/edgent-spi-topology
public EndlessSupplier(Supplier<T> data) {
super(Functions.synchronizedSupplier(data));
}
代码示例来源:origin: apache/incubator-edgent
/**
* Capture the first and every nth tuple
* @param count the nth value interval
*/
public void setCaptureByCount(int count) {
if (count == 1)
setCaptureByPredicate(Functions.alwaysTrue());
else
setCaptureByPredicate(newByCountPredicate(count));
}
代码示例来源:origin: org.apache.edgent/edgent-spi-topology
@Override
public <U> TStream<U> map(Function<T, U> mapper) {
mapper = synchronizedFunction(mapper);
return connectPipe(new Map<T, U>(mapper));
}
代码示例来源:origin: org.apache.edgent/edgent-connectors-iot
Functions.unpartitioned(), 1).tag("pressureRelieved");
代码示例来源: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
public EndlessSupplier(Supplier<T> data) {
super(Functions.synchronizedSupplier(data));
}
代码示例来源:origin: apache/incubator-edgent
@Test
public void testAlwaysTrue() {
assertTrue(Functions.alwaysTrue().test("hello"));
assertTrue(Functions.alwaysTrue().test(42));
assertTrue(Functions.alwaysTrue().test(new Object()));
}
@Test
代码示例来源:origin: apache/incubator-edgent
@Override
public <U> TStream<U> map(Function<T, U> mapper) {
mapper = synchronizedFunction(mapper);
return connectPipe(new Map<T, U>(mapper));
}
代码示例来源:origin: apache/incubator-edgent
Functions.unpartitioned(), 1).tag("pressureRelieved");
代码示例来源:origin: apache/incubator-edgent
/**
* Create with the destination set to {@link Functions#discard()}.
*/
public SettableForwarder() {
this.destination = Functions.discard();
}
代码示例来源: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
@Override
public <T> TStream<T> poll(Supplier<T> data, long period, TimeUnit unit) {
data = Functions.synchronizedSupplier(data);
return sourceStream(new SupplierPeriodicSource<>(period, unit, data));
}
代码示例来源:origin: apache/incubator-edgent
/**
* Returns a constant function that returns zero (0).
* This is identical to {@link #zero()} but is more
* readable when applied as a key function.
* @param <T> tuple type
* @return Constant function that returns zero (0).
*/
public static <T> Function<T,Integer> unpartitioned() {
return zero();
}
代码示例来源:origin: apache/incubator-edgent
@Override
public TSink<T> sink(Consumer<T> sinker) {
return sink(new Sink<>(Functions.synchronizedConsumer(sinker)));
}
}
内容来源于网络,如有侵权,请联系作者删除!