1 /*
2  * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 package test.java.util.SequencedCollection;
25 
26 import java.util.*;
27 
28 /**
29  * A complete List implementation that inherits the reversed() method
30  * from List. Useful for testing ReverseOrderListView.
31  * Underlying implementation provided by ArrayList.
32  */
33 public class SimpleList<E> implements List<E> {
34 
35     final List<E> list;
36 
SimpleList()37     public SimpleList() {
38         list = new ArrayList<>();
39     }
40 
SimpleList(Collection<? extends E> c)41     public SimpleList(Collection<? extends E> c) {
42         list = new ArrayList<>(c);
43     }
44 
45     // ========== Object ==========
46 
equals(Object o)47     public boolean equals(Object o) {
48         return list.equals(o);
49     }
50 
hashCode()51     public int hashCode() {
52         return list.hashCode();
53     }
54 
toString()55     public String toString() {
56         return list.toString();
57     }
58 
59     // ========== Collection ==========
60 
add(E e)61     public boolean add(E e) {
62         return list.add(e);
63     }
64 
addAll(Collection<? extends E> c)65     public boolean addAll(Collection<? extends E> c) {
66         return list.addAll(c);
67     }
68 
clear()69     public void clear() {
70         list.clear();
71     }
72 
contains(Object o)73     public boolean contains(Object o) {
74         return list.contains(o);
75     }
76 
containsAll(Collection<?> c)77     public boolean containsAll(Collection<?> c) {
78         return list.containsAll(c);
79     }
80 
isEmpty()81     public boolean isEmpty() {
82         return list.isEmpty();
83     }
84 
iterator()85     public Iterator<E> iterator() {
86         return list.iterator();
87     }
88 
remove(Object o)89     public boolean remove(Object o) {
90         return list.remove(o);
91     }
92 
removeAll(Collection<?> c)93     public boolean removeAll(Collection<?> c) {
94         return list.removeAll(c);
95     }
96 
retainAll(Collection<?> c)97     public boolean retainAll(Collection<?> c) {
98         return list.retainAll(c);
99     }
100 
size()101     public int size() {
102         return list.size();
103     }
104 
toArray()105     public Object[] toArray() {
106         return list.toArray();
107     }
108 
toArray(T[] a)109     public <T> T[] toArray(T[] a) {
110         return list.toArray(a);
111     }
112 
113     // ========== List ==========
114 
add(int index, E element)115     public void add(int index, E element) {
116         list.add(index, element);
117     }
118 
addAll(int index, Collection<? extends E> c)119     public boolean addAll(int index, Collection<? extends E> c) {
120         return list.addAll(index, c);
121     }
122 
get(int index)123     public E get(int index) {
124         return list.get(index);
125     }
126 
indexOf(Object o)127     public int indexOf(Object o) {
128         return list.indexOf(o);
129     }
130 
lastIndexOf(Object o)131     public int lastIndexOf(Object o) {
132         return list.lastIndexOf(o);
133     }
134 
listIterator()135     public ListIterator<E> listIterator() {
136         return list.listIterator();
137     }
138 
listIterator(int index)139     public ListIterator<E> listIterator(int index) {
140         return list.listIterator(index);
141     }
142 
remove(int index)143     public E remove(int index) {
144         return list.remove(index);
145     }
146 
set(int index, E element)147     public E set(int index, E element) {
148         return list.set(index, element);
149     }
150 
subList(int fromIndex, int toIndex)151     public List<E> subList(int fromIndex, int toIndex) {
152         return list.subList(fromIndex, toIndex);
153     }
154 }
155