akka.japi.pf.AbstractPFBuilder Maven / Gradle / Ivy
/**
* Copyright (C) 2009-2014 Typesafe Inc.
*/
package akka.japi.pf;
import scala.PartialFunction;
/**
* A builder for {@link scala.PartialFunction}.
*
* @param the input type, that this PartialFunction will be applied to
* @param 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.
*/
abstract class AbstractPFBuilder {
protected PartialFunction statements = null;
protected void addStatement(PartialFunction statement) {
if (statements == null)
statements = statement;
else
statements = statements.orElse(statement);
}
/**
* Build a {@link scala.PartialFunction} from this builder.
* After this call the builder will be reset.
*
* @return a PartialFunction for this builder.
*/
public PartialFunction build() {
PartialFunction empty = CaseStatement.empty();
PartialFunction statements = this.statements;
this.statements = null;
if (statements == null)
return empty;
else
return statements.orElse(empty);
}
}