aboutsummaryrefslogtreecommitdiffstats
path: root/config-lib/src/main/java/com/yahoo/config/NodeVector.java
blob: 38a4944f5eb064d10ae5c23c3a16d5756da558fb (plain) (blame)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;

import java.util.*;


/**
 * A NodeVector represents an array declared with '[]' in a config definition file.
 * It is a List that stores nodes with a given type. A given default node must
 * be given, and this node will be cloned as the NodeVector size are increased.
 *
 */
public abstract class NodeVector<NODE> implements java.util.List<NODE> {

    protected final ArrayList<NODE> vector = new ArrayList<>();

    /**
     * Returns the number of elements in this NodeVector.
     * Alias for size().
     *
     * @return the number of elements in this NodeVector.
     */
    public int length() {
        return size();
    }

    public static class ReadOnlyException extends RuntimeException {
    }

    private static final ReadOnlyException e = new ReadOnlyException();

    public void add(int index, NODE element) {
        throw e;
    }

    public boolean add(NODE o) {
        throw e;
    }

    public boolean addAll(Collection<? extends NODE> c) {
        throw e;
    }

    public boolean addAll(int index, Collection<? extends NODE> c) {
        throw e;
    }

    public void clear() {
        throw e;
    }

    public NODE remove(int index) {
        throw e;
    }

    public boolean remove(Object o) {
        throw e;
    }

    public boolean removeAll(Collection<?> c) {
        throw e;
    }

    public boolean retainAll(Collection<?> c) {
        throw e;
    }

    public NODE set(int index, NODE element) {
        throw e;
    }

    public boolean contains(Object o) {
        return vector.contains(o);
    }

    public boolean containsAll(Collection<?> c) {
        return vector.containsAll(c);
    }

    @Override
    public boolean equals(Object o) {
        return o instanceof NodeVector && vector.equals(((NodeVector) o).vector);
    }

    @Override
    public int hashCode() {
        return vector.hashCode();
    }

    public NODE get(int index) {
        return vector.get(index);
    }

    public int indexOf(Object o) {
        return vector.indexOf(o);
    }

    public boolean isEmpty() {
        return vector.isEmpty();
    }

    public Iterator<NODE> iterator() {
        return vector.iterator();
    }

    public int lastIndexOf(Object o) {
        return vector.lastIndexOf(o);
    }

    public ListIterator<NODE> listIterator() {
        return vector.listIterator();
    }

    public ListIterator<NODE> listIterator(int index) {
        return vector.listIterator(index);
    }

    public int size() {
        return vector.size();
    }

    public List<NODE> subList(int fromIndex, int toIndex) {
        return vector.subList(fromIndex, toIndex);
    }

    public Object[] toArray() {
        return vector.toArray();
    }

    public <T> T[] toArray(T[] a) {
        return vector.toArray(a);
    }
}