diff --git a/src/main/scala/config/Config.scala b/src/main/scala/config/Config.scala index 5ae84865..1da72b77 100644 --- a/src/main/scala/config/Config.scala +++ b/src/main/scala/config/Config.scala @@ -23,9 +23,17 @@ abstract class View { } abstract class Parameters extends View { - final def ++ (x: Parameters): Parameters = new ChainParameters(this, x) - final def alter(f: (View, View, View) => PartialFunction[Any,Any]): Parameters = Parameters(f) ++ this - final def alterPartial(f: PartialFunction[Any,Any]): Parameters = Parameters((_,_,_) => f) ++ this + final def ++ (x: Parameters): Parameters = + new ChainParameters(this, x) + + final def alter(f: (View, View, View) => PartialFunction[Any,Any]): Parameters = + Parameters(f) ++ this + + final def alterPartial(f: PartialFunction[Any,Any]): Parameters = + Parameters((_,_,_) => f) ++ this + + final def alterMap(m: Map[Any,Any]): Parameters = + new MapParameters(m) ++ this protected[config] def chain[T](site: View, tail: View, pname: Field[T]): Option[T] protected[config] def find[T](pname: Field[T], site: View) = chain(site, new TerminalView, pname) @@ -69,3 +77,10 @@ private class PartialParameters(f: (View, View, View) => PartialFunction[Any,Any if (g.isDefinedAt(pname)) Some(g.apply(pname).asInstanceOf[T]) else tail.find(pname, site) } } + +private class MapParameters(map: Map[Any, Any]) extends Parameters { + protected[config] def chain[T](site: View, tail: View, pname: Field[T]) = { + val g = map.get(pname) + if (g.isDefined) Some(g.get.asInstanceOf[T]) else tail.find(pname, site) + } +}