aboutsummaryrefslogtreecommitdiff
path: root/Mammoth/Couscous/java/util/ArrayList.cs
blob: 2e6d736f69f2abc581537ef5638853eae290fa58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Mammoth.Couscous.java.lang;
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();
            } else {
                return _list[index];
            }
        }

        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);
        }

        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();
        }
    }
}