T - X - public class MatchingInstance<T,X>
extends java.lang.Object
implements java.util.function.Function<T,java.util.Optional<X>>
| Constructor and Description |
|---|
MatchingInstance() |
| Modifier and Type | Method and Description |
|---|---|
java.util.Optional<X> |
apply(java.lang.Object t) |
java.util.function.Function<T,java.util.stream.Stream<X>> |
asStreamFunction() |
java.util.function.Function<T,X> |
asUnwrappedFunction() |
Cases<T,X,TypedFunction<T,X>> |
cases() |
java.util.Optional<X> |
match(java.lang.Object... t)
Aggregates supplied objects into a List for matching against
|
java.util.Optional<X> |
match(java.lang.Object t) |
<R> java.util.stream.Stream<R> |
matchFromStream(java.util.stream.Stream s)
Each input element can generated a single matched value
|
<R> java.util.stream.Stream<R> |
matchMany(java.lang.Object t) |
<R> java.util.stream.Stream<R> |
matchManyFromStream(java.util.stream.Stream s)
Each input element can generated multiple matched values
|
java.util.Optional<X> |
unapply(com.aol.cyclops.objects.Decomposable decomposableObject)
Immediately decompose the supplied parameter and pass it to the PatternMatcher for matching
|
ElementCase<X> |
when()
Create a builder for Matching against a provided Object as is (i.e.
|
<V> CaseBuilder.InMatchOfBuilder<V,X> |
whenAllMatch(org.hamcrest.Matcher<V>... matchers)
Build a Case which is triggered when all of the supplied Hamcrest Matchers holds
|
<V> CaseBuilder.InMatchOfBuilder<V,X> |
whenAnyMatch(org.hamcrest.Matcher<V>... matchers)
Build a Case which is triggered when any of the supplied Hamcrest Matchers holds
|
<V> CaseBuilder.InMatchOfBuilder<V,X> |
whenIsMatch(org.hamcrest.Matcher<V> match)
Build a Case which is triggered when the supplied Hamcrest Matcher holds
|
<V> CaseBuilder.InCaseOfBuilder<V> |
whenIsTrue(java.util.function.Predicate<V> match)
Build a Case which is triggered when the supplied Predicate holds
|
<T,R> MatchingInstance<T,R> |
whenIsType(TypedFunction<T,R> a)
Create a completed Case which is triggered when matching input is of the same type (T) as the input parameter to ActionWithReturn.
|
<V> Step<V,X> |
whenIsValue(V value)
Build a Case which is triggered when the user input matches the supplied Value (via Objects.equals)
|
<V> CaseBuilder.InMatchOfBuilder<V,X> |
whenNoneMatch(org.hamcrest.Matcher<V>... matchers)
Build a Case which is triggered when none of the supplied Hamcrest Matchers holds
|
public final ElementCase<X> when()
public <V> Step<V,X> whenIsValue(V value)
value - will be compared to input provided in match methodpublic <T,R> MatchingInstance<T,R> whenIsType(TypedFunction<T,R> a)
a - Action for the new Case, Predicate for the Case will be created from the input type to the Action.public <V> CaseBuilder.InCaseOfBuilder<V> whenIsTrue(java.util.function.Predicate<V> match)
match - Predicate which will trigger this casepublic <V> CaseBuilder.InMatchOfBuilder<V,X> whenIsMatch(org.hamcrest.Matcher<V> match)
match - Hamcrest Matcher that will trigger this case@SafeVarargs public final <V> CaseBuilder.InMatchOfBuilder<V,X> whenAllMatch(org.hamcrest.Matcher<V>... matchers)
matchers - Hamcrest Matchers that will trigger this case@SafeVarargs public final <V> CaseBuilder.InMatchOfBuilder<V,X> whenAnyMatch(org.hamcrest.Matcher<V>... matchers)
matchers - Hamcrest Matchers that will trigger this case@SafeVarargs public final <V> CaseBuilder.InMatchOfBuilder<V,X> whenNoneMatch(org.hamcrest.Matcher<V>... matchers)
matchers - Hamcrest Matchers that will trigger this casepublic java.util.function.Function<T,X> asUnwrappedFunction()
public java.util.function.Function<T,java.util.stream.Stream<X>> asStreamFunction()
public java.util.Optional<X> apply(java.lang.Object t)
public <R> java.util.stream.Stream<R> matchManyFromStream(java.util.stream.Stream s)
s - Stream of data to match against (input to matcher)public <R> java.util.stream.Stream<R> matchMany(java.lang.Object t)
t - input to match against - can generate multiple valuespublic <R> java.util.stream.Stream<R> matchFromStream(java.util.stream.Stream s)
s - Stream of data to match against (input to matcher)public java.util.Optional<X> match(java.lang.Object... t)
assertThat(Cases.of(Case.of((List<Integer> input) -> input.size()==3, input -> "hello"),
Case.of((List<Integer> input) -> input.size()==2, input -> "ignored"),
Case.of((List<Integer> input) -> input.size()==1, input -> "world")).match(1,2,3).get(),is("hello"));
t - Array to match onpublic java.util.Optional<X> match(java.lang.Object t)
t - Object to match against supplied casespublic java.util.Optional<X> unapply(com.aol.cyclops.objects.Decomposable decomposableObject)
decomposableObject - Object to match on after decomposed via unapply method