+act #16245 receive builder works with generic messages
UnitPFBuilder use CaseStatements as previously, because apply is cast to exact type ( not ? extends T ) PFBuilder.match working with generic messages
This commit is contained in:
parent
c183989ea2
commit
7cd4a68cee
8 changed files with 289 additions and 176 deletions
|
|
@ -13,8 +13,8 @@ import scala.PartialFunction;
|
|||
*
|
||||
* @param <I> the input type, that this PartialFunction will be applied to
|
||||
* @param <R> the return type, that the results of the application will have
|
||||
*
|
||||
* This is an EXPERIMENTAL feature and is subject to change until it has received more real world testing.
|
||||
* <p>
|
||||
* This is an EXPERIMENTAL feature and is subject to change until it has received more real world testing.
|
||||
*/
|
||||
public class Match<I, R> extends AbstractMatch<I, R> {
|
||||
|
||||
|
|
@ -22,13 +22,13 @@ public class Match<I, R> extends AbstractMatch<I, R> {
|
|||
* Convenience function to create a {@link PFBuilder} with the first
|
||||
* case statement added.
|
||||
*
|
||||
* @param type a type to match the argument against
|
||||
* @param apply an action to apply to the argument if the type matches
|
||||
* @return a builder with the case statement added
|
||||
* @param type a type to match the argument against
|
||||
* @param apply an action to apply to the argument if the type matches
|
||||
* @return a builder with the case statement added
|
||||
* @see PFBuilder#match(Class, FI.Apply)
|
||||
*/
|
||||
public static final <F, T, P> PFBuilder<F, T> match(final Class<P> type,
|
||||
final FI.Apply<P, T> apply) {
|
||||
public static <F, T, P> PFBuilder<F, T> match(final Class<? extends P> type,
|
||||
final FI.Apply<? extends P, T> apply) {
|
||||
return new PFBuilder<F, T>().match(type, apply);
|
||||
}
|
||||
|
||||
|
|
@ -36,15 +36,15 @@ public class Match<I, R> extends AbstractMatch<I, R> {
|
|||
* Convenience function to create a {@link PFBuilder} with the first
|
||||
* case statement added.
|
||||
*
|
||||
* @param type a type to match the argument against
|
||||
* @param predicate a predicate that will be evaluated on the argument if the type matches
|
||||
* @param apply an action to apply to the argument if the type matches
|
||||
* @return a builder with the case statement added
|
||||
* @param type a type to match the argument against
|
||||
* @param predicate a predicate that will be evaluated on the argument if the type matches
|
||||
* @param apply an action to apply to the argument if the type matches
|
||||
* @return a builder with the case statement added
|
||||
* @see PFBuilder#match(Class, FI.TypedPredicate, FI.Apply)
|
||||
*/
|
||||
public static <F, T, P> PFBuilder<F, T> match(final Class<P> type,
|
||||
final FI.TypedPredicate<P> predicate,
|
||||
final FI.Apply<P, T> apply) {
|
||||
public static <F, T, P> PFBuilder<F, T> match(final Class<? extends P> type,
|
||||
final FI.TypedPredicate<? extends P> predicate,
|
||||
final FI.Apply<? extends P, T> apply) {
|
||||
return new PFBuilder<F, T>().match(type, predicate, apply);
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ public class Match<I, R> extends AbstractMatch<I, R> {
|
|||
* Convenience function to create a {@link PFBuilder} with the first
|
||||
* case statement added.
|
||||
*
|
||||
* @param object the object to compare equals with
|
||||
* @param object the object to compare equals with
|
||||
* @param apply an action to apply to the argument if the object compares equal
|
||||
* @return a builder with the case statement added
|
||||
* @see PFBuilder#matchEquals(Object, FI.Apply)
|
||||
|
|
@ -66,7 +66,7 @@ public class Match<I, R> extends AbstractMatch<I, R> {
|
|||
* Convenience function to create a {@link PFBuilder} with the first
|
||||
* case statement added.
|
||||
*
|
||||
* @param apply an action to apply to the argument
|
||||
* @param apply an action to apply to the argument
|
||||
* @return a builder with the case statement added
|
||||
* @see PFBuilder#matchAny(FI.Apply)
|
||||
*/
|
||||
|
|
@ -77,8 +77,8 @@ public class Match<I, R> extends AbstractMatch<I, R> {
|
|||
/**
|
||||
* Create a {@link Match} from the builder.
|
||||
*
|
||||
* @param builder a builder representing the partial function
|
||||
* @return a {@link Match} that can be reused
|
||||
* @param builder a builder representing the partial function
|
||||
* @return a {@link Match} that can be reused
|
||||
*/
|
||||
public static final <F, T> Match<F, T> create(PFBuilder<F, T> builder) {
|
||||
return new Match<F, T>(builder.build());
|
||||
|
|
@ -90,16 +90,16 @@ public class Match<I, R> extends AbstractMatch<I, R> {
|
|||
|
||||
/**
|
||||
* Convenience function to make the Java code more readable.
|
||||
*
|
||||
* <p>
|
||||
* <pre><code>
|
||||
* Matcher<X, Y> matcher = Matcher.create(...);
|
||||
*
|
||||
* <p>
|
||||
* Y someY = matcher.match(obj);
|
||||
* </code></pre>
|
||||
*
|
||||
* @param i the argument to apply the match to
|
||||
* @return the result of the application
|
||||
* @throws MatchError if there is no match
|
||||
* @param i the argument to apply the match to
|
||||
* @return the result of the application
|
||||
* @throws MatchError if there is no match
|
||||
*/
|
||||
public R match(I i) throws MatchError {
|
||||
return statements.apply(i);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue