From 14ac28c468ca81b645cabf21552748a46f7b21e2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 10 Jun 2024 15:21:00 +0100 Subject: Update java-mammoth --- Mammoth/Couscous/java/util/AbstractMap.cs | 9 ++++--- Mammoth/Couscous/java/util/ArrayList.cs | 33 ++++++++++++++---------- Mammoth/Couscous/java/util/HashMap.cs | 40 +++++++++++++++++------------ Mammoth/Couscous/java/util/List.cs | 1 + Mammoth/Couscous/java/util/Map.cs | 7 ++--- Mammoth/Couscous/java/util/regex/Pattern.cs | 12 ++++++--- 6 files changed, 61 insertions(+), 41 deletions(-) (limited to 'Mammoth/Couscous/java') diff --git a/Mammoth/Couscous/java/util/AbstractMap.cs b/Mammoth/Couscous/java/util/AbstractMap.cs index f619267..86e4629 100644 --- a/Mammoth/Couscous/java/util/AbstractMap.cs +++ b/Mammoth/Couscous/java/util/AbstractMap.cs @@ -12,7 +12,7 @@ namespace Mammoth.Couscous.java.util { return Equals(otherMap); } } - + public bool Equals(Map other) { var first = AsUntypedDictionary(); var second = other.AsUntypedDictionary(); @@ -20,16 +20,17 @@ namespace Mammoth.Couscous.java.util { first.Count == second.Count && first.Keys.Cast().All(key => second.Contains(key) && first[key].Equals(second[key])); } - + public override int GetHashCode() { throw new System.NotSupportedException(); } - + public abstract void put(TKey key, TValue value); + public abstract void putAll(Map other); public abstract bool containsKey(TKey key); public abstract Set> entrySet(); public abstract Collection values(); - + public abstract Optional _lookup(TKey key); public abstract System.Collections.Generic.IDictionary AsDictionary(); public abstract System.Collections.IDictionary AsUntypedDictionary(); diff --git a/Mammoth/Couscous/java/util/ArrayList.cs b/Mammoth/Couscous/java/util/ArrayList.cs index 2bd3031..2e6d736 100644 --- a/Mammoth/Couscous/java/util/ArrayList.cs +++ b/Mammoth/Couscous/java/util/ArrayList.cs @@ -4,33 +4,33 @@ 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; } - + internal ArrayList(List list) : this(new System.Collections.Generic.List(FromJava.IterableToEnumerable(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(); @@ -38,7 +38,7 @@ namespace Mammoth.Couscous.java.util { return _list[index]; } } - + public List subList(int fromIndex, int toIndex) { var list = _list as System.Collections.Generic.List; if (list == null) { @@ -47,21 +47,28 @@ namespace Mammoth.Couscous.java.util { return new ArrayList(list.GetRange(fromIndex, toIndex - fromIndex)); } } - + public void add(T value) { _list.Add(value); } - + + public void addAll(List other) { + var iterator = other.iterator(); + while (iterator.hasNext()) { + add(iterator.next()); + } + } + public T remove(int index) { T value = _list[index]; _list.RemoveAt(index); return value; } - + public void set(int index, T value) { _list[index] = value; } - + public void clear() { _list.Clear(); } diff --git a/Mammoth/Couscous/java/util/HashMap.cs b/Mammoth/Couscous/java/util/HashMap.cs index 13383a8..bc54490 100644 --- a/Mammoth/Couscous/java/util/HashMap.cs +++ b/Mammoth/Couscous/java/util/HashMap.cs @@ -6,33 +6,39 @@ using Mammoth.Couscous.java.lang; namespace Mammoth.Couscous.java.util { internal class HashMap : AbstractMap { private readonly Dictionary _dictionary; - + internal HashMap() : this(new Dictionary()) { } - + internal HashMap(Dictionary dictionary) { _dictionary = dictionary; } - + internal HashMap(Map map) : this(new Dictionary(map.AsDictionary())) { } - + public override void put(TKey key, TValue value) { _dictionary[key] = value; } - + + public override void putAll(Map other) { + foreach (var pair in other.AsDictionary()) { + _dictionary[pair.Key] = pair.Value; + } + } + public override bool containsKey(TKey key) { return _dictionary.ContainsKey(key); } - + public override Set> entrySet() { return new EntrySet(_dictionary); } - + public override Collection values() { return ToJava.CollectionToCollection(_dictionary.Values); } - + public override Optional _lookup(TKey key) { if (_dictionary.ContainsKey(key)) { return new Some(_dictionary[key]); @@ -40,38 +46,38 @@ namespace Mammoth.Couscous.java.util { return None.Instance; } } - + public override IDictionary AsDictionary() { return _dictionary; } - + public override System.Collections.IDictionary AsUntypedDictionary() { 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/Mammoth/Couscous/java/util/List.cs b/Mammoth/Couscous/java/util/List.cs index 5082968..446d784 100644 --- a/Mammoth/Couscous/java/util/List.cs +++ b/Mammoth/Couscous/java/util/List.cs @@ -4,6 +4,7 @@ namespace Mammoth.Couscous.java.util { interface List : Collection { T get(int index); List subList(int fromIndex, int toIndex); + void addAll(List other); T remove(int index); void set(int index, T value); void clear(); diff --git a/Mammoth/Couscous/java/util/Map.cs b/Mammoth/Couscous/java/util/Map.cs index 0d3eaf7..723ce46 100644 --- a/Mammoth/Couscous/java/util/Map.cs +++ b/Mammoth/Couscous/java/util/Map.cs @@ -2,17 +2,18 @@ namespace Mammoth.Couscous.java.util { internal interface Map { System.Collections.IDictionary AsUntypedDictionary(); } - + internal interface Map : Map { void put(K key, V value); + void putAll(Map other); bool containsKey(K key); Set> entrySet(); Collection values(); - + Optional _lookup(K key); System.Collections.Generic.IDictionary AsDictionary(); } - + internal interface Map__Entry { K getKey(); V getValue(); diff --git a/Mammoth/Couscous/java/util/regex/Pattern.cs b/Mammoth/Couscous/java/util/regex/Pattern.cs index 42277ae..64ccc37 100644 --- a/Mammoth/Couscous/java/util/regex/Pattern.cs +++ b/Mammoth/Couscous/java/util/regex/Pattern.cs @@ -5,19 +5,23 @@ namespace Mammoth.Couscous.java.util.regex { internal static Pattern compile(string pattern) { return new Pattern(pattern, new Regex(pattern)); } - + + internal static bool matches(string regex, string input) { + return Regex.IsMatch(input, regex); + } + private readonly string _pattern; private readonly Regex _regex; - + internal Pattern(string pattern, Regex regex) { _pattern = pattern; _regex = regex; } - + internal string pattern() { return _pattern; } - + internal Matcher matcher(string value) { return new Matcher(_regex, value); } -- cgit v1.2.3