From 14ac28c468ca81b645cabf21552748a46f7b21e2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 10 Jun 2024 15:21:00 +0100 Subject: Update java-mammoth --- Mammoth/Couscous/java/util/HashMap.cs | 40 ++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'Mammoth/Couscous/java/util/HashMap.cs') 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 : AbstractMap { private readonly Dictionary _dictionary; - + internal HashMap() : this(new Dictionary()) { } - + internal HashMap(Dictionary dictionary) { _dictionary = dictionary; } - + internal HashMap(Map map) : this(new Dictionary(map.AsDictionary())) { } - + public override void put(TKey key, TValue value) { _dictionary[key] = value; } - + + public override void putAll(Map 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> entrySet() { return new EntrySet(_dictionary); } - + public override Collection values() { return ToJava.CollectionToCollection(_dictionary.Values); } - + public override Optional _lookup(TKey key) { if (_dictionary.ContainsKey(key)) { return new Some(_dictionary[key]); @@ -40,38 +46,38 @@ namespace Mammoth.Couscous.java.util { return None.Instance; } } - + public override IDictionary AsDictionary() { return _dictionary; } - + public override System.Collections.IDictionary AsUntypedDictionary() { return _dictionary; } - + internal class EntrySet : Set> { private readonly IDictionary _dictionary; - + internal EntrySet(IDictionary dictionary) { _dictionary = dictionary; } - + public Iterator> 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 value) { throw new UnsupportedOperationException(); } -- cgit v1.2.3