alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Akka/Scala example source code file (AbstractPFBuilder.java)

This example Akka source code file (AbstractPFBuilder.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Akka and Scala source code examples by using tags.

All credit for the original source code belongs to akka.io; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Akka tags/keywords

abstractpfbuilder, akka, japi, partialfunction, t

The AbstractPFBuilder.java Akka example source code

/**
 * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
 */

package akka.japi.pf;

import scala.PartialFunction;

/**
 * A builder for {@link scala.PartialFunction}.
 *
 * @param <F> the input type, that this PartialFunction will be applied to
 * @param <T> 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<F, T> {

  protected PartialFunction<F, T> statements = null;

  protected void addStatement(PartialFunction<F, T> 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<F, T> build() {
    PartialFunction<F, T> empty = CaseStatement.empty();
    PartialFunction<F, T> statements = this.statements;

    this.statements = null;
    if (statements == null)
      return empty;
    else
      return statements.orElse(empty);
  }
}

Other Akka source code examples

Here is a short list of links related to this Akka AbstractPFBuilder.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.