aboutsummaryrefslogtreecommitdiff
path: root/dotnet/Mammoth/Couscous/java/util
diff options
context:
space:
mode:
Diffstat (limited to 'dotnet/Mammoth/Couscous/java/util')
-rw-r--r--dotnet/Mammoth/Couscous/java/util/ArrayList.cs49
-rw-r--r--dotnet/Mammoth/Couscous/java/util/Collection.cs11
-rw-r--r--dotnet/Mammoth/Couscous/java/util/HashMap.cs69
-rw-r--r--dotnet/Mammoth/Couscous/java/util/HashSet.cs34
-rw-r--r--dotnet/Mammoth/Couscous/java/util/List.cs8
-rw-r--r--dotnet/Mammoth/Couscous/java/util/Map.cs15
-rw-r--r--dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs6
-rw-r--r--dotnet/Mammoth/Couscous/java/util/Optional.cs103
-rw-r--r--dotnet/Mammoth/Couscous/java/util/Set.cs6
-rw-r--r--dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs6
-rw-r--r--dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs6
-rw-r--r--dotnet/Mammoth/Couscous/java/util/function/Consumer.cs5
-rw-r--r--dotnet/Mammoth/Couscous/java/util/function/Function.cs6
-rw-r--r--dotnet/Mammoth/Couscous/java/util/function/Predicate.cs5
-rw-r--r--dotnet/Mammoth/Couscous/java/util/function/Supplier.cs5
15 files changed, 334 insertions, 0 deletions
diff --git a/dotnet/Mammoth/Couscous/java/util/ArrayList.cs b/dotnet/Mammoth/Couscous/java/util/ArrayList.cs
new file mode 100644
index 0000000..4414123
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/ArrayList.cs
@@ -0,0 +1,49 @@
+using Mammoth.Couscous.java.lang;
+using Mammoth.Couscous.java.util;
+
+namespace Mammoth.Couscous.java.util {
+ internal class ArrayList<T> : List<T> {
+ private readonly System.Collections.Generic.IList<T> _list;
+
+ internal ArrayList() : this(new System.Collections.Generic.List<T>()) {
+ }
+
+ internal ArrayList(System.Collections.Generic.IList<T> list) {
+ _list = list;
+ }
+
+ public Iterator<T> iterator() {
+ return ToJava.EnumeratorToIterator(_list.GetEnumerator());
+ }
+
+ public bool isEmpty() {
+ return _list.Count == 0;
+ }
+
+ public int size() {
+ return _list.Count;
+ }
+
+ public bool contains(object value) {
+ return value is T && _list.Contains((T) value);
+ }
+
+ public T get(int index) {
+ if (index < 0 || index >= _list.Count) {
+ throw new IndexOutOfBoundsException();
+ } else {
+ return _list[index];
+ }
+ }
+
+ public void add(T value) {
+ _list.Add(value);
+ }
+
+ public T remove(int index) {
+ T value = _list[index];
+ _list.RemoveAt(index);
+ return value;
+ }
+ }
+}
diff --git a/dotnet/Mammoth/Couscous/java/util/Collection.cs b/dotnet/Mammoth/Couscous/java/util/Collection.cs
new file mode 100644
index 0000000..a0cae74
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/Collection.cs
@@ -0,0 +1,11 @@
+using Mammoth.Couscous.java.lang;
+
+namespace Mammoth.Couscous.java.util {
+ interface Collection<T> : Iterable<T> {
+ bool isEmpty();
+ int size();
+ bool contains(object value);
+
+ void add(T value);
+ }
+}
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();
+ }
+ }
+ }
+}
diff --git a/dotnet/Mammoth/Couscous/java/util/HashSet.cs b/dotnet/Mammoth/Couscous/java/util/HashSet.cs
new file mode 100644
index 0000000..ac10075
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/HashSet.cs
@@ -0,0 +1,34 @@
+using System.Collections.Generic;
+
+namespace Mammoth.Couscous.java.util {
+ internal class HashSet<T> : Set<T> {
+ private readonly ISet<T> _set;
+
+ internal HashSet() : this(new System.Collections.Generic.HashSet<T>()) {
+ }
+
+ internal HashSet(ISet<T> set) {
+ _set = set;
+ }
+
+ public Iterator<T> iterator() {
+ return ToJava.EnumeratorToIterator(_set.GetEnumerator());
+ }
+
+ public bool isEmpty() {
+ return _set.Count == 0;
+ }
+
+ public int size() {
+ return _set.Count;
+ }
+
+ public bool contains(object value) {
+ return value is T && _set.Contains((T)value);
+ }
+
+ public void add(T value) {
+ _set.Add(value);
+ }
+ }
+}
diff --git a/dotnet/Mammoth/Couscous/java/util/List.cs b/dotnet/Mammoth/Couscous/java/util/List.cs
new file mode 100644
index 0000000..45a9299
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/List.cs
@@ -0,0 +1,8 @@
+using Mammoth.Couscous.java.lang;
+
+namespace Mammoth.Couscous.java.util {
+ interface List<T> : Collection<T> {
+ T get(int index);
+ T remove(int index);
+ }
+}
diff --git a/dotnet/Mammoth/Couscous/java/util/Map.cs b/dotnet/Mammoth/Couscous/java/util/Map.cs
new file mode 100644
index 0000000..5405c77
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/Map.cs
@@ -0,0 +1,15 @@
+namespace Mammoth.Couscous.java.util {
+ internal interface Map<K, V> {
+ void put(K key, V value);
+ bool containsKey(K key);
+ Set<Map__Entry<K, V>> entrySet();
+
+ Optional<V> _lookup(K key);
+ System.Collections.Generic.IDictionary<K, V> AsDictionary();
+ }
+
+ internal interface Map__Entry<K, V> {
+ K getKey();
+ V getValue();
+ }
+}
diff --git a/dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs b/dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs
new file mode 100644
index 0000000..4a1ee9c
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs
@@ -0,0 +1,6 @@
+using Mammoth.Couscous.java.lang;
+
+namespace Mammoth.Couscous.java.util {
+ internal class NoSuchElementException : RuntimeException {
+ }
+}
diff --git a/dotnet/Mammoth/Couscous/java/util/Optional.cs b/dotnet/Mammoth/Couscous/java/util/Optional.cs
new file mode 100644
index 0000000..f295688
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/Optional.cs
@@ -0,0 +1,103 @@
+using System;
+using Mammoth.Couscous.java.util.function;
+
+namespace Mammoth.Couscous.java.util
+{
+ internal interface Optional<T>
+ {
+ bool isPresent();
+ Optional<U> map<U>(Function<T, U> function);
+ Optional<U> flatMap<U>(Function<T, Optional<U>> function);
+ T orElse(T value);
+ T orElseGet(Supplier<T> supplier);
+ T orElseThrow<TException>(Supplier<TException> exceptionSupplier) where TException : Exception;
+ T get();
+ void ifPresent(Consumer<T> consumer);
+ }
+
+ internal class None<T> : Optional<T> {
+ public bool isPresent() {
+ return false;
+ }
+
+ public Optional<U> map<U>(Function<T, U> function) {
+ return new None<U>();
+ }
+
+ public Optional<U> flatMap<U>(Function<T, Optional<U>> function) {
+ return new None<U>();
+ }
+
+ public T orElse(T value) {
+ return value;
+ }
+
+ public T orElseGet(Supplier<T> supplier) {
+ return supplier.get();
+ }
+
+ public T orElseThrow<TException>(Supplier<TException> exceptionSupplier) where TException : Exception {
+ throw exceptionSupplier.get();
+ }
+
+ public T get() {
+ throw new NoSuchElementException();
+ }
+
+ public void ifPresent(Consumer<T> consumer) {
+ }
+ }
+
+ internal class Some<T> : Optional<T> {
+ private readonly T _value;
+
+ internal Some(T value) {
+ _value = value;
+ }
+
+ public bool isPresent() {
+ return true;
+ }
+
+ public Optional<U> map<U>(Function<T, U> function) {
+ return new Some<U>(function.apply(_value));
+ }
+
+ public Optional<U> flatMap<U>(Function<T, Optional<U>> function) {
+ return function.apply(_value);
+ }
+
+ public T orElse(T value) {
+ return _value;
+ }
+
+ public T orElseGet(Supplier<T> supplier) {
+ return _value;
+ }
+
+ public T orElseThrow<TException>(Supplier<TException> exceptionSupplier) where TException : Exception {
+ return _value;
+ }
+
+ public T get() {
+ return _value;
+ }
+
+ public void ifPresent(Consumer<T> consumer) {
+ consumer.accept(_value);
+ }
+ }
+
+ internal static class Optional
+ {
+ internal static Optional<T> empty<T>()
+ {
+ return new None<T>();
+ }
+
+ internal static Optional<T> of<T>(T value)
+ {
+ return new Some<T> (value);
+ }
+ }
+}
diff --git a/dotnet/Mammoth/Couscous/java/util/Set.cs b/dotnet/Mammoth/Couscous/java/util/Set.cs
new file mode 100644
index 0000000..34a23ac
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/Set.cs
@@ -0,0 +1,6 @@
+using Mammoth.Couscous.java.lang;
+
+namespace Mammoth.Couscous.java.util {
+ internal interface Set<T> : Collection<T> {
+ }
+}
diff --git a/dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs b/dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs
new file mode 100644
index 0000000..050f85f
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs
@@ -0,0 +1,6 @@
+namespace Mammoth.Couscous.java.util.function
+{
+ internal interface BiFunction<T1, T2, U> {
+ U apply(T1 first, T2 second);
+ }
+} \ No newline at end of file
diff --git a/dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs b/dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs
new file mode 100644
index 0000000..0419a6e
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs
@@ -0,0 +1,6 @@
+namespace Mammoth.Couscous.java.util.function
+{
+ internal interface BiPredicate<T, U> {
+ bool test(T first, U second);
+ }
+} \ No newline at end of file
diff --git a/dotnet/Mammoth/Couscous/java/util/function/Consumer.cs b/dotnet/Mammoth/Couscous/java/util/function/Consumer.cs
new file mode 100644
index 0000000..f80d426
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/function/Consumer.cs
@@ -0,0 +1,5 @@
+namespace Mammoth.Couscous.java.util.function {
+ internal interface Consumer<T> {
+ void accept(T value);
+ }
+} \ No newline at end of file
diff --git a/dotnet/Mammoth/Couscous/java/util/function/Function.cs b/dotnet/Mammoth/Couscous/java/util/function/Function.cs
new file mode 100644
index 0000000..2b4d3ae
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/function/Function.cs
@@ -0,0 +1,6 @@
+namespace Mammoth.Couscous.java.util.function
+{
+ internal interface Function<T, U> {
+ U apply(T arg);
+ }
+} \ No newline at end of file
diff --git a/dotnet/Mammoth/Couscous/java/util/function/Predicate.cs b/dotnet/Mammoth/Couscous/java/util/function/Predicate.cs
new file mode 100644
index 0000000..2023309
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/function/Predicate.cs
@@ -0,0 +1,5 @@
+namespace Mammoth.Couscous.java.util.function {
+ internal interface Predicate<T> {
+ bool test(T value);
+ }
+} \ No newline at end of file
diff --git a/dotnet/Mammoth/Couscous/java/util/function/Supplier.cs b/dotnet/Mammoth/Couscous/java/util/function/Supplier.cs
new file mode 100644
index 0000000..eab3ffb
--- /dev/null
+++ b/dotnet/Mammoth/Couscous/java/util/function/Supplier.cs
@@ -0,0 +1,5 @@
+namespace Mammoth.Couscous.java.util.function {
+ internal interface Supplier<T> {
+ T get();
+ }
+} \ No newline at end of file