diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-06-10 15:21:00 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-06-10 15:21:00 +0100 |
| commit | 14ac28c468ca81b645cabf21552748a46f7b21e2 (patch) | |
| tree | 917469516808b98a43b5e20c0efc712d32b963f0 /Mammoth/Couscous/java/util/HashMap.cs | |
| parent | 7657de4df31f35408a75ea927c3141cf3ff0cee8 (diff) | |
Update java-mammoth
Diffstat (limited to 'Mammoth/Couscous/java/util/HashMap.cs')
| -rw-r--r-- | Mammoth/Couscous/java/util/HashMap.cs | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/Mammoth/Couscous/java/util/HashMap.cs b/Mammoth/Couscous/java/util/HashMap.cs index 13383a8..bc54490 100644 --- a/Mammoth/Couscous/java/util/HashMap.cs +++ b/Mammoth/Couscous/java/util/HashMap.cs @@ -6,33 +6,39 @@ using Mammoth.Couscous.java.lang; namespace Mammoth.Couscous.java.util { internal class HashMap<TKey, TValue> : AbstractMap<TKey, TValue> { private readonly Dictionary<TKey, TValue> _dictionary; - + internal HashMap() : this(new Dictionary<TKey, TValue>()) { } - + internal HashMap(Dictionary<TKey, TValue> dictionary) { _dictionary = dictionary; } - + internal HashMap(Map<TKey, TValue> map) : this(new Dictionary<TKey, TValue>(map.AsDictionary())) { } - + public override void put(TKey key, TValue value) { _dictionary[key] = value; } - + + public override void putAll(Map<TKey, TValue> other) { + foreach (var pair in other.AsDictionary()) { + _dictionary[pair.Key] = pair.Value; + } + } + public override bool containsKey(TKey key) { return _dictionary.ContainsKey(key); } - + public override Set<Map__Entry<TKey, TValue>> entrySet() { return new EntrySet(_dictionary); } - + public override Collection<TValue> values() { return ToJava.CollectionToCollection(_dictionary.Values); } - + public override Optional<TValue> _lookup(TKey key) { if (_dictionary.ContainsKey(key)) { return new Some<TValue>(_dictionary[key]); @@ -40,38 +46,38 @@ namespace Mammoth.Couscous.java.util { return None<TValue>.Instance; } } - + public override IDictionary<TKey, TValue> AsDictionary() { return _dictionary; } - + public override System.Collections.IDictionary AsUntypedDictionary() { return _dictionary; } - + internal class EntrySet : Set<Map__Entry<TKey, TValue>> { private readonly IDictionary<TKey, TValue> _dictionary; - + internal EntrySet(IDictionary<TKey, TValue> dictionary) { _dictionary = dictionary; } - + public Iterator<Map__Entry<TKey, TValue>> iterator() { return ToJava.EnumeratorToIterator(_dictionary.Select(entry => Maps.entry(entry.Key, entry.Value)).GetEnumerator()); } - + public bool isEmpty() { return _dictionary.Count == 0; } - + public int size() { return _dictionary.Count; } - + public bool contains(object value) { return value is TKey && _dictionary.ContainsKey((TKey) value); } - + public void add(Map__Entry<TKey, TValue> value) { throw new UnsupportedOperationException(); } |
