From 0f9ef005f063198ea2e16ca36beaead4bd5e3824 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 14 Apr 2016 21:12:07 +0100 Subject: Add .NET output --- dotnet/Mammoth/Couscous/java/io/Closeable.cs | 9 ++ dotnet/Mammoth/Couscous/java/io/IOException.cs | 17 ++++ dotnet/Mammoth/Couscous/java/io/InputStream.cs | 5 + .../java/lang/IndexOutOfBoundsException.cs | 7 ++ .../Mammoth/Couscous/java/lang/RuntimeException.cs | 13 +++ dotnet/Mammoth/Couscous/java/lang/String.cs | 7 ++ dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs | 14 +++ .../java/lang/UnsupportedOperationException.cs | 7 ++ dotnet/Mammoth/Couscous/java/nio/file/Path.cs | 9 ++ dotnet/Mammoth/Couscous/java/util/ArrayList.cs | 49 ++++++++++ dotnet/Mammoth/Couscous/java/util/Collection.cs | 11 +++ dotnet/Mammoth/Couscous/java/util/HashMap.cs | 69 ++++++++++++++ dotnet/Mammoth/Couscous/java/util/HashSet.cs | 34 +++++++ dotnet/Mammoth/Couscous/java/util/List.cs | 8 ++ dotnet/Mammoth/Couscous/java/util/Map.cs | 15 +++ .../Couscous/java/util/NoSuchElementException.cs | 6 ++ dotnet/Mammoth/Couscous/java/util/Optional.cs | 103 +++++++++++++++++++++ dotnet/Mammoth/Couscous/java/util/Set.cs | 6 ++ .../Couscous/java/util/function/BiFunction.cs | 6 ++ .../Couscous/java/util/function/BiPredicate.cs | 6 ++ .../Couscous/java/util/function/Consumer.cs | 5 + .../Couscous/java/util/function/Function.cs | 6 ++ .../Couscous/java/util/function/Predicate.cs | 5 + .../Couscous/java/util/function/Supplier.cs | 5 + 24 files changed, 422 insertions(+) create mode 100644 dotnet/Mammoth/Couscous/java/io/Closeable.cs create mode 100644 dotnet/Mammoth/Couscous/java/io/IOException.cs create mode 100644 dotnet/Mammoth/Couscous/java/io/InputStream.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/IndexOutOfBoundsException.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/RuntimeException.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/String.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/UnsupportedOperationException.cs create mode 100644 dotnet/Mammoth/Couscous/java/nio/file/Path.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/ArrayList.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/Collection.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/HashMap.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/HashSet.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/List.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/Map.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/Optional.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/Set.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/Consumer.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/Function.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/Predicate.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/Supplier.cs (limited to 'dotnet/Mammoth/Couscous/java') diff --git a/dotnet/Mammoth/Couscous/java/io/Closeable.cs b/dotnet/Mammoth/Couscous/java/io/Closeable.cs new file mode 100644 index 0000000..36b2a80 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/io/Closeable.cs @@ -0,0 +1,9 @@ +using System; + +namespace Mammoth.Couscous.java.io +{ + internal interface Closeable + { + } +} + diff --git a/dotnet/Mammoth/Couscous/java/io/IOException.cs b/dotnet/Mammoth/Couscous/java/io/IOException.cs new file mode 100644 index 0000000..f7b708e --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/io/IOException.cs @@ -0,0 +1,17 @@ +using System; + +namespace Mammoth.Couscous.java.io +{ + internal class IOException : Exception { + internal IOException() : base() { + } + + internal IOException(string message) : base(message) { + } + + internal string getMessage() { + return Message; + } + } +} + diff --git a/dotnet/Mammoth/Couscous/java/io/InputStream.cs b/dotnet/Mammoth/Couscous/java/io/InputStream.cs new file mode 100644 index 0000000..9609a2b --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/io/InputStream.cs @@ -0,0 +1,5 @@ +namespace Mammoth.Couscous.java.io { + internal interface InputStream { + + } +} diff --git a/dotnet/Mammoth/Couscous/java/lang/IndexOutOfBoundsException.cs b/dotnet/Mammoth/Couscous/java/lang/IndexOutOfBoundsException.cs new file mode 100644 index 0000000..c56c7c1 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/IndexOutOfBoundsException.cs @@ -0,0 +1,7 @@ +using System; + +namespace Mammoth.Couscous.java.lang { + internal class IndexOutOfBoundsException : RuntimeException { + } +} + diff --git a/dotnet/Mammoth/Couscous/java/lang/RuntimeException.cs b/dotnet/Mammoth/Couscous/java/lang/RuntimeException.cs new file mode 100644 index 0000000..cf882aa --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/RuntimeException.cs @@ -0,0 +1,13 @@ +using System; + +namespace Mammoth.Couscous.java.lang +{ + internal class RuntimeException : Exception { + internal RuntimeException() : base() { + } + + internal RuntimeException(string message) : base(message) { + } + } +} + diff --git a/dotnet/Mammoth/Couscous/java/lang/String.cs b/dotnet/Mammoth/Couscous/java/lang/String.cs new file mode 100644 index 0000000..bd0838d --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/String.cs @@ -0,0 +1,7 @@ +namespace Mammoth.Couscous.java.lang { + internal partial class String { + internal static string join(string separator, Iterable values) { + return string.Join(separator, FromJava.IterableToEnumerable(values)); + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs b/dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs new file mode 100644 index 0000000..c894936 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs @@ -0,0 +1,14 @@ +namespace Mammoth.Couscous.java.lang { + internal class StringBuilder { + private readonly System.Text.StringBuilder _builder = new System.Text.StringBuilder(); + + internal StringBuilder append(string value) { + _builder.Append(value); + return this; + } + + internal string toString() { + return _builder.ToString(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/lang/UnsupportedOperationException.cs b/dotnet/Mammoth/Couscous/java/lang/UnsupportedOperationException.cs new file mode 100644 index 0000000..da86874 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/UnsupportedOperationException.cs @@ -0,0 +1,7 @@ +using System; + +namespace Mammoth.Couscous.java.lang { + internal class UnsupportedOperationException : RuntimeException { + } +} + diff --git a/dotnet/Mammoth/Couscous/java/nio/file/Path.cs b/dotnet/Mammoth/Couscous/java/nio/file/Path.cs new file mode 100644 index 0000000..6c85cc8 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/nio/file/Path.cs @@ -0,0 +1,9 @@ +using System; + +namespace Mammoth.Couscous.java.nio.file +{ + internal class Path + { + } +} + 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 : List { + private readonly System.Collections.Generic.IList _list; + + internal ArrayList() : this(new System.Collections.Generic.List()) { + } + + internal ArrayList(System.Collections.Generic.IList list) { + _list = list; + } + + public Iterator 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 : Iterable { + 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 : Map { + private readonly IDictionary _dictionary; + + internal HashMap() : this(new Dictionary()) { + } + + internal HashMap(IDictionary dictionary) { + _dictionary = dictionary; + } + + public void put(TKey key, TValue value) { + _dictionary[key] = value; + } + + public bool containsKey(TKey key) { + return _dictionary.ContainsKey(key); + } + + public Set> entrySet() { + return new EntrySet(_dictionary); + } + + public Optional _lookup(TKey key) { + if (_dictionary.ContainsKey(key)) { + return new Some(_dictionary[key]); + } else { + return new None(); + } + } + + public IDictionary AsDictionary() { + 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(); + } + } + } +} 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 : Set { + private readonly ISet _set; + + internal HashSet() : this(new System.Collections.Generic.HashSet()) { + } + + internal HashSet(ISet set) { + _set = set; + } + + public Iterator 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 : Collection { + 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 { + void put(K key, V value); + bool containsKey(K key); + Set> entrySet(); + + Optional _lookup(K key); + System.Collections.Generic.IDictionary AsDictionary(); + } + + internal interface Map__Entry { + 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 + { + bool isPresent(); + Optional map(Function function); + Optional flatMap(Function> function); + T orElse(T value); + T orElseGet(Supplier supplier); + T orElseThrow(Supplier exceptionSupplier) where TException : Exception; + T get(); + void ifPresent(Consumer consumer); + } + + internal class None : Optional { + public bool isPresent() { + return false; + } + + public Optional map(Function function) { + return new None(); + } + + public Optional flatMap(Function> function) { + return new None(); + } + + public T orElse(T value) { + return value; + } + + public T orElseGet(Supplier supplier) { + return supplier.get(); + } + + public T orElseThrow(Supplier exceptionSupplier) where TException : Exception { + throw exceptionSupplier.get(); + } + + public T get() { + throw new NoSuchElementException(); + } + + public void ifPresent(Consumer consumer) { + } + } + + internal class Some : Optional { + private readonly T _value; + + internal Some(T value) { + _value = value; + } + + public bool isPresent() { + return true; + } + + public Optional map(Function function) { + return new Some(function.apply(_value)); + } + + public Optional flatMap(Function> function) { + return function.apply(_value); + } + + public T orElse(T value) { + return _value; + } + + public T orElseGet(Supplier supplier) { + return _value; + } + + public T orElseThrow(Supplier exceptionSupplier) where TException : Exception { + return _value; + } + + public T get() { + return _value; + } + + public void ifPresent(Consumer consumer) { + consumer.accept(_value); + } + } + + internal static class Optional + { + internal static Optional empty() + { + return new None(); + } + + internal static Optional of(T value) + { + return new Some (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 : Collection { + } +} 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 { + 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 { + 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 { + 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 { + 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 { + 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 get(); + } +} \ No newline at end of file -- cgit v1.2.3