-
Notifications
You must be signed in to change notification settings - Fork 585
/
AbstractListAdapter.java
372 lines (318 loc) · 11.3 KB
/
AbstractListAdapter.java
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
* Copyright (c) 2017 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.impl.list.mutable;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.ExecutorService;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.BooleanFunction;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.block.function.primitive.CharFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.list.ParallelListIterable;
import org.eclipse.collections.api.list.primitive.MutableBooleanList;
import org.eclipse.collections.api.list.primitive.MutableByteList;
import org.eclipse.collections.api.list.primitive.MutableCharList;
import org.eclipse.collections.api.list.primitive.MutableDoubleList;
import org.eclipse.collections.api.list.primitive.MutableFloatList;
import org.eclipse.collections.api.list.primitive.MutableIntList;
import org.eclipse.collections.api.list.primitive.MutableLongList;
import org.eclipse.collections.api.list.primitive.MutableShortList;
import org.eclipse.collections.api.multimap.list.MutableListMultimap;
import org.eclipse.collections.api.partition.list.PartitionMutableList;
import org.eclipse.collections.api.stack.MutableStack;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.block.factory.Functions;
import org.eclipse.collections.impl.block.factory.HashingStrategies;
import org.eclipse.collections.impl.collection.mutable.AbstractCollectionAdapter;
import org.eclipse.collections.impl.lazy.ReverseIterable;
import org.eclipse.collections.impl.lazy.parallel.list.ListIterableParallelIterable;
import org.eclipse.collections.impl.stack.mutable.ArrayStack;
import org.eclipse.collections.impl.utility.ListIterate;
@SuppressWarnings("AbstractMethodOverridesConcreteMethod")
public abstract class AbstractListAdapter<T>
extends AbstractCollectionAdapter<T>
implements MutableList<T>
{
@Override
public MutableList<T> clone()
{
try
{
return (MutableList<T>) super.clone();
}
catch (CloneNotSupportedException e)
{
throw new AssertionError(e);
}
}
@Override
protected abstract List<T> getDelegate();
@Override
public boolean addAll(int index, Collection<? extends T> collection)
{
return this.getDelegate().addAll(index, collection);
}
@Override
public T get(int index)
{
return this.getDelegate().get(index);
}
@Override
public T set(int index, T element)
{
return this.getDelegate().set(index, element);
}
@Override
public void add(int index, T element)
{
this.getDelegate().add(index, element);
}
@Override
public T remove(int index)
{
return this.getDelegate().remove(index);
}
@Override
public int indexOf(Object o)
{
return this.getDelegate().indexOf(o);
}
@Override
public int lastIndexOf(Object o)
{
return this.getDelegate().lastIndexOf(o);
}
@Override
public ListIterator<T> listIterator()
{
return this.getDelegate().listIterator();
}
@Override
public ListIterator<T> listIterator(int index)
{
return this.getDelegate().listIterator(index);
}
@Override
public <V extends Comparable<? super V>> MutableList<T> sortThisBy(Function<? super T, ? extends V> function)
{
return this.sortThis(Comparators.byFunction(function));
}
/**
* @since 9.0
*/
@Override
public <V> MutableList<T> distinctBy(Function<? super T, ? extends V> function)
{
return this.distinct(HashingStrategies.fromFunction(function));
}
@Override
public MutableList<T> sortThisByInt(IntFunction<? super T> function)
{
return this.sortThis(Functions.toIntComparator(function));
}
@Override
public MutableList<T> sortThisByBoolean(BooleanFunction<? super T> function)
{
return this.sortThis(Functions.toBooleanComparator(function));
}
@Override
public MutableList<T> sortThisByChar(CharFunction<? super T> function)
{
return this.sortThis(Functions.toCharComparator(function));
}
@Override
public MutableList<T> sortThisByByte(ByteFunction<? super T> function)
{
return this.sortThis(Functions.toByteComparator(function));
}
@Override
public MutableList<T> sortThisByShort(ShortFunction<? super T> function)
{
return this.sortThis(Functions.toShortComparator(function));
}
@Override
public MutableList<T> sortThisByFloat(FloatFunction<? super T> function)
{
return this.sortThis(Functions.toFloatComparator(function));
}
@Override
public MutableList<T> sortThisByLong(LongFunction<? super T> function)
{
return this.sortThis(Functions.toLongComparator(function));
}
@Override
public MutableList<T> sortThisByDouble(DoubleFunction<? super T> function)
{
return this.sortThis(Functions.toDoubleComparator(function));
}
@Override
public MutableList<T> subList(int fromIndex, int toIndex)
{
return ListAdapter.adapt(this.getDelegate().subList(fromIndex, toIndex));
}
@Override
public boolean equals(Object o)
{
return this.getDelegate().equals(o);
}
@Override
public int hashCode()
{
return this.getDelegate().hashCode();
}
@Override
public MutableStack<T> toStack()
{
return ArrayStack.newStack(this.getDelegate());
}
@Override
public ReverseIterable<T> asReversed()
{
return ReverseIterable.adapt(this);
}
@Override
public ParallelListIterable<T> asParallel(ExecutorService executorService, int batchSize)
{
return new ListIterableParallelIterable<>(this, executorService, batchSize);
}
@Override
public <V> MutableListMultimap<V, T> groupBy(Function<? super T, ? extends V> function)
{
return ListIterate.groupBy(this.getDelegate(), function);
}
@Override
public <V> MutableListMultimap<V, T> groupByEach(Function<? super T, ? extends Iterable<V>> function)
{
return ListIterate.groupByEach(this.getDelegate(), function);
}
@Override
public MutableList<T> tap(Procedure<? super T> procedure)
{
this.forEach(procedure);
return this;
}
@Override
public MutableList<T> select(Predicate<? super T> predicate)
{
return ListIterate.select(this.getDelegate(), predicate);
}
@Override
public MutableList<T> reject(Predicate<? super T> predicate)
{
return ListIterate.reject(this.getDelegate(), predicate);
}
@Override
public <S> MutableList<S> selectInstancesOf(Class<S> clazz)
{
return ListIterate.selectInstancesOf(this.getDelegate(), clazz);
}
@Override
public <V> MutableList<V> collect(Function<? super T, ? extends V> function)
{
return ListIterate.collect(this.getDelegate(), function);
}
@Override
public MutableBooleanList collectBoolean(BooleanFunction<? super T> booleanFunction)
{
return ListIterate.collectBoolean(this.getDelegate(), booleanFunction);
}
@Override
public MutableByteList collectByte(ByteFunction<? super T> byteFunction)
{
return ListIterate.collectByte(this.getDelegate(), byteFunction);
}
@Override
public MutableCharList collectChar(CharFunction<? super T> charFunction)
{
return ListIterate.collectChar(this.getDelegate(), charFunction);
}
@Override
public MutableDoubleList collectDouble(DoubleFunction<? super T> doubleFunction)
{
return ListIterate.collectDouble(this.getDelegate(), doubleFunction);
}
@Override
public MutableFloatList collectFloat(FloatFunction<? super T> floatFunction)
{
return ListIterate.collectFloat(this.getDelegate(), floatFunction);
}
@Override
public MutableIntList collectInt(IntFunction<? super T> intFunction)
{
return ListIterate.collectInt(this.getDelegate(), intFunction);
}
@Override
public MutableLongList collectLong(LongFunction<? super T> longFunction)
{
return ListIterate.collectLong(this.getDelegate(), longFunction);
}
@Override
public MutableShortList collectShort(ShortFunction<? super T> shortFunction)
{
return ListIterate.collectShort(this.getDelegate(), shortFunction);
}
@Override
public <V> MutableList<V> flatCollect(Function<? super T, ? extends Iterable<V>> function)
{
return ListIterate.flatCollect(this.getDelegate(), function);
}
@Override
public <V> MutableList<V> collectIf(Predicate<? super T> predicate, Function<? super T, ? extends V> function)
{
return ListIterate.collectIf(this.getDelegate(), predicate, function);
}
@Override
public PartitionMutableList<T> partition(Predicate<? super T> predicate)
{
return ListIterate.partition(this.getDelegate(), predicate);
}
@Override
public <P> PartitionMutableList<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return ListIterate.partitionWith(this.getDelegate(), predicate, parameter);
}
@Override
public <P> MutableList<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return ListIterate.selectWith(this.getDelegate(), predicate, parameter);
}
@Override
public <P> MutableList<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return ListIterate.rejectWith(this.getDelegate(), predicate, parameter);
}
@Override
public <P, V> MutableList<V> collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter)
{
return ListIterate.collectWith(this.getDelegate(), function, parameter);
}
@Override
public <S> MutableList<Pair<T, S>> zip(Iterable<S> that)
{
return ListIterate.zip(this.getDelegate(), that);
}
@Override
public MutableList<Pair<T, Integer>> zipWithIndex()
{
return ListIterate.zipWithIndex(this.getDelegate());
}
}