akka.japi.pf.UnitPFBuilder Maven / Gradle / Ivy
/*
* Copyright (C) 2009-2020 Lightbend Inc.
*/
package akka.japi.pf;
import scala.runtime.BoxedUnit;
/**
* A builder for {@link scala.PartialFunction}. This is a specialized version of {@link PFBuilder}
* to map java void methods to {@link scala.runtime.BoxedUnit}.
*
* @param the input type, that this PartialFunction to be applied to
*/
public final class UnitPFBuilder extends AbstractPFBuilder {
/** Create a UnitPFBuilder. */
public UnitPFBuilder() {}
/**
* Add a new case statement to this builder.
*
* @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
*/
public UnitPFBuilder match(final Class
type, final FI.UnitApply
apply) {
return matchUnchecked(type, apply);
}
/**
* Add a new case statement to this builder without compile time type check. Should normally not
* be used, but when matching on class with generic type argument it can be useful, e.g.
* List.class
and (List<String> list) -> {}
.
*
* @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
*/
@SuppressWarnings("unchecked")
public UnitPFBuilder matchUnchecked(final Class type, final FI.UnitApply apply) {
FI.Predicate predicate =
new FI.Predicate() {
@Override
public boolean defined(Object o) {
return type.isInstance(o);
}
};
addStatement(new UnitCaseStatement(predicate, (FI.UnitApply