aboutsummaryrefslogtreecommitdiff
path: root/Mammoth/Couscous/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-06-10 15:21:00 +0100
committerMichael Williamson <mike@zwobble.org>2024-06-10 15:21:00 +0100
commit14ac28c468ca81b645cabf21552748a46f7b21e2 (patch)
tree917469516808b98a43b5e20c0efc712d32b963f0 /Mammoth/Couscous/java
parent7657de4df31f35408a75ea927c3141cf3ff0cee8 (diff)
Update java-mammoth
Diffstat (limited to 'Mammoth/Couscous/java')
-rw-r--r--Mammoth/Couscous/java/util/AbstractMap.cs9
-rw-r--r--Mammoth/Couscous/java/util/ArrayList.cs33
-rw-r--r--Mammoth/Couscous/java/util/HashMap.cs40
-rw-r--r--Mammoth/Couscous/java/util/List.cs1
-rw-r--r--Mammoth/Couscous/java/util/Map.cs7
-rw-r--r--Mammoth/Couscous/java/util/regex/Pattern.cs12
6 files changed, 61 insertions, 41 deletions
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<object>().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<TKey, TValue> other);
public abstract bool containsKey(TKey key);
public abstract Set<Map__Entry<TKey, TValue>> entrySet();
public abstract Collection<TValue> values();
-
+
public abstract Optional<TValue> _lookup(TKey key);
public abstract System.Collections.Generic.IDictionary<TKey, TValue> 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<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;
}
-
+
internal ArrayList(List<T> list) : this(new System.Collections.Generic.List<T>(FromJava.IterableToEnumerable(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();
@@ -38,7 +38,7 @@ namespace Mammoth.Couscous.java.util {
return _list[index];
}
}
-
+
public List<T> subList(int fromIndex, int toIndex) {
var list = _list as System.Collections.Generic.List<T>;
if (list == null) {
@@ -47,21 +47,28 @@ namespace Mammoth.Couscous.java.util {
return new ArrayList<T>(list.GetRange(fromIndex, toIndex - fromIndex));
}
}
-
+
public void add(T value) {
_list.Add(value);
}
-
+
+ public void addAll(List<T> 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<TKey, TValue> : AbstractMap<TKey, TValue> {
private readonly Dictionary<TKey, TValue> _dictionary;
-
+
internal HashMap() : this(new Dictionary<TKey, TValue>()) {
}
-
+
internal HashMap(Dictionary<TKey, TValue> dictionary) {
_dictionary = dictionary;
}
-
+
internal HashMap(Map<TKey, TValue> map) : this(new Dictionary<TKey, TValue>(map.AsDictionary())) {
}
-
+
public override void put(TKey key, TValue value) {
_dictionary[key] = value;
}
-
+
+ public override void putAll(Map<TKey, TValue> 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<Map__Entry<TKey, TValue>> entrySet() {
return new EntrySet(_dictionary);
}
-
+
public override Collection<TValue> values() {
return ToJava.CollectionToCollection(_dictionary.Values);
}
-
+
public override Optional<TValue> _lookup(TKey key) {
if (_dictionary.ContainsKey(key)) {
return new Some<TValue>(_dictionary[key]);
@@ -40,38 +46,38 @@ namespace Mammoth.Couscous.java.util {
return None<TValue>.Instance;
}
}
-
+
public override IDictionary<TKey, TValue> AsDictionary() {
return _dictionary;
}
-
+
public override System.Collections.IDictionary AsUntypedDictionary() {
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/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<T> : Collection<T> {
T get(int index);
List<T> subList(int fromIndex, int toIndex);
+ void addAll(List<T> 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<K, V> : Map {
void put(K key, V value);
+ void putAll(Map<K, V> other);
bool containsKey(K key);
Set<Map__Entry<K, V>> entrySet();
Collection<V> values();
-
+
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/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);
}