Search in sources :

Example 1 with ResultReadable

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);
}
Also used : SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) ArrayList(java.util.ArrayList) ResultReadable(io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable) SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)

Example 2 with ResultReadable

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);
}
Also used : SimpleConfig(io.engineblock.util.SimpleConfig) InputType(io.engineblock.activityapi.input.InputType) Activity(io.engineblock.activityapi.core.Activity) ResultValueFilterType(io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType) OutputType(io.engineblock.activityapi.output.OutputType) Predicate(java.util.function.Predicate) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) SimpleConfig(io.engineblock.util.SimpleConfig) Optional(java.util.Optional) ResultReadable(io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable) ResultFilterDispenser(io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) Predicate(java.util.function.Predicate)

Example 3 with ResultReadable

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();
}
Also used : ResultFilterDispenser(io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser) SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) ResultValueFilterType(io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType) ResultReadable(io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable) Test(org.testng.annotations.Test)

Aggregations

ResultReadable (io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable)3 ResultFilterDispenser (io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser)2 ResultValueFilterType (io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType)2 SimpleCycleResult (io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult)2 Activity (io.engineblock.activityapi.core.Activity)1 CycleResult (io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)1 InputDispenser (io.engineblock.activityapi.input.InputDispenser)1 InputType (io.engineblock.activityapi.input.InputType)1 OutputDispenser (io.engineblock.activityapi.output.OutputDispenser)1 OutputType (io.engineblock.activityapi.output.OutputType)1 SimpleConfig (io.engineblock.util.SimpleConfig)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 Test (org.testng.annotations.Test)1