Package akka.japi

Class 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 &ldquo;application&rdquo;, 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 JavaPartialFunction.apply(x, true) and if that does not throw noMatch() it will continue with calling JavaPartialFunction.apply(x, false).

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JavaPartialFunction.NoMatch$  
      static class  JavaPartialFunction.NoMatchException  
      • Nested classes/interfaces inherited from interface scala.PartialFunction

        scala.PartialFunction.AndThen<A extends java.lang.Object,​B extends java.lang.Object,​C extends java.lang.Object>, scala.PartialFunction.Lifted<A extends java.lang.Object,​B extends java.lang.Object>, scala.PartialFunction.OrElse<A extends java.lang.Object,​B extends java.lang.Object>, scala.PartialFunction.Unlifted<A extends java.lang.Object,​B extends java.lang.Object>
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static <C> scala.PartialFunction<A,​C> andThen​(scala.Function1<B,​C> k)  
      B apply​(A x)  
      abstract B apply​(A x, boolean isCheck)  
      static double apply$mcDD$sp​(double x)  
      static double apply$mcDF$sp​(float x)  
      static double apply$mcDI$sp​(int x)  
      static double apply$mcDJ$sp​(long x)  
      static float apply$mcFD$sp​(double x)  
      static float apply$mcFF$sp​(float x)  
      static float apply$mcFI$sp​(int x)  
      static float apply$mcFJ$sp​(long x)  
      static int apply$mcID$sp​(double x)  
      static int apply$mcIF$sp​(float x)  
      static int apply$mcII$sp​(int x)  
      static int apply$mcIJ$sp​(long x)  
      static long apply$mcJD$sp​(double x)  
      static long apply$mcJF$sp​(float x)  
      static long apply$mcJI$sp​(int x)  
      static long apply$mcJJ$sp​(long x)  
      static void apply$mcVD$sp​(double x)  
      static void apply$mcVF$sp​(float x)  
      static void apply$mcVI$sp​(int x)  
      static void apply$mcVJ$sp​(long x)  
      static boolean apply$mcZD$sp​(double x)  
      static boolean apply$mcZF$sp​(float x)  
      static boolean apply$mcZI$sp​(int x)  
      static boolean apply$mcZJ$sp​(long x)  
      <A1 extends A,​B1>
      applyOrElse​(A1 x, scala.Function1<A1,​B1> default_)  
      static <A> scala.Function1<A,​R> compose​(scala.Function1<A,​T1> g)  
      boolean isDefinedAt​(A x)  
      static scala.Function1<A,​scala.Option<B>> lift()  
      static java.lang.RuntimeException noMatch()  
      static <A1 extends A,​B1>
      orElse​(scala.PartialFunction<A1,​B1> that)  
      static <U> scala.Function1<A,​java.lang.Object> runWith​(scala.Function1<B,​U> action)  
      static java.lang.String toString()  
      • Methods inherited from class scala.runtime.AbstractPartialFunction

        andThen, apply$mcDD$sp, apply$mcDF$sp, apply$mcDI$sp, apply$mcDJ$sp, apply$mcFD$sp, apply$mcFF$sp, apply$mcFI$sp, apply$mcFJ$sp, apply$mcID$sp, apply$mcIF$sp, apply$mcII$sp, apply$mcIJ$sp, apply$mcJD$sp, apply$mcJF$sp, apply$mcJI$sp, apply$mcJJ$sp, apply$mcVD$sp, apply$mcVF$sp, apply$mcVI$sp, apply$mcVJ$sp, apply$mcZD$sp, apply$mcZF$sp, apply$mcZI$sp, apply$mcZJ$sp, compose, lift, orElse, runWith, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • JavaPartialFunction

        public JavaPartialFunction()
    • Method Detail

      • noMatch

        public static final java.lang.RuntimeException noMatch()
      • compose

        public static <A> scala.Function1<A,​R> compose​(scala.Function1<A,​T1> g)
      • toString

        public static java.lang.String toString()
      • orElse

        public static <A1 extends A,​B1> scala.PartialFunction<A1,​B1> orElse​(scala.PartialFunction<A1,​B1> that)
      • andThen

        public static <C> scala.PartialFunction<A,​C> andThen​(scala.Function1<B,​C> k)
      • lift

        public static scala.Function1<A,​scala.Option<B>> lift()
      • runWith

        public static <U> scala.Function1<A,​java.lang.Object> runWith​(scala.Function1<B,​U> action)
      • apply$mcZD$sp

        public static boolean apply$mcZD$sp​(double x)
      • apply$mcDD$sp

        public static double apply$mcDD$sp​(double x)
      • apply$mcFD$sp

        public static float apply$mcFD$sp​(double x)
      • apply$mcID$sp

        public static int apply$mcID$sp​(double x)
      • apply$mcJD$sp

        public static long apply$mcJD$sp​(double x)
      • apply$mcVD$sp

        public static void apply$mcVD$sp​(double x)
      • apply$mcZF$sp

        public static boolean apply$mcZF$sp​(float x)
      • apply$mcDF$sp

        public static double apply$mcDF$sp​(float x)
      • apply$mcFF$sp

        public static float apply$mcFF$sp​(float x)
      • apply$mcIF$sp

        public static int apply$mcIF$sp​(float x)
      • apply$mcJF$sp

        public static long apply$mcJF$sp​(float x)
      • apply$mcVF$sp

        public static void apply$mcVF$sp​(float x)
      • apply$mcZI$sp

        public static boolean apply$mcZI$sp​(int x)
      • apply$mcDI$sp

        public static double apply$mcDI$sp​(int x)
      • apply$mcFI$sp

        public static float apply$mcFI$sp​(int x)
      • apply$mcII$sp

        public static int apply$mcII$sp​(int x)
      • apply$mcJI$sp

        public static long apply$mcJI$sp​(int x)
      • apply$mcVI$sp

        public static void apply$mcVI$sp​(int x)
      • apply$mcZJ$sp

        public static boolean apply$mcZJ$sp​(long x)
      • apply$mcDJ$sp

        public static double apply$mcDJ$sp​(long x)
      • apply$mcFJ$sp

        public static float apply$mcFJ$sp​(long x)
      • apply$mcIJ$sp

        public static int apply$mcIJ$sp​(long x)
      • apply$mcJJ$sp

        public static long apply$mcJJ$sp​(long x)
      • apply$mcVJ$sp

        public static void apply$mcVJ$sp​(long x)
      • apply

        public abstract B apply​(A x,
                                boolean isCheck)
                         throws java.lang.Exception
      • isDefinedAt

        public final boolean isDefinedAt​(A x)
      • apply

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

        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>