-
Notifications
You must be signed in to change notification settings - Fork 587
/
AbstractMutableSet.java
344 lines (298 loc) · 11.3 KB
/
AbstractMutableSet.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
/*
* Copyright (c) 2022 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.set.mutable;
import java.util.Set;
import org.eclipse.collections.api.LazyIterable;
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.factory.Sets;
import org.eclipse.collections.api.factory.primitive.BooleanSets;
import org.eclipse.collections.api.factory.primitive.ByteSets;
import org.eclipse.collections.api.factory.primitive.CharSets;
import org.eclipse.collections.api.factory.primitive.DoubleSets;
import org.eclipse.collections.api.factory.primitive.FloatSets;
import org.eclipse.collections.api.factory.primitive.IntSets;
import org.eclipse.collections.api.factory.primitive.LongSets;
import org.eclipse.collections.api.factory.primitive.ShortSets;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.partition.set.PartitionMutableSet;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.SetIterable;
import org.eclipse.collections.api.set.UnsortedSetIterable;
import org.eclipse.collections.api.set.primitive.MutableBooleanSet;
import org.eclipse.collections.api.set.primitive.MutableByteSet;
import org.eclipse.collections.api.set.primitive.MutableCharSet;
import org.eclipse.collections.api.set.primitive.MutableDoubleSet;
import org.eclipse.collections.api.set.primitive.MutableFloatSet;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.api.set.primitive.MutableShortSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.block.procedure.PartitionPredicate2Procedure;
import org.eclipse.collections.impl.block.procedure.PartitionProcedure;
import org.eclipse.collections.impl.block.procedure.SelectInstancesOfProcedure;
import org.eclipse.collections.impl.collection.mutable.AbstractMutableCollection;
import org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap;
import org.eclipse.collections.impl.partition.set.PartitionUnifiedSet;
import org.eclipse.collections.impl.utility.internal.SetIterables;
import org.eclipse.collections.impl.utility.internal.SetIterate;
public abstract class AbstractMutableSet<T>
extends AbstractMutableCollection<T>
implements MutableSet<T>
{
@Override
public MutableSet<T> clone()
{
try
{
return (MutableSet<T>) super.clone();
}
catch (CloneNotSupportedException e)
{
throw new AssertionError(e);
}
}
@Override
public MutableSet<T> newEmpty()
{
return Sets.mutable.empty();
}
protected <K> MutableSet<K> newEmptySameSize()
{
return Sets.mutable.withInitialCapacity(this.size());
}
@Override
public MutableSet<T> tap(Procedure<? super T> procedure)
{
this.forEach(procedure);
return this;
}
@Override
public MutableSet<T> select(Predicate<? super T> predicate)
{
return this.select(predicate, this.newEmpty());
}
@Override
public <P> MutableSet<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return this.selectWith(predicate, parameter, this.newEmptySameSize());
}
@Override
public MutableSet<T> reject(Predicate<? super T> predicate)
{
return this.reject(predicate, this.newEmptySameSize());
}
@Override
public <P> MutableSet<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return this.rejectWith(predicate, parameter, this.newEmptySameSize());
}
@Override
public PartitionMutableSet<T> partition(Predicate<? super T> predicate)
{
PartitionMutableSet<T> partitionMutableSet = new PartitionUnifiedSet<>();
this.forEach(new PartitionProcedure<>(predicate, partitionMutableSet));
return partitionMutableSet;
}
@Override
public <P> PartitionMutableSet<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
PartitionMutableSet<T> partitionMutableSet = new PartitionUnifiedSet<>();
this.forEach(new PartitionPredicate2Procedure<>(predicate, parameter, partitionMutableSet));
return partitionMutableSet;
}
@Override
public <S> MutableSet<S> selectInstancesOf(Class<S> clazz)
{
MutableSet<S> result = (MutableSet<S>) this.newEmpty();
this.forEach(new SelectInstancesOfProcedure<>(clazz, result));
return result;
}
@Override
public <V> MutableSet<V> collect(Function<? super T, ? extends V> function)
{
return this.collect(function, this.newEmptySameSize());
}
@Override
public MutableBooleanSet collectBoolean(BooleanFunction<? super T> booleanFunction)
{
return this.collectBoolean(booleanFunction, BooleanSets.mutable.empty());
}
@Override
public MutableByteSet collectByte(ByteFunction<? super T> byteFunction)
{
return this.collectByte(byteFunction, ByteSets.mutable.empty());
}
@Override
public MutableCharSet collectChar(CharFunction<? super T> charFunction)
{
return this.collectChar(charFunction, CharSets.mutable.empty());
}
@Override
public MutableDoubleSet collectDouble(DoubleFunction<? super T> doubleFunction)
{
return this.collectDouble(doubleFunction, DoubleSets.mutable.empty());
}
@Override
public MutableFloatSet collectFloat(FloatFunction<? super T> floatFunction)
{
return this.collectFloat(floatFunction, FloatSets.mutable.empty());
}
@Override
public MutableIntSet collectInt(IntFunction<? super T> intFunction)
{
return this.collectInt(intFunction, IntSets.mutable.empty());
}
@Override
public MutableLongSet collectLong(LongFunction<? super T> longFunction)
{
return this.collectLong(longFunction, LongSets.mutable.empty());
}
@Override
public MutableShortSet collectShort(ShortFunction<? super T> shortFunction)
{
return this.collectShort(shortFunction, ShortSets.mutable.empty());
}
@Override
public <V> MutableSet<V> flatCollect(Function<? super T, ? extends Iterable<V>> function)
{
return this.flatCollect(function, this.newEmptySameSize());
}
@Override
public <P, V> MutableSet<V> collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter)
{
return this.collectWith(function, parameter, this.newEmptySameSize());
}
@Override
public <V> MutableSet<V> collectIf(Predicate<? super T> predicate, Function<? super T, ? extends V> function)
{
return this.collectIf(predicate, function, this.newEmptySameSize());
}
@Override
public <V> UnifiedSetMultimap<V, T> groupBy(Function<? super T, ? extends V> function)
{
return this.groupBy(function, UnifiedSetMultimap.newMultimap());
}
@Override
public <V> UnifiedSetMultimap<V, T> groupByEach(Function<? super T, ? extends Iterable<V>> function)
{
return this.groupByEach(function, UnifiedSetMultimap.newMultimap());
}
@Override
public MutableSet<T> asUnmodifiable()
{
return UnmodifiableMutableSet.of(this);
}
@Override
public MutableSet<T> asSynchronized()
{
return SynchronizedMutableSet.of(this);
}
@Override
public ImmutableSet<T> toImmutable()
{
return Sets.immutable.withAll(this);
}
/**
* @deprecated in 6.0. Use {@link OrderedIterable#zip(Iterable)} instead.
*/
@Override
@Deprecated
public <S> MutableSet<Pair<T, S>> zip(Iterable<S> that)
{
return this.zip(that, this.newEmptySameSize());
}
/**
* @deprecated in 6.0. Use {@link OrderedIterable#zipWithIndex()} instead.
*/
@Override
@Deprecated
public MutableSet<Pair<T, Integer>> zipWithIndex()
{
return this.zipWithIndex(this.newEmptySameSize());
}
@Override
public boolean removeAllIterable(Iterable<?> iterable)
{
return SetIterate.removeAllIterable(this, iterable);
}
@Override
public MutableSet<T> union(SetIterable<? extends T> set)
{
return SetIterables.union(this, set);
}
@Override
public <R extends Set<T>> R unionInto(SetIterable<? extends T> set, R targetSet)
{
return SetIterables.unionInto(this, set, targetSet);
}
@Override
public MutableSet<T> intersect(SetIterable<? extends T> set)
{
return SetIterables.intersect(this, set);
}
@Override
public <R extends Set<T>> R intersectInto(SetIterable<? extends T> set, R targetSet)
{
return SetIterables.intersectInto(this, set, targetSet);
}
@Override
public MutableSet<T> difference(SetIterable<? extends T> subtrahendSet)
{
return SetIterables.difference(this, subtrahendSet);
}
@Override
public <R extends Set<T>> R differenceInto(SetIterable<? extends T> subtrahendSet, R targetSet)
{
return SetIterables.differenceInto(this, subtrahendSet, targetSet);
}
@Override
public MutableSet<T> symmetricDifference(SetIterable<? extends T> setB)
{
return SetIterables.symmetricDifference(this, setB);
}
@Override
public <R extends Set<T>> R symmetricDifferenceInto(SetIterable<? extends T> set, R targetSet)
{
return SetIterables.symmetricDifferenceInto(this, set, targetSet);
}
@Override
public boolean isSubsetOf(SetIterable<? extends T> candidateSuperset)
{
return SetIterables.isSubsetOf(this, candidateSuperset);
}
@Override
public boolean isProperSubsetOf(SetIterable<? extends T> candidateSuperset)
{
return SetIterables.isProperSubsetOf(this, candidateSuperset);
}
@Override
public MutableSet<UnsortedSetIterable<T>> powerSet()
{
return (MutableSet<UnsortedSetIterable<T>>) (MutableSet<?>) SetIterables.powerSet(this);
}
@Override
public <B> LazyIterable<Pair<T, B>> cartesianProduct(SetIterable<B> set)
{
return SetIterables.cartesianProduct(this, set);
}
}