config: MapParameters are back in style
This commit is contained in:
parent
f4853c4f63
commit
46751bedeb
@ -23,9 +23,17 @@ abstract class View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class Parameters extends View {
|
abstract class Parameters extends View {
|
||||||
final def ++ (x: Parameters): Parameters = new ChainParameters(this, x)
|
final def ++ (x: Parameters): Parameters =
|
||||||
final def alter(f: (View, View, View) => PartialFunction[Any,Any]): Parameters = Parameters(f) ++ this
|
new ChainParameters(this, x)
|
||||||
final def alterPartial(f: PartialFunction[Any,Any]): Parameters = Parameters((_,_,_) => f) ++ this
|
|
||||||
|
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 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)
|
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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user