@@ -33,7 +33,7 @@ class Env private[env](private val map: Map[TypedKey[_], Any]) {
33
33
map.get(key) match {
34
34
case Some (value) ⇒
35
35
Maybe (value).asInstanceOf [Maybe [T ]]
36
-
36
+
37
37
case None ⇒
38
38
NoVal
39
39
}
@@ -48,12 +48,17 @@ class Env private[env](private val map: Map[TypedKey[_], Any]) {
48
48
def ++ (other : Env ): Env = new Env (other.map ++ map)
49
49
50
50
override def hashCode () = map.##
51
+
51
52
override def equals (any : Any ): Boolean = {
52
53
any match {
53
- case that : Env ⇒ this .map == that.map && this .getClass == that.getClass
54
- case _ ⇒ false
54
+ case that : Env ⇒
55
+ this .map == that.map && this .getClass == that.getClass
56
+
57
+ case _ ⇒
58
+ false
55
59
}
56
60
}
61
+
57
62
override def toString = " Env(%s)" .format(map.mkString(" , " ))
58
63
59
64
def size = map.size
@@ -88,6 +93,22 @@ class Env private[env](private val map: Map[TypedKey[_], Any]) {
88
93
def contains [T : Manifest ](key : TypedKey [T ]): Boolean = {
89
94
map.contains(key)
90
95
}
96
+
97
+ /**
98
+ * Returns a `Map` whose keys are the names of the typed keys. Beware that typed keys may have the same names,
99
+ * so this can lead to loss of key-value pairs.
100
+ */
101
+ def toMap : Map [String , Any ] = {
102
+ map.map{case (tk, vt) ⇒ (tk.name, vt)}
103
+ }
104
+
105
+ /**
106
+ * Returns a [[java.util.Map ]] whose keys are the names of the typed keys. Beware that typed keys may have the same
107
+ * names, so this can lead to loss of key-value pairs.
108
+ */
109
+ def toJavaMap : java.util.Map [String , Any ] = {
110
+ scala.collection.JavaConversions .mapAsJavaMap(toMap)
111
+ }
91
112
}
92
113
93
114
object Env {
0 commit comments