From 804c182cc0060ddf1a19704abda814f66e36215c Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 4 Jul 2012 10:29:44 +0200 Subject: [PATCH] incorporate review: add docs, see #1952 --- .../src/main/scala/akka/japi/JavaAPI.scala | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/akka-actor/src/main/scala/akka/japi/JavaAPI.scala b/akka-actor/src/main/scala/akka/japi/JavaAPI.scala index d3123153da..b5a53d1fe5 100644 --- a/akka-actor/src/main/scala/akka/japi/JavaAPI.scala +++ b/akka-actor/src/main/scala/akka/japi/JavaAPI.scala @@ -58,6 +58,10 @@ object PurePartialFunction { * `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 PurePartialFunction() { * public String apply(Object in, boolean isCheck) { @@ -74,7 +78,9 @@ object PurePartialFunction { * The typical use of partial functions from Akka looks like the following: * * {{{ - * if (pf.isDefinedAt(x)) pf.apply(x) + * if (pf.isDefinedAt(x)) { + * pf.apply(x); + * } * }}} * * i.e. it will first call `PurePartialFunction.apply(x, true)` and if that @@ -90,6 +96,15 @@ abstract class PurePartialFunction[A, B] extends scala.runtime.AbstractFunction1 final def apply(x: A): B = try apply(x, false) catch { case NoMatch ⇒ throw new MatchError } } +/** + * This is a specialized variant of PartialFunction which is only + * applicable if you know that `isDefinedAt(x)` is always called before + * `apply(x)`—with the same `x` of course. + * + * `match(x)` will be called for `isDefinedAt(x)` only, and its semantics + * are the same as for [[akka.japi.PurePartialFunction]] (apart from the + * missing because unneeded boolean argument). + */ abstract class CachingPartialFunction[A, B <: AnyRef] extends scala.runtime.AbstractFunction1[A, B] with PartialFunction[A, B] { import PurePartialFunction._