1 /*
2 * Copyright (c) 2016, 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 */
165 updater.accept(m);
166 }
167 }
168
169 Map<String, Consumer<Map<T, T>>> actions = new HashMap<>();
170 actions.put("ADD", m -> m.put(newValue, newValue));
171 actions.put("REMOVE", m -> m.remove(m.keySet().iterator().next()));
172
173 String description = "new " + mapConstructor.apply(Collections.<T, T>emptyMap()).getClass().getName();
174 for (Map.Entry<String, Consumer<Map<T, T>>> e : actions.entrySet()) {
175 add(description + ".keySet().spliterator() " + e.getKey(),
176 () -> new MapSource<>(m -> m.keySet(), e.getValue()));
177 add(description + ".values().spliterator() " + e.getKey(),
178 () -> new MapSource<>(m -> m.values(), e.getValue()));
179 add(description + ".entrySet().spliterator() " + e.getKey(),
180 () -> new MapSource<>(m -> m.entrySet(), e.getValue()));
181 }
182 }
183 }
184
185 static class AbstractRandomAccessListImpl extends AbstractList<Integer> implements RandomAccess {
186 List<Integer> l;
187
188 AbstractRandomAccessListImpl(Collection<Integer> c) {
189 this.l = new ArrayList<>(c);
190 }
191
192 @Override
193 public boolean add(Integer integer) {
194 modCount++;
195 return l.add(integer);
196 }
197
198 @Override
199 public Iterator<Integer> iterator() {
200 return l.iterator();
201 }
202
203 @Override
204 public Integer get(int index) {
205 return l.get(index);
206 }
207
208 @Override
209 public boolean remove(Object o) {
210 modCount++;
211 return l.remove(o);
212 }
213
214 @Override
215 public int size() {
216 return l.size();
217 }
218
219 @Override
220 public List<Integer> subList(int fromIndex, int toIndex) {
221 return l.subList(fromIndex, toIndex);
222 }
223 }
224 }
|
1 /*
2 * Copyright (c) 2016, 2024, 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 */
165 updater.accept(m);
166 }
167 }
168
169 Map<String, Consumer<Map<T, T>>> actions = new HashMap<>();
170 actions.put("ADD", m -> m.put(newValue, newValue));
171 actions.put("REMOVE", m -> m.remove(m.keySet().iterator().next()));
172
173 String description = "new " + mapConstructor.apply(Collections.<T, T>emptyMap()).getClass().getName();
174 for (Map.Entry<String, Consumer<Map<T, T>>> e : actions.entrySet()) {
175 add(description + ".keySet().spliterator() " + e.getKey(),
176 () -> new MapSource<>(m -> m.keySet(), e.getValue()));
177 add(description + ".values().spliterator() " + e.getKey(),
178 () -> new MapSource<>(m -> m.values(), e.getValue()));
179 add(description + ".entrySet().spliterator() " + e.getKey(),
180 () -> new MapSource<>(m -> m.entrySet(), e.getValue()));
181 }
182 }
183 }
184
185 static class AbstractRandomAccessListImpl<T> extends AbstractList<T> implements RandomAccess {
186 List<T> l;
187
188 AbstractRandomAccessListImpl(Collection<T> c) {
189 this.l = new ArrayList<>(c);
190 }
191
192 @Override
193 public boolean add(T value) {
194 modCount++;
195 return l.add(value);
196 }
197
198 @Override
199 public Iterator<T> iterator() {
200 return l.iterator();
201 }
202
203 @Override
204 public T get(int index) {
205 return l.get(index);
206 }
207
208 @Override
209 public boolean remove(Object o) {
210 modCount++;
211 return l.remove(o);
212 }
213
214 @Override
215 public int size() {
216 return l.size();
217 }
218
219 @Override
220 public List<T> subList(int fromIndex, int toIndex) {
221 return l.subList(fromIndex, toIndex);
222 }
223 }
224 }
|