@@ -23,12 +23,23 @@ class Env private[env](private val map: Map[TypedKey[_], Any]) {
23
23
/**
24
24
* Get a value or throw an exception if it does not exist.
25
25
*/
26
+ @ inline
26
27
@ throws(classOf [NoSuchElementException ])
27
28
@ throws(classOf [ClassCastException ])
28
29
def getEx [T : Manifest ](key : TypedKey [T ]): T = {
30
+ this apply key
31
+ }
32
+
33
+ /**
34
+ * Get a value or throw an exception if it does not exist.
35
+ */
36
+ @ throws(classOf [NoSuchElementException ])
37
+ @ throws(classOf [ClassCastException ])
38
+ def apply [T : Manifest ](key : TypedKey [T ]): T = {
29
39
map(key).asInstanceOf [T ]
30
40
}
31
41
42
+
32
43
def get [T : Manifest ](key : TypedKey [T ]): Maybe [T ] = {
33
44
map.get(key) match {
34
45
case Some (value) ⇒
@@ -102,12 +113,19 @@ class Env private[env](private val map: Map[TypedKey[_], Any]) {
102
113
map.map{case (tk, vt) ⇒ (tk.name, vt)}
103
114
}
104
115
116
+ private [this ] def fillJMap [M <: java.util.Map [String , AnyRef ]](jmap : M ): M = {
117
+ for ((tk, vt) ← map) {
118
+ jmap.put(tk.name, vt.asInstanceOf [AnyRef ])
119
+ }
120
+ jmap
121
+ }
122
+
105
123
/**
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.
124
+ * Returns a [[java.util.Map ]] whose keys are the names of the typed keys. Beware that typed keys may have the
125
+ * same names, so this can lead to loss of key-value pairs.
108
126
*/
109
- def toJavaMap : java.util.Map [String , Any ] = {
110
- scala.collection. JavaConversions .mapAsJavaMap(toMap )
127
+ def toJavaMap : java.util.Map [String , AnyRef ] = {
128
+ fillJMap( new java.util. HashMap [ String , AnyRef ](size) )
111
129
}
112
130
}
113
131
0 commit comments