aboutsummaryrefslogtreecommitdiff
path: root/dotnet/Mammoth/Couscous/java/util/HashMap.cs
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-04-14 21:12:07 +0100
committerMichael Williamson <mike@zwobble.org>2016-04-17 16:52:39 +0100
commit0f9ef005f063198ea2e16ca36beaead4bd5e3824 (patch)
tree4ec2f53e900d4cbe9e5258bca48ec0938a8a1762 /dotnet/Mammoth/Couscous/java/util/HashMap.cs
parent490f87c92ff1618591d1932f23613740e79dcb4b (diff)
Add .NET output
Diffstat (limited to 'dotnet/Mammoth/Couscous/java/util/HashMap.cs')
-rw-r--r--dotnet/Mammoth/Couscous/java/util/HashMap.cs69
1 files changed, 69 insertions, 0 deletions
diff --git a/dotnet/Mammoth/Couscous/java/util/HashMap.cs b/dotnet/Mammoth/Couscous/java/util/HashMap.cs
new file mode 100644
index 0000000..38e516e
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/HashMap.cs
@@ -0,0 +1,69 @@
+using System.Collections.Generic;
+using System.Linq;
+using Mammoth.Couscous.org.zwobble.mammoth.@internal.util;
+using Mammoth.Couscous.java.lang;
+
+namespace Mammoth.Couscous.java.util {
+ internal class HashMap<TKey, TValue> : Map<TKey, TValue> {
+ private readonly IDictionary<TKey, TValue> _dictionary;
+
+ internal HashMap() : this(new Dictionary<TKey, TValue>()) {
+ }
+
+ internal HashMap(IDictionary<TKey, TValue> dictionary) {
+ _dictionary = dictionary;
+ }
+
+ public void put(TKey key, TValue value) {
+ _dictionary[key] = value;
+ }
+
+ public bool containsKey(TKey key) {
+ return _dictionary.ContainsKey(key);
+ }
+
+ public Set<Map__Entry<TKey, TValue>> entrySet() {
+ return new EntrySet(_dictionary);
+ }
+
+ public Optional<TValue> _lookup(TKey key) {
+ if (_dictionary.ContainsKey(key)) {
+ return new Some<TValue>(_dictionary[key]);
+ } else {
+ return new None<TValue>();
+ }
+ }
+
+ public IDictionary<TKey, TValue> AsDictionary() {
+ 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();
+ }
+ }
+ }
+}