diff options
Diffstat (limited to 'dotnet/Mammoth')
42 files changed, 1073 insertions, 0 deletions
diff --git a/dotnet/Mammoth/Couscous/Adapters.cs b/dotnet/Mammoth/Couscous/Adapters.cs new file mode 100644 index 0000000..a613473 --- /dev/null +++ b/dotnet/Mammoth/Couscous/Adapters.cs @@ -0,0 +1,86 @@ +using System.Collections.Generic; +using System.Linq; +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; + +namespace Mammoth.Couscous { + internal static class FromJava { + internal static IEnumerable<T> IterableToEnumerable<T>(Iterable<T> iterable) { + Iterator<T> iterator = iterable.iterator(); + while (iterator.hasNext()) { + yield return iterator.next(); + } + } + + internal static IDictionary<TKey, TValue> MapToDictionary<TKey, TValue>(Map<TKey, TValue> map) { + return map.AsDictionary(); + } + } + + internal static class ToJava { + internal static Iterable<T> EnumerableToIterable<T>(IEnumerable<T> enumerator) { + return new IterableWrapper<T>(enumerator); + } + + private class IterableWrapper<T> : Iterable<T> { + private readonly IEnumerable<T> _enumerable; + + internal IterableWrapper(IEnumerable<T> enumerable) { + _enumerable = enumerable; + } + + public Iterator<T> iterator() { + return EnumeratorToIterator(_enumerable.GetEnumerator()); + } + } + + internal static Iterator<T> EnumeratorToIterator<T>(IEnumerator<T> enumerator) { + return new EnumeratorToIteratorAdapter<T>(enumerator); + } + + private class EnumeratorToIteratorAdapter<T> : Iterator<T> { + private readonly IEnumerator<T> _enumerator; + private bool _ready; + private bool _hasNext; + + internal EnumeratorToIteratorAdapter(IEnumerator<T> enumerator) { + _enumerator = enumerator; + _ready = false; + } + + public bool hasNext() { + MakeReady(); + return _hasNext; + } + + public T next() { + MakeReady(); + if (_hasNext) { + _ready = false; + return _enumerator.Current; + } else { + throw new NoSuchElementException(); + } + } + + private void MakeReady() { + if (!_ready) { + MoveNext(); + } + } + + private void MoveNext() { + _hasNext = _enumerator.MoveNext(); + _ready = true; + } + } + + internal static Map<TKey, TValue> DictionaryToMap<TKey, TValue>(IDictionary<TKey, TValue> dictionary) { + return new HashMap<TKey, TValue>(dictionary); + } + + internal static java.util.List<T> ListToList<T>(IList<T> list) { + return new ArrayList<T>(list); + } + } +} diff --git a/dotnet/Mammoth/Couscous/HorribleHacks.cs b/dotnet/Mammoth/Couscous/HorribleHacks.cs new file mode 100644 index 0000000..88c746b --- /dev/null +++ b/dotnet/Mammoth/Couscous/HorribleHacks.cs @@ -0,0 +1,21 @@ +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.org.zwobble.mammoth.@internal.documents; +using System.Linq; + +namespace Mammoth.Couscous { + internal static class HorribleHacks { + internal static bool equals(this Optional<string> first, Optional<string> second) { + return (!first.isPresent() && !second.isPresent()) || (first.isPresent() && second.isPresent() && first.get() == second.get()); + } + + internal static bool equals(this Map<string, string> firstMap, Map<string, string> secondMap) { + var first = FromJava.MapToDictionary(firstMap); + var second = FromJava.MapToDictionary(secondMap); + return first.Count == second.Count && first.All(item => second.ContainsKey(item.Key) && second[item.Key] == item.Value); + } + + internal static bool equals(this NoteType first, NoteType second) { + return first == second; + } + } +} diff --git a/dotnet/Mammoth/Couscous/IterableExtensions.cs b/dotnet/Mammoth/Couscous/IterableExtensions.cs new file mode 100644 index 0000000..bac0b43 --- /dev/null +++ b/dotnet/Mammoth/Couscous/IterableExtensions.cs @@ -0,0 +1,13 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util.function; + +namespace Mammoth.Couscous { + internal static class IterableExtensions { + public static void forEach<T>(this Iterable<T> iterable, Consumer<T> consumer) { + var iterator = iterable.iterator(); + while (iterator.hasNext()) { + consumer.accept(iterator.next()); + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/JavaStringExtensions.cs b/dotnet/Mammoth/Couscous/JavaStringExtensions.cs new file mode 100644 index 0000000..429bc7d --- /dev/null +++ b/dotnet/Mammoth/Couscous/JavaStringExtensions.cs @@ -0,0 +1,17 @@ +using System; + +namespace Mammoth.Couscous { + internal static class JavaStringExtensions { + internal static bool equalsIgnoreCase(this string first, string second) { + return first.Equals(second, StringComparison.InvariantCultureIgnoreCase); + } + + internal static string replace(this string original, string search, string replacement) { + return original.Replace(search, replacement); + } + + internal static bool isEmpty(this string value) { + return value.Length == 0; + } + } +} 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<string> 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<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 diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/docx/PathRelativeFileReader.cs b/dotnet/Mammoth/Couscous/mammoth/internal/docx/PathRelativeFileReader.cs new file mode 100644 index 0000000..b581e9d --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/docx/PathRelativeFileReader.cs @@ -0,0 +1,17 @@ +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.io; +using Mammoth.Couscous.java.nio.file; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.docx { + internal class PathRelativeFileReader : FileReader { + private readonly Optional<Path> _path; + + internal PathRelativeFileReader(Optional<Path> path) { + _path = path; + } + + public InputStream getInputStream(string uri) { + throw new System.NotImplementedException(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/styles/parsing/StyleMapParser.cs b/dotnet/Mammoth/Couscous/mammoth/internal/styles/parsing/StyleMapParser.cs new file mode 100644 index 0000000..44d1ddd --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/styles/parsing/StyleMapParser.cs @@ -0,0 +1,14 @@ +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.org.zwobble.mammoth.@internal.styles; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.styles.parsing { + internal static class StyleMapParser { + internal static StyleMap parseStyleMappings(List<string> mappings) { + return StyleMap.builder().build(); + } + + internal static StyleMap parse(string styleMap) { + return StyleMap.builder().build(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Base64Encoding.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Base64Encoding.cs new file mode 100644 index 0000000..f8270b0 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Base64Encoding.cs @@ -0,0 +1,10 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.io; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Base64Encoding { + internal static string streamToBase64(SupplierWithException<InputStream, IOException> stream) { + throw new UnsupportedOperationException(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Casts.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Casts.cs new file mode 100644 index 0000000..c342e20 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Casts.cs @@ -0,0 +1,13 @@ +using Mammoth.Couscous.java.util; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Casts { + internal static Optional<T> tryCast<T>(System.Type type, object value) { + if (value is T) { + return new Some<T>((T) value); + } else { + return new None<T>(); + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Iterables.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Iterables.cs new file mode 100644 index 0000000..b1e1477 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Iterables.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.Linq; +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.util.function; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util +{ + internal static class Iterables + { + internal static T getFirst<T>(Iterable<T> iterable, T defaultValue) { + var iterator = iterable.iterator(); + if (iterator.hasNext()) { + return iterator.next(); + } else { + return defaultValue; + } + } + + internal static Optional<T> tryFind<T>(Iterable<T> iterable, Predicate<T> predicate) { + var iterator = iterable.iterator(); + while (iterator.hasNext()) { + T value = iterator.next(); + if (predicate.test(value)) { + return new Some<T>(value); + } + } + return new None<T>(); + } + + internal static Iterable<T> lazyFilter<T>(Iterable<T> iterable, Predicate<T> predicate) { + var enumerable = FromJava.IterableToEnumerable(iterable).Where(predicate.test); + return ToJava.EnumerableToIterable(enumerable); + } + + internal static Iterable<U> lazyFilter<T, U>(Iterable<T> iterable, System.Type type) { + var enumerable = FromJava.IterableToEnumerable(iterable).OfType<U>(); + return ToJava.EnumerableToIterable(enumerable); + } + + internal static Iterable<U> lazyMap<T, U>(Iterable<T> iterable, Function<T, U> function) { + var enumerable = FromJava.IterableToEnumerable(iterable) + .Select(function.apply); + return ToJava.EnumerableToIterable(enumerable); + } + + internal static Iterable<U> lazyFlatMap<T, U>(Iterable<T> iterable, Function<T, Iterable<U>> function) { + var enumerable = FromJava.IterableToEnumerable(iterable) + .SelectMany(element => FromJava.IterableToEnumerable(function.apply(element))); + return ToJava.EnumerableToIterable(enumerable); + } + + internal static Iterable<T> lazyConcat<T>(Iterable<T> first, Iterable<T> second) { + var enumerable = FromJava.IterableToEnumerable(first) + .Concat(FromJava.IterableToEnumerable(second)); + return ToJava.EnumerableToIterable(enumerable); + } + } +} + diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs new file mode 100644 index 0000000..b914a34 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs @@ -0,0 +1,97 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.util.function; +using System.Linq; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Lists { + internal static List<T> list<T>(params T[] values) { + return ToJava.ListToList(values); + } + + internal static List<T> toList<T>(Iterable<T> iterable) { + return ToJava.ListToList(FromJava.IterableToEnumerable(iterable).ToList()); + } + + internal static List<U> eagerMap<T, U>(Iterable<T> iterable, Function<T, U> function) { + var result = FromJava.IterableToEnumerable(iterable) + .Select(function.apply) + .ToList(); + return ToJava.ListToList(result); + } + + internal static List<U> eagerFlatMap<T, U>(Iterable<T> iterable, Function<T, Iterable<U>> function) { + var result = FromJava.IterableToEnumerable(iterable) + .SelectMany(element => FromJava.IterableToEnumerable(function.apply(element))) + .ToList(); + return ToJava.ListToList(result); + } + + internal static List<T> cons<T>(T head, Iterable<T> tail) { + var result = new T[] { head } + .Concat(FromJava.IterableToEnumerable(tail)) + .ToList(); + return ToJava.ListToList(result); + } + + internal static List<T> eagerConcat<T>(Iterable<T> first, Iterable<T> second) { + var result = FromJava.IterableToEnumerable(first) + .Concat(FromJava.IterableToEnumerable(second)) + .ToList(); + return ToJava.ListToList(result); + } + + internal static List<T> orderedBy<T, R>(Iterable<T> iterable, Function<T, R> getKey) { + var result = FromJava.IterableToEnumerable(iterable) + .OrderBy(getKey.apply) + .ToList(); + return ToJava.ListToList(result); + } + + internal static Optional<T> tryGetLast<T>(List<T> list) { + if (list.isEmpty()) { + return new None<T>(); + } else { + return new Some<T>(list.get(list.size() - 1)); + } + } + + internal static Iterable<T> reversed<T>(List<T> list) { + return new ReversedList<T>(list); + } + + private class ReversedList<T> : Iterable<T> { + private readonly List<T> _list; + + internal ReversedList(List<T> list) { + _list = list; + } + + public Iterator<T> iterator() { + return new ReverseIterator<T>(_list); + } + } + + private class ReverseIterator<T> : Iterator<T> { + private readonly List<T> _list; + private int _nextIndex; + + internal ReverseIterator(List<T> list) { + _list = list; + _nextIndex = _list.size() - 1; + } + + public bool hasNext() { + return _nextIndex >= 0; + } + + public T next() { + if (hasNext()) { + return _list.get(_nextIndex--); + } else { + throw new NoSuchElementException(); + } + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Maps.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Maps.cs new file mode 100644 index 0000000..bee2dac --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Maps.cs @@ -0,0 +1,110 @@ +using System.Linq; +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util.function; +using Mammoth.Couscous; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util +{ + internal static class Maps + { + internal static Map<K, V> map<K, V>() { + return ToJava.DictionaryToMap(new System.Collections.Generic.Dictionary<K, V>()); + } + + internal static Map<K, V> map<K, V>(K key1, V value1) { + return ToJava.DictionaryToMap(new System.Collections.Generic.Dictionary<K, V> { + {key1, value1} + }); + } + + internal static Map<K, V> map<K, V>(K key1, V value1, K key2, V value2) { + return ToJava.DictionaryToMap(new System.Collections.Generic.Dictionary<K, V> { + {key1, value1}, + {key2, value2} + }); + } + + internal static Map<K, V> toMap<T, K, V>(Iterable<T> iterable, Function<T, Map__Entry<K, V>> function) { + var dictionary = FromJava.IterableToEnumerable(iterable) + .Select(function.apply) + .ToDictionary(entry => entry.getKey(), entry => entry.getValue()); + return ToJava.DictionaryToMap(dictionary); + + } + + internal static Map<K, T> toMapWithKey<T, K>(Iterable<T> iterable, Function<T, K> function) { + var dictionary = FromJava.IterableToEnumerable(iterable) + .ToDictionary(function.apply); + return ToJava.DictionaryToMap(dictionary); + } + + internal static Map<K, java.util.List<T>> toMultiMapWithKey<T, K>(Iterable<T> iterable, Function<T, K> function) { + var dictionary = FromJava.IterableToEnumerable(iterable) + .GroupBy(value => function.apply(value)) + .ToDictionary( + grouping => grouping.Key, + grouping => ToJava.ListToList(grouping.ToList())); + return ToJava.DictionaryToMap(dictionary); + } + + internal static Optional<V> lookup<K, V>(Map<K, V> map, K key) { + return map._lookup(key); + } + + internal static Map<K2, V> eagerMapKeys<K1, K2, V>(Map<K1, V> map, Function<K1, K2> function) { + var dictionary = FromJava.MapToDictionary(map) + .ToDictionary( + entry => function.apply(entry.Key), + entry => entry.Value); + return ToJava.DictionaryToMap(dictionary); + } + + internal static Map<K, V2> eagerMapValues<K, V1, V2>(Map<K, V1> map, Function<V1, V2> function) { + var dictionary = FromJava.MapToDictionary(map) + .ToDictionary( + entry => entry.Key, + entry => function.apply(entry.Value)); + return ToJava.DictionaryToMap(dictionary); + } + + internal static Map__Entry<K, V> entry<K, V>(K key, V value) { + return new Entry<K, V>(key, value); + } + + private class Entry<K, V> : Map__Entry<K, V> { + private readonly K _key; + private readonly V _value; + + internal Entry(K key, V value) { + this._key = key; + this._value = value; + } + + public K getKey() { + return _key; + } + + public V getValue() { + return _value; + } + } + + internal static Builder<K, V> builder<K, V>() { + return new Builder<K, V>(); + } + + internal class Builder<K, V> { + private readonly System.Collections.Generic.IDictionary<K, V> _values = new System.Collections.Generic.Dictionary<K, V>(); + + internal Builder<K, V> put(K key, V value) { + _values[key] = value; + return this; + } + + internal Map<K, V> build() { + return ToJava.DictionaryToMap(_values); + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/PassThroughException.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/PassThroughException.cs new file mode 100644 index 0000000..4bd2a2a --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/PassThroughException.cs @@ -0,0 +1,21 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.io; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal class PassThroughException : RuntimeException { + internal static T wrap<T>(SupplierWithException<T, IOException> supplier) { + try { + return supplier.get(); + } catch (IOException exception) { + throw new PassThroughException(exception); + } + } + + private readonly IOException _exception; + + internal PassThroughException(IOException exception) { + _exception = exception; + } + } +} + diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Paths.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Paths.cs new file mode 100644 index 0000000..ca876eb --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Paths.cs @@ -0,0 +1,8 @@ +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Paths { + internal static string getExtension(string path) { + int dotIndex = path.LastIndexOf('.'); + return dotIndex == -1 ? "" : path.Substring(dotIndex + 1); + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Sets.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Sets.cs new file mode 100644 index 0000000..7843537 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Sets.cs @@ -0,0 +1,19 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.nio.file; +using System; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util +{ + internal static class Sets + { + internal static Set<T> set<T>(T[] values) { + return new HashSet<T>(new System.Collections.Generic.HashSet<T>(values)); + } + + internal static Set<T> toSet<T>(Iterable<T> iterable) { + return new HashSet<T>(new System.Collections.Generic.HashSet<T>(FromJava.IterableToEnumerable(iterable))); + } + } +} + diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Strings.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Strings.cs new file mode 100644 index 0000000..65f5e0b --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Strings.cs @@ -0,0 +1,18 @@ +using System; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Strings { + internal static string trimLeft(string value, int character) { + int index = 0; + while (index < value.Length && value[index] == character) { + index++; + } + return value.Substring(index); + } + + internal static bool isNullOrEmpty(string value) { + return string.IsNullOrEmpty(value); + } + } +} + diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs b/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs new file mode 100644 index 0000000..8ebdf28 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs @@ -0,0 +1,13 @@ +using Mammoth.Couscous.java.io; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.xml.parsing { + internal static class SimpleSax { + internal static void parseStream(InputStream input, SimpleSaxHandler handler) { + throw new System.NotImplementedException(); + } + + internal static void parseString(string value, SimpleSaxHandler handler) { + throw new System.NotImplementedException(); + } + } +} diff --git a/dotnet/Mammoth/Mammoth.csproj b/dotnet/Mammoth/Mammoth.csproj new file mode 100644 index 0000000..ac380f8 --- /dev/null +++ b/dotnet/Mammoth/Mammoth.csproj @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{51C5CBD6-8809-4D5E-BABE-1787A16F5ED8}</ProjectGuid> + <OutputType>Library</OutputType> + <RootNamespace>Mammoth</RootNamespace> + <AssemblyName>Mammoth</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug</OutputPath> + <DefineConstants>DEBUG;</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <ConsolePause>false</ConsolePause> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>full</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release</OutputPath> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <ConsolePause>false</ConsolePause> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="generated.cs" /> + <Compile Include="Couscous\Adapters.cs" /> + <Compile Include="Couscous\HorribleHacks.cs" /> + <Compile Include="Couscous\IterableExtensions.cs" /> + <Compile Include="Couscous\JavaStringExtensions.cs" /> + <Compile Include="Couscous\java\io\InputStream.cs" /> + <Compile Include="Couscous\java\io\IOException.cs" /> + <Compile Include="Couscous\java\io\Closeable.cs" /> + <Compile Include="Couscous\java\nio\file\Path.cs" /> + <Compile Include="Couscous\java\lang\IndexOutOfBoundsException.cs" /> + <Compile Include="Couscous\java\lang\RuntimeException.cs" /> + <Compile Include="Couscous\java\lang\String.cs" /> + <Compile Include="Couscous\java\lang\StringBuilder.cs" /> + <Compile Include="Couscous\java\lang\UnsupportedOperationException.cs" /> + <Compile Include="Couscous\java\util\function\BiFunction.cs" /> + <Compile Include="Couscous\java\util\function\BiPredicate.cs" /> + <Compile Include="Couscous\java\util\function\Consumer.cs" /> + <Compile Include="Couscous\java\util\function\Function.cs" /> + <Compile Include="Couscous\java\util\function\Predicate.cs" /> + <Compile Include="Couscous\java\util\function\Supplier.cs" /> + <Compile Include="Couscous\java\util\ArrayList.cs" /> + <Compile Include="Couscous\java\util\Collection.cs" /> + <Compile Include="Couscous\java\util\HashMap.cs" /> + <Compile Include="Couscous\java\util\HashSet.cs" /> + <Compile Include="Couscous\java\util\List.cs" /> + <Compile Include="Couscous\java\util\Map.cs" /> + <Compile Include="Couscous\java\util\NoSuchElementException.cs" /> + <Compile Include="Couscous\java\util\Optional.cs" /> + <Compile Include="Couscous\java\util\Set.cs" /> + <Compile Include="Couscous\mammoth\internal\docx\PathRelativeFileReader.cs" /> + <Compile Include="Couscous\mammoth\internal\styles\parsing\StyleMapParser.cs" /> + <Compile Include="Couscous\mammoth\internal\util\Base64Encoding.cs" /> + <Compile Include="Couscous\mammoth\internal\util\Casts.cs" /> + <Compile Include="Couscous\mammoth\internal\util\Lists.cs" /> + <Compile Include="Couscous\mammoth\internal\util\Maps.cs" /> + <Compile Include="Couscous\mammoth\internal\util\Paths.cs" /> + <Compile Include="Couscous\mammoth\internal\util\PassThroughException.cs" /> + <Compile Include="Couscous\mammoth\internal\util\Sets.cs" /> + <Compile Include="Couscous\mammoth\internal\util\Strings.cs" /> + <Compile Include="Couscous\mammoth\internal\util\Iterables.cs" /> + <Compile Include="Couscous\mammoth\internal\xml\parsing\SimpleSax.cs" /> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <ItemGroup> + <Folder Include="Couscous\" /> + <Folder Include="Couscous\java\" /> + <Folder Include="Couscous\mammoth\" /> + <Folder Include="Couscous\mammoth\internal\" /> + <Folder Include="Couscous\mammoth\internal\util\" /> + <Folder Include="Couscous\java\nio\" /> + <Folder Include="Couscous\java\nio\file\" /> + </ItemGroup> +</Project> diff --git a/dotnet/Mammoth/Properties/AssemblyInfo.cs b/dotnet/Mammoth/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6ef611f --- /dev/null +++ b/dotnet/Mammoth/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("Mammoth")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("mick")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + |
