1
+ using System ;
2
+ using System . Collections ;
3
+ using System . Collections . Generic ;
4
+ using System . Linq ;
5
+
6
+ using java . util ;
7
+
8
+ namespace IKVM . Maven . Sdk . Tasks . Extensions
9
+ {
10
+
11
+ class MapWrapper < TKey , TValue > : IDictionary < TKey , TValue >
12
+ {
13
+
14
+ readonly Map map ;
15
+
16
+ /// <summary>
17
+ /// Initializes a new instance.
18
+ /// </summary>
19
+ /// <param name="map"></param>
20
+ /// <exception cref="ArgumentNullException"></exception>
21
+ public MapWrapper ( Map map )
22
+ {
23
+ this . map = map ?? throw new ArgumentNullException ( nameof ( map ) ) ;
24
+ }
25
+
26
+ public TValue this [ TKey key ]
27
+ {
28
+ get => ( TValue ) map . get ( key ) ;
29
+ set => map . put ( key , value ) ;
30
+ }
31
+
32
+ public ICollection < TKey > Keys => map . keySet ( ) . AsCollection < TKey > ( ) ;
33
+
34
+ public ICollection < TValue > Values => map . values ( ) . AsCollection < TValue > ( ) ;
35
+
36
+ public int Count => map . size ( ) ;
37
+
38
+ public bool IsReadOnly => false ;
39
+
40
+ public void Add ( TKey key , TValue value ) => map . put ( key , value ) ;
41
+
42
+ public void Add ( KeyValuePair < TKey , TValue > item ) => map . put ( item . Key , item . Value ) ;
43
+
44
+ public void Clear ( ) => map . clear ( ) ;
45
+
46
+ public bool Contains ( KeyValuePair < TKey , TValue > item )
47
+ {
48
+ return map . containsKey ( item . Key ) && map . get ( item . Key ) . Equals ( item . Value ) ;
49
+ }
50
+
51
+ public bool ContainsKey ( TKey key )
52
+ {
53
+ return map . containsKey ( key ) ;
54
+ }
55
+
56
+ public void CopyTo ( KeyValuePair < TKey , TValue > [ ] array , int arrayIndex )
57
+ {
58
+ foreach ( var entry in this )
59
+ array [ arrayIndex ++ ] = entry ;
60
+ }
61
+
62
+ public IEnumerator < KeyValuePair < TKey , TValue > > GetEnumerator ( )
63
+ {
64
+ return map . entrySet ( ) . AsEnumerable < Map . Entry > ( ) . Select ( i => new KeyValuePair < TKey , TValue > ( ( TKey ) i . getKey ( ) , ( TValue ) i . getValue ( ) ) ) . GetEnumerator ( ) ;
65
+ }
66
+
67
+ public bool Remove ( TKey key )
68
+ {
69
+ if ( map . containsKey ( key ) )
70
+ {
71
+ map . remove ( key ) ;
72
+ return true ;
73
+ }
74
+
75
+ return false ;
76
+ }
77
+
78
+ public bool Remove ( KeyValuePair < TKey , TValue > item )
79
+ {
80
+ return map . remove ( item . Key , item . Value ) ;
81
+ }
82
+
83
+ public bool TryGetValue ( TKey key , out TValue value )
84
+ {
85
+ if ( map . containsKey ( key ) )
86
+ {
87
+ value = ( TValue ) map . get ( key ) ;
88
+ return true ;
89
+ }
90
+
91
+ value = default ;
92
+ return false ;
93
+ }
94
+
95
+ IEnumerator IEnumerable . GetEnumerator ( )
96
+ {
97
+ return GetEnumerator ( ) ;
98
+ }
99
+
100
+ }
101
+
102
+ }
0 commit comments