|
Akka/Scala example source code file (WildcardTree.scala)
The WildcardTree.scala Akka example source code/** * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> */ package akka.util import annotation.tailrec import collection.immutable.HashMap private[akka] object WildcardTree { private val empty = new WildcardTree[Nothing]() def apply[T](): WildcardTree[T] = empty.asInstanceOf[WildcardTree[T]] } private[akka] final case class WildcardTree[T](data: Option[T] = None, children: Map[String, WildcardTree[T]] = HashMap[String, WildcardTree[T]]()) { def insert(elems: Iterator[String], d: T): WildcardTree[T] = if (!elems.hasNext) { copy(data = Some(d)) } else { val e = elems.next() copy(children = children.updated(e, children.get(e).getOrElse(WildcardTree()).insert(elems, d))) } @tailrec final def find(elems: Iterator[String]): WildcardTree[T] = if (!elems.hasNext) this else { (children.get(elems.next()) orElse children.get("*")) match { case Some(branch) ⇒ branch.find(elems) case None ⇒ WildcardTree() } } } Other Akka source code examplesHere is a short list of links related to this Akka WildcardTree.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.