com.aol.cyclops.matcher.builders.StreamCase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cyclops-pattern-matching-collections Show documentation
Show all versions of cyclops-pattern-matching-collections Show documentation
Advanced pattern matching for Java 8
package com.aol.cyclops.matcher.builders;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.Wither;
import com.aol.cyclops.matcher.ChainOfResponsibility;
import com.aol.cyclops.matcher.Two;
/**
* Case Builder for building Cases from Stream data
*
* @author johnmcclean
*
*/
@AllArgsConstructor
public class StreamCase extends CaseBeingBuilt{
@Getter(AccessLevel.PACKAGE)
@Wither(AccessLevel.PACKAGE)
private final PatternMatcher patternMatcher;
/**Select matching / passing elements from Stream **/
/**
* Build a 'Stream of responsibility' pattern
* Stream of responsibility equivalent to ChainOfResponsibility pattern
* ChainOfResponsibility interface includes a Predicate and an Action - each will be used to build a case
*
* @param stream Each member of this Stream will result in one additional Case
* @return Pattern Matcher Builder with additional new Cases per Stream element added.
*/
public CollectionMatchingInstance streamOfResponsibility(Stream extends ChainOfResponsibility> stream){
return addCase(patternMatcher.selectFromChain(stream));
}
/**
* Build a 'Stream of responsibility' pattern
* Stream of responsibility equivalent to ChainOfResponsibility pattern
* Tuple includes a Predicate and an Action (Function) - each will be used to build a case
*
* @param stream Each member of this Stream will result in one additional Case
* @return Pattern Matcher Builder with additional new Cases per Stream element added.
*/
public CollectionMatchingInstance streamOfResponsibilityFromTuple(Stream,Function>> stream){
return addCase(patternMatcher.selectFrom(stream));
}
private CollectionMatchingInstance addCase(PatternMatcher o){
return new CollectionMatchingInstance<>(this.withPatternMatcher(o));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy