Class JavaPartialFunction<A,B>

  extended by scala.runtime.AbstractPartialFunction<A,B>
      extended by akka.japi.JavaPartialFunction<A,B>
All Implemented Interfaces:
scala.Function1<A,B>, scala.PartialFunction<A,B>

public abstract class JavaPartialFunction<A,B>
extends scala.runtime.AbstractPartialFunction<A,B>

Helper for implementing a *pure* partial function: it will possibly be invoked multiple times for a single “application”, because its only abstract method is used for both isDefinedAt() and apply(); the former is mapped to isCheck == true and the latter to isCheck == false for those cases where this is important to know.

Failure to match is signaled by throwing noMatch(), i.e. not returning normally (the exception used in this case is pre-allocated, hence not that expensive).

 new JavaPartialFunction<Object, String>() {
   public String apply(Object in, boolean isCheck) {
     if (in instanceof TheThing) {
       if (isCheck) return null; // to spare the expensive or side-effecting code
       return doSomethingWithTheThing((TheThing) in);
     } else {
       throw noMatch();

The typical use of partial functions from Akka looks like the following:

 if (pf.isDefinedAt(x)) {

i.e. it will first call PurePartialFunction.apply(x, true) and if that does not throw noMatch() it will continue with calling PurePartialFunction.apply(x, false).

Nested Class Summary
static class JavaPartialFunction.NoMatch$
static class JavaPartialFunction.NoMatchException
Nested classes/interfaces inherited from interface scala.PartialFunction
scala.PartialFunction.AndThen<A,B,C>, scala.PartialFunction.Lifted<A,B>, scala.PartialFunction.OrElse<A,B>, scala.PartialFunction.Unlifted<A,B>
Constructor Summary
Method Summary
 B apply(A x)
abstract  B apply(A x, boolean isCheck)
<A1 extends A,B1>
applyOrElse(A1 x, scala.Function1<A1,B1> default_)
 boolean isDefinedAt(A x)
static java.lang.RuntimeException noMatch()
Methods inherited from class scala.runtime.AbstractPartialFunction
andThen, andThen$mcDD$sp, andThen$mcDF$sp, andThen$mcDI$sp, andThen$mcDJ$sp, andThen$mcFD$sp, andThen$mcFF$sp, andThen$mcFI$sp, andThen$mcFJ$sp, andThen$mcID$sp, andThen$mcIF$sp, andThen$mcII$sp, andThen$mcIJ$sp, andThen$mcJD$sp, andThen$mcJF$sp, andThen$mcJI$sp, andThen$mcJJ$sp, andThen$mcVD$sp, andThen$mcVF$sp, andThen$mcVI$sp, andThen$mcVJ$sp, andThen$mcZD$sp, andThen$mcZF$sp, andThen$mcZI$sp, andThen$mcZJ$sp, apply$mcDD$sp, apply$mcDF$sp, apply$mcDI$sp, apply$mcDJ$sp, apply$mcDL$sp, apply$mcFD$sp, apply$mcFF$sp, apply$mcFI$sp, apply$mcFJ$sp, apply$mcFL$sp, apply$mcID$sp, apply$mcIF$sp, apply$mcII$sp, apply$mcIJ$sp, apply$mcIL$sp, apply$mcJD$sp, apply$mcJF$sp, apply$mcJI$sp, apply$mcJJ$sp, apply$mcJL$sp, apply$mcLD$sp, apply$mcLF$sp, apply$mcLI$sp, apply$mcLJ$sp, apply$mcVD$sp, apply$mcVF$sp, apply$mcVI$sp, apply$mcVJ$sp, apply$mcVL$sp, apply$mcZD$sp, apply$mcZF$sp, apply$mcZI$sp, apply$mcZJ$sp, apply$mcZL$sp, compose, compose$mcDD$sp, compose$mcDF$sp, compose$mcDI$sp, compose$mcDJ$sp, compose$mcFD$sp, compose$mcFF$sp, compose$mcFI$sp, compose$mcFJ$sp, compose$mcID$sp, compose$mcIF$sp, compose$mcII$sp, compose$mcIJ$sp, compose$mcJD$sp, compose$mcJF$sp, compose$mcJI$sp, compose$mcJJ$sp, compose$mcVD$sp, compose$mcVF$sp, compose$mcVI$sp, compose$mcVJ$sp, compose$mcZD$sp, compose$mcZF$sp, compose$mcZI$sp, compose$mcZJ$sp, lift, orElse, runWith, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public JavaPartialFunction()
Method Detail


public static final java.lang.RuntimeException noMatch()


public abstract B apply(A x,
                        boolean isCheck)


public final boolean isDefinedAt(A x)


public final B apply(A x)
Specified by:
apply in interface scala.Function1<A,B>
apply in class scala.runtime.AbstractPartialFunction<A,B>


public final <A1 extends A,B1> B1 applyOrElse(A1 x,
                                              scala.Function1<A1,B1> default_)
Specified by:
applyOrElse in interface scala.PartialFunction<A,B>
applyOrElse in class scala.runtime.AbstractPartialFunction<A,B>