convenience method on Settings to get all (Scope, AttributeKey[_]) pairs

This commit is contained in:
Mark Harrah
2011-01-25 22:19:03 -05:00
parent e739e74ff5
commit f6abc17ddf
+2
View File
@@ -10,6 +10,7 @@ sealed trait Settings[Scope]
def data: Map[Scope, AttributeMap] def data: Map[Scope, AttributeMap]
def keys(scope: Scope): Set[AttributeKey[_]] def keys(scope: Scope): Set[AttributeKey[_]]
def scopes: Set[Scope] def scopes: Set[Scope]
def allKeys[T](f: (Scope, AttributeKey[_]) => T): Seq[T]
def get[T](scope: Scope, key: AttributeKey[T]): Option[T] def get[T](scope: Scope, key: AttributeKey[T]): Option[T]
def set[T](scope: Scope, key: AttributeKey[T], value: T): Settings[Scope] def set[T](scope: Scope, key: AttributeKey[T], value: T): Settings[Scope]
} }
@@ -18,6 +19,7 @@ private final class Settings0[Scope](val data: Map[Scope, AttributeMap], val del
{ {
def scopes: Set[Scope] = data.keySet.toSet def scopes: Set[Scope] = data.keySet.toSet
def keys(scope: Scope) = data(scope).keys.toSet def keys(scope: Scope) = data(scope).keys.toSet
def allKeys[T](f: (Scope, AttributeKey[_]) => T): Seq[T] = data.flatMap { case (scope, map) => map.keys.map(k => f(scope, k)) } toSeq;
def get[T](scope: Scope, key: AttributeKey[T]): Option[T] = def get[T](scope: Scope, key: AttributeKey[T]): Option[T] =
delegates(scope).toStream.flatMap(sc => scopeLocal(sc, key) ).headOption delegates(scope).toStream.flatMap(sc => scopeLocal(sc, key) ).headOption