2using System.Collections;
3using System.Collections.Generic;
11 class MapWrapper<TKey, TValue> : IDictionary<TKey, TValue>
23 _map = map ??
throw new ArgumentNullException(nameof(map));
27 public TValue
this[TKey key]
29 get => (TValue)_map.get(key);
30 set => _map.put(key, value);
34 public ICollection<TKey>
Keys => _map.keySet().AsCollection<TKey>();
37 public ICollection<TValue>
Values => _map.values().AsCollection<TValue>();
40 public int Count => _map.size();
46 public void Add(TKey key, TValue value) => _map.put(key, value);
49 public void Add(KeyValuePair<TKey, TValue> item) => _map.put(item.Key, item.Value);
52 public void Clear() => _map.clear();
55 public bool Contains(KeyValuePair<TKey, TValue> item)
57 return _map.containsKey(item.Key) && _map.get(item.Key).Equals(item.Value);
63 return _map.containsKey(key);
67 public void CopyTo(KeyValuePair<TKey, TValue>[] array,
int arrayIndex)
69 foreach (var entry
in this)
70 array[arrayIndex++] = entry;
76 return _map.entrySet().AsEnumerable<Map.Entry>().Select(i =>
new KeyValuePair<TKey, TValue>((TKey)i.getKey(), (TValue)i.getValue())).GetEnumerator();
82 if (_map.containsKey(key))
92 public bool Remove(KeyValuePair<TKey, TValue> item)
94 return _map.remove(item.Key, item.Value);
100 if (_map.containsKey(key))
102 value = (TValue) _map.get(key);
111 IEnumerator IEnumerable.GetEnumerator()
void CopyTo(KeyValuePair< TKey, TValue >[] array, int arrayIndex)
MapWrapper(Map map)
Initializes a new instance.
bool TryGetValue(TKey key, out TValue value)
bool Remove(KeyValuePair< TKey, TValue > item)
bool Contains(KeyValuePair< TKey, TValue > item)
void Add(TKey key, TValue value)
ICollection< TValue > Values
bool ContainsKey(TKey key)
void Add(KeyValuePair< TKey, TValue > item)
IEnumerator< KeyValuePair< TKey, TValue > > GetEnumerator()