diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-06-17 21:55:57 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-06-17 21:55:57 +0100 |
| commit | 8b2845269ec07da3c506c9bb41f673b59053e1aa (patch) | |
| tree | 2c9086008d37f65501fb90f043f4eee2b2b9fe83 /Mammoth/Couscous | |
| parent | 117e22cdd0d6b20968fc39e2c8e1a7e6c73e9e73 (diff) | |
Update java-mammoth
Diffstat (limited to 'Mammoth/Couscous')
| -rw-r--r-- | Mammoth/Couscous/mammoth/internal/util/Iterables.cs | 9 | ||||
| -rw-r--r-- | Mammoth/Couscous/mammoth/internal/util/Lists.cs | 7 | ||||
| -rw-r--r-- | Mammoth/Couscous/mammoth/internal/util/Maps.cs | 15 |
3 files changed, 31 insertions, 0 deletions
diff --git a/Mammoth/Couscous/mammoth/internal/util/Iterables.cs b/Mammoth/Couscous/mammoth/internal/util/Iterables.cs index ac571bc..09b683c 100644 --- a/Mammoth/Couscous/mammoth/internal/util/Iterables.cs +++ b/Mammoth/Couscous/mammoth/internal/util/Iterables.cs @@ -8,6 +8,15 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { internal static class Iterables { + internal static Optional<T> getFirst<T>(Iterable<T> iterable) { + var iterator = iterable.iterator(); + if (iterator.hasNext()) { + return Optional.of(iterator.next()); + } else { + return Optional.empty<T>(); + } + } + internal static T getFirst<T>(Iterable<T> iterable, T defaultValue) { var iterator = iterable.iterator(); if (iterator.hasNext()) { diff --git a/Mammoth/Couscous/mammoth/internal/util/Lists.cs b/Mammoth/Couscous/mammoth/internal/util/Lists.cs index db18a21..18c14f3 100644 --- a/Mammoth/Couscous/mammoth/internal/util/Lists.cs +++ b/Mammoth/Couscous/mammoth/internal/util/Lists.cs @@ -20,6 +20,13 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { return ToJava.ListToList(result); } + internal static List<U> eagerMap<T, U>(Iterable<T> iterable, BiFunction<int, T, U> function) { + var result = FromJava.IterableToEnumerable(iterable) + .Select((value, index) => function.apply(index, value)) + .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))) diff --git a/Mammoth/Couscous/mammoth/internal/util/Maps.cs b/Mammoth/Couscous/mammoth/internal/util/Maps.cs index bee2dac..54128b0 100644 --- a/Mammoth/Couscous/mammoth/internal/util/Maps.cs +++ b/Mammoth/Couscous/mammoth/internal/util/Maps.cs @@ -88,6 +88,21 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util public V getValue() { return _value; } + + public override bool Equals(object otherObj) { + var other = otherObj as Entry<K, V>; + if (other == null) { + return false; + } else if (object.ReferenceEquals(this, other)) { + return true; + } else { + return _key.Equals(other._key) && _value.Equals(other._value); + } + } + + public override int GetHashCode() { + return _key.GetHashCode() * 17 + _value.GetHashCode(); + } } internal static Builder<K, V> builder<K, V>() { |
