diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-06-10 15:21:00 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-06-10 15:21:00 +0100 |
| commit | 14ac28c468ca81b645cabf21552748a46f7b21e2 (patch) | |
| tree | 917469516808b98a43b5e20c0efc712d32b963f0 /Mammoth/Couscous/java/util/ArrayList.cs | |
| parent | 7657de4df31f35408a75ea927c3141cf3ff0cee8 (diff) | |
Update java-mammoth
Diffstat (limited to 'Mammoth/Couscous/java/util/ArrayList.cs')
| -rw-r--r-- | Mammoth/Couscous/java/util/ArrayList.cs | 33 |
1 files changed, 20 insertions, 13 deletions
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(); } |
