diff options
| author | Michael Williamson <mike@zwobble.org> | 2018-01-28 12:36:26 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2018-01-28 12:36:26 +0000 |
| commit | 56e424be69f5728d36ed59509284e6592ee374ce (patch) | |
| tree | c66d20ce4bb0d68518bf7d5fff839913f0fe4866 /Mammoth/Couscous | |
| parent | c5f9b5e6971da9611b599991858e9c4dd23ee008 (diff) | |
Update java-mammoth
Diffstat (limited to 'Mammoth/Couscous')
| -rw-r--r-- | Mammoth/Couscous/JavaStringExtensions.cs | 8 | ||||
| -rw-r--r-- | Mammoth/Couscous/java/util/ArrayList.cs | 13 | ||||
| -rw-r--r-- | Mammoth/Couscous/java/util/List.cs | 2 | ||||
| -rw-r--r-- | Mammoth/Couscous/java/util/OptionalInt.cs | 9 | ||||
| -rw-r--r-- | Mammoth/Couscous/java/util/function/IntFunction.cs | 5 | ||||
| -rw-r--r-- | Mammoth/Couscous/mammoth/internal/archives/ZippedArchive.cs | 4 | ||||
| -rw-r--r-- | Mammoth/Couscous/mammoth/internal/util/Lists.cs | 15 | ||||
| -rw-r--r-- | Mammoth/Couscous/mammoth/internal/util/Maps.cs | 18 |
8 files changed, 73 insertions, 1 deletions
diff --git a/Mammoth/Couscous/JavaStringExtensions.cs b/Mammoth/Couscous/JavaStringExtensions.cs index bf4e73f..13b4483 100644 --- a/Mammoth/Couscous/JavaStringExtensions.cs +++ b/Mammoth/Couscous/JavaStringExtensions.cs @@ -29,5 +29,13 @@ namespace Mammoth.Couscous { internal static string[] split(this string value, string separator) { return System.Text.RegularExpressions.Regex.Split(value, separator); } + + internal static int indexOf(this string value, string search) { + return value.IndexOf(search); + } + + internal static int lastIndexOf(this string value, string search) { + return value.LastIndexOf(search); + } } } diff --git a/Mammoth/Couscous/java/util/ArrayList.cs b/Mammoth/Couscous/java/util/ArrayList.cs index 81d180c..2bd3031 100644 --- a/Mammoth/Couscous/java/util/ArrayList.cs +++ b/Mammoth/Couscous/java/util/ArrayList.cs @@ -39,6 +39,15 @@ namespace Mammoth.Couscous.java.util { } } + public List<T> subList(int fromIndex, int toIndex) { + var list = _list as System.Collections.Generic.List<T>; + if (list == null) { + throw new System.NotImplementedException(); + } else { + return new ArrayList<T>(list.GetRange(fromIndex, toIndex - fromIndex)); + } + } + public void add(T value) { _list.Add(value); } @@ -52,5 +61,9 @@ namespace Mammoth.Couscous.java.util { public void set(int index, T value) { _list[index] = value; } + + public void clear() { + _list.Clear(); + } } } diff --git a/Mammoth/Couscous/java/util/List.cs b/Mammoth/Couscous/java/util/List.cs index 38641e3..5082968 100644 --- a/Mammoth/Couscous/java/util/List.cs +++ b/Mammoth/Couscous/java/util/List.cs @@ -3,7 +3,9 @@ using Mammoth.Couscous.java.lang; namespace Mammoth.Couscous.java.util { interface List<T> : Collection<T> { T get(int index); + List<T> subList(int fromIndex, int toIndex); T remove(int index); void set(int index, T value); + void clear(); } } diff --git a/Mammoth/Couscous/java/util/OptionalInt.cs b/Mammoth/Couscous/java/util/OptionalInt.cs index 4dfca2f..fb92624 100644 --- a/Mammoth/Couscous/java/util/OptionalInt.cs +++ b/Mammoth/Couscous/java/util/OptionalInt.cs @@ -6,6 +6,7 @@ namespace Mammoth.Couscous.java.util { bool isPresent(); int getAsInt(); + int orElse(int elseValue); } internal struct NoneInt : OptionalInt { @@ -18,6 +19,10 @@ namespace Mammoth.Couscous.java.util public int getAsInt() { throw new NoSuchElementException(); } + + public int orElse(int elseValue) { + return elseValue; + } } internal struct SomeInt : OptionalInt { @@ -34,5 +39,9 @@ namespace Mammoth.Couscous.java.util public int getAsInt() { return _value; } + + public int orElse(int elseValue) { + return _value; + } } } diff --git a/Mammoth/Couscous/java/util/function/IntFunction.cs b/Mammoth/Couscous/java/util/function/IntFunction.cs new file mode 100644 index 0000000..7190cee --- /dev/null +++ b/Mammoth/Couscous/java/util/function/IntFunction.cs @@ -0,0 +1,5 @@ +namespace Mammoth.Couscous.java.util.function { + internal interface IntFunction<R> { + R apply(int arg); + } +} diff --git a/Mammoth/Couscous/mammoth/internal/archives/ZippedArchive.cs b/Mammoth/Couscous/mammoth/internal/archives/ZippedArchive.cs index 4ebbf09..6ff10bf 100644 --- a/Mammoth/Couscous/mammoth/internal/archives/ZippedArchive.cs +++ b/Mammoth/Couscous/mammoth/internal/archives/ZippedArchive.cs @@ -23,6 +23,10 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.archives { } } + public bool exists(string name) { + return _zipFile.GetEntry(name) != null; + } + public void close() { _zipFile.Dispose(); } diff --git a/Mammoth/Couscous/mammoth/internal/util/Lists.cs b/Mammoth/Couscous/mammoth/internal/util/Lists.cs index 6f1b8be..4601b28 100644 --- a/Mammoth/Couscous/mammoth/internal/util/Lists.cs +++ b/Mammoth/Couscous/mammoth/internal/util/Lists.cs @@ -13,6 +13,13 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { return ToJava.ListToList(FromJava.IterableToEnumerable(iterable).ToList()); } + internal static List<T> eagerFilter<T>(Iterable<T> iterable, Predicate<T> function) { + var result = FromJava.IterableToEnumerable(iterable) + .Where(function.test) + .ToList(); + return ToJava.ListToList(result); + } + internal static List<U> eagerMap<T, U>(Iterable<T> iterable, Function<T, U> function) { var result = FromJava.IterableToEnumerable(iterable) .Select(function.apply) @@ -63,6 +70,14 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { return ToJava.ListToList(result); } + internal static Optional<T> tryGetFirst<T>(List<T> list) { + if (list.isEmpty()) { + return None<T>.Instance; + } else { + return new Some<T>(list.get(0)); + } + } + internal static Optional<T> tryGetLast<T>(List<T> list) { if (list.isEmpty()) { return None<T>.Instance; diff --git a/Mammoth/Couscous/mammoth/internal/util/Maps.cs b/Mammoth/Couscous/mammoth/internal/util/Maps.cs index 38964d8..0902fd3 100644 --- a/Mammoth/Couscous/mammoth/internal/util/Maps.cs +++ b/Mammoth/Couscous/mammoth/internal/util/Maps.cs @@ -46,7 +46,7 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util .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)) @@ -55,6 +55,16 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util grouping => ToJava.ListToList(grouping.ToList())); return ToJava.DictionaryToMap(dictionary); } + + internal static Map<K, java.util.List<V>> toMultiMap<T, K, V>(Iterable<T> iterable, Function<T, Map__Entry<K, V>> function) { + var dictionary = FromJava.IterableToEnumerable(iterable) + .Select(element => function.apply(element)) + .GroupBy(entry => entry.getKey()) + .ToDictionary( + grouping => grouping.Key, + grouping => ToJava.ListToList(grouping.Select(entry => entry.getValue()).ToList())); + return ToJava.DictionaryToMap(dictionary); + } internal static Optional<V> lookup<K, V>(Map<K, V> map, K key) { return map._lookup(key); @@ -129,5 +139,11 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util return ToJava.DictionaryToMap(_values); } } + + internal static Map<K, V> mutableMap<K, V>(K key1, V value1) { + var map = new HashMap<K, V>(); + map.put(key1, value1); + return map; + } } } |
