File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
main/java/com/jnape/palatable/lambda/adt/hmap
test/java/com/jnape/palatable/lambda/adt/hmap Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,16 @@ public Iterable<Object> values() {
125
125
return map (Tuple2 ::_2 , this );
126
126
}
127
127
128
+ /**
129
+ * Return a standard {@link Map} view of the current snapshot of this {@link HMap}. Note that updates to either the
130
+ * {@link Map} view or to the original {@link HMap} do not propagate to the other.
131
+ *
132
+ * @return the map view
133
+ */
134
+ public Map <TypeSafeKey , Object > toMap () {
135
+ return new HashMap <>(table );
136
+ }
137
+
128
138
@ Override
129
139
public Iterator <Tuple2 <TypeSafeKey , Object >> iterator () {
130
140
return map (Tuple2 ::fromEntry , table .entrySet ()).iterator ();
Original file line number Diff line number Diff line change 2
2
3
3
import org .junit .Test ;
4
4
5
+ import java .util .HashMap ;
5
6
import java .util .NoSuchElementException ;
6
7
import java .util .Optional ;
7
8
@@ -128,6 +129,18 @@ public void demandForAbsentKey() {
128
129
emptyHMap ().demand (typeSafeKey ());
129
130
}
130
131
132
+ @ Test
133
+ public void toMap () {
134
+ TypeSafeKey <String > stringKey = typeSafeKey ();
135
+ TypeSafeKey <Integer > intKey = typeSafeKey ();
136
+
137
+ assertEquals (new HashMap <TypeSafeKey , Object >() {{
138
+ put (stringKey , "string" );
139
+ put (intKey , 1 );
140
+ }}, hMap (stringKey , "string" ,
141
+ intKey , 1 ).toMap ());
142
+ }
143
+
131
144
@ Test
132
145
public void iteratesKVPairsAsTuples () {
133
146
TypeSafeKey <String > stringKey = typeSafeKey ();
You can’t perform that action at this time.
0 commit comments