use of io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable in project engineblock by engineblock.
the class ResultFilteringSieveTest method testPredicateConversions.
public void testPredicateConversions() {
SimpleCycleResult c1 = new SimpleCycleResult(1, 1);
SimpleCycleResult c2 = new SimpleCycleResult(2, 2);
SimpleCycleResult c3 = new SimpleCycleResult(3, 3);
SimpleCycleResult c4 = new SimpleCycleResult(4, 4);
SimpleCycleResult c5 = new SimpleCycleResult(5, 5);
SimpleCycleResult c6 = new SimpleCycleResult(6, 6);
SimpleCycleResult c7 = new SimpleCycleResult(7, 7);
List<CycleResult> results = new ArrayList<CycleResult>() {
{
add(c1);
add(c2);
add(c3);
add(c4);
add(c5);
add(c6);
add(c7);
}
};
Predicate<ResultReadable> includer = new ResultFilteringSieve.Builder().include(3).exclude(4).build().toInclusivePredicate();
List<CycleResult> included = results.stream().filter(includer).collect(Collectors.toList());
assertThat(included).containsExactly(c1, c2, c3, c5, c6, c7);
Predicate<ResultReadable> excluder = new ResultFilteringSieve.Builder().include(3).exclude(4).build().toExclusivePredicate();
List<CycleResult> excluded = results.stream().filter(excluder).collect(Collectors.toList());
assertThat(excluded).containsExactly(c3);
}
use of io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable in project engineblock by engineblock.
the class CoreServices method getOutputDispenser.
public static <A extends Activity> Optional<OutputDispenser> getOutputDispenser(A activity) {
OutputDispenser outputDispenser = new SimpleConfig(activity, "output").getString("type").flatMap(OutputType.FINDER::get).map(mt -> mt.getOutputDispenser(activity)).orElse(null);
if (outputDispenser == null) {
return Optional.empty();
}
Optional<Predicate<ResultReadable>> outputFilterDispenser = getOutputFilter(activity);
if (outputFilterDispenser.isPresent()) {
outputDispenser = new FilteringOutputDispenser(outputDispenser, outputFilterDispenser.get());
}
return Optional.ofNullable(outputDispenser);
}
use of io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable in project engineblock by engineblock.
the class CoreResultFilterTest method testComponentLifecycle.
@Test
public void testComponentLifecycle() {
ResultValueFilterType filterType = CoreResultValueFilter.FINDER.get("core").orElseThrow(() -> new RuntimeException("Unable to find " + ResultValueFilterType.class.getSimpleName() + " for 'core'"));
ResultFilterDispenser fd = filterType.getDispenser("in:5,ex:6,in:7");
Predicate<ResultReadable> cycleResultFilter = fd.getResultFilter();
assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 3))).isFalse();
assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 5))).isTrue();
assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 6))).isFalse();
assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 7))).isTrue();
assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 8))).isFalse();
}
Aggregations