~ubuntu-branches/ubuntu/wily/gs-collections/wily

« back to all changes in this revision

Viewing changes to collections/src/main/java/com/gs/collections/impl/collection/mutable/AbstractCollectionAdapter.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2015-07-23 12:42:30 UTC
  • Revision ID: package-import@ubuntu.com-20150723124230-2rjvfv6elyn2m7d4
Tags: upstream-5.1.0
ImportĀ upstreamĀ versionĀ 5.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Goldman Sachs.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
package com.gs.collections.impl.collection.mutable;
 
18
 
 
19
import java.util.Collection;
 
20
import java.util.Comparator;
 
21
import java.util.Iterator;
 
22
 
 
23
import com.gs.collections.api.LazyIterable;
 
24
import com.gs.collections.api.RichIterable;
 
25
import com.gs.collections.api.bag.MutableBag;
 
26
import com.gs.collections.api.block.function.Function;
 
27
import com.gs.collections.api.block.function.Function0;
 
28
import com.gs.collections.api.block.function.Function2;
 
29
import com.gs.collections.api.block.function.Function3;
 
30
import com.gs.collections.api.block.function.primitive.BooleanFunction;
 
31
import com.gs.collections.api.block.function.primitive.ByteFunction;
 
32
import com.gs.collections.api.block.function.primitive.CharFunction;
 
33
import com.gs.collections.api.block.function.primitive.DoubleFunction;
 
34
import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction;
 
35
import com.gs.collections.api.block.function.primitive.FloatFunction;
 
36
import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction;
 
37
import com.gs.collections.api.block.function.primitive.IntFunction;
 
38
import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction;
 
39
import com.gs.collections.api.block.function.primitive.LongFunction;
 
40
import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction;
 
41
import com.gs.collections.api.block.function.primitive.ShortFunction;
 
42
import com.gs.collections.api.block.predicate.Predicate;
 
43
import com.gs.collections.api.block.predicate.Predicate2;
 
44
import com.gs.collections.api.block.procedure.Procedure;
 
45
import com.gs.collections.api.block.procedure.Procedure2;
 
46
import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure;
 
47
import com.gs.collections.api.collection.MutableCollection;
 
48
import com.gs.collections.api.collection.primitive.MutableBooleanCollection;
 
49
import com.gs.collections.api.collection.primitive.MutableByteCollection;
 
50
import com.gs.collections.api.collection.primitive.MutableCharCollection;
 
51
import com.gs.collections.api.collection.primitive.MutableDoubleCollection;
 
52
import com.gs.collections.api.collection.primitive.MutableFloatCollection;
 
53
import com.gs.collections.api.collection.primitive.MutableIntCollection;
 
54
import com.gs.collections.api.collection.primitive.MutableLongCollection;
 
55
import com.gs.collections.api.collection.primitive.MutableShortCollection;
 
56
import com.gs.collections.api.list.MutableList;
 
57
import com.gs.collections.api.map.MutableMap;
 
58
import com.gs.collections.api.map.sorted.MutableSortedMap;
 
59
import com.gs.collections.api.multimap.MutableMultimap;
 
60
import com.gs.collections.api.partition.PartitionMutableCollection;
 
61
import com.gs.collections.api.set.MutableSet;
 
62
import com.gs.collections.api.set.sorted.MutableSortedSet;
 
63
import com.gs.collections.api.tuple.Pair;
 
64
import com.gs.collections.api.tuple.Twin;
 
65
import com.gs.collections.impl.bag.mutable.HashBag;
 
66
import com.gs.collections.impl.block.factory.Comparators;
 
67
import com.gs.collections.impl.block.factory.Predicates2;
 
68
import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure;
 
69
import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure;
 
70
import com.gs.collections.impl.factory.Lists;
 
71
import com.gs.collections.impl.map.mutable.UnifiedMap;
 
72
import com.gs.collections.impl.map.sorted.mutable.TreeSortedMap;
 
73
import com.gs.collections.impl.set.mutable.UnifiedSet;
 
74
import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet;
 
75
import com.gs.collections.impl.utility.ArrayIterate;
 
76
import com.gs.collections.impl.utility.Iterate;
 
77
import com.gs.collections.impl.utility.LazyIterate;
 
78
import com.gs.collections.impl.utility.internal.IterableIterate;
 
79
import com.gs.collections.impl.utility.internal.MutableCollectionIterate;
 
80
 
 
81
public abstract class AbstractCollectionAdapter<T>
 
82
        implements MutableCollection<T>
 
83
{
 
84
    protected abstract Collection<T> getDelegate();
 
85
 
 
86
    protected <E> MutableCollection<E> wrap(Collection<E> collection)
 
87
    {
 
88
        return CollectionAdapter.adapt(collection);
 
89
    }
 
90
 
 
91
    public boolean notEmpty()
 
92
    {
 
93
        return !this.getDelegate().isEmpty();
 
94
    }
 
95
 
 
96
    public T getFirst()
 
97
    {
 
98
        return Iterate.getFirst(this.getDelegate());
 
99
    }
 
100
 
 
101
    public T getLast()
 
102
    {
 
103
        return Iterate.getLast(this.getDelegate());
 
104
    }
 
105
 
 
106
    public void forEach(Procedure<? super T> procedure)
 
107
    {
 
108
        Iterate.forEach(this.getDelegate(), procedure);
 
109
    }
 
110
 
 
111
    public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
 
112
    {
 
113
        Iterate.forEachWithIndex(this.getDelegate(), objectIntProcedure);
 
114
    }
 
115
 
 
116
    public void removeIf(Predicate<? super T> predicate)
 
117
    {
 
118
        Iterate.removeIf(this.getDelegate(), predicate);
 
119
    }
 
120
 
 
121
    public <P> void removeIfWith(Predicate2<? super T, ? super P> predicate, P parameter)
 
122
    {
 
123
        Iterate.removeIfWith(this.getDelegate(), predicate, parameter);
 
124
    }
 
125
 
 
126
    public T detect(Predicate<? super T> predicate)
 
127
    {
 
128
        return Iterate.detect(this.getDelegate(), predicate);
 
129
    }
 
130
 
 
131
    public T min(Comparator<? super T> comparator)
 
132
    {
 
133
        return Iterate.min(this, comparator);
 
134
    }
 
135
 
 
136
    public T max(Comparator<? super T> comparator)
 
137
    {
 
138
        return Iterate.max(this, comparator);
 
139
    }
 
140
 
 
141
    public T min()
 
142
    {
 
143
        return Iterate.min(this);
 
144
    }
 
145
 
 
146
    public T max()
 
147
    {
 
148
        return Iterate.max(this);
 
149
    }
 
150
 
 
151
    public <V extends Comparable<? super V>> T minBy(Function<? super T, ? extends V> function)
 
152
    {
 
153
        return IterableIterate.minBy(this, function);
 
154
    }
 
155
 
 
156
    public <V extends Comparable<? super V>> T maxBy(Function<? super T, ? extends V> function)
 
157
    {
 
158
        return IterableIterate.maxBy(this, function);
 
159
    }
 
160
 
 
161
    public T detectIfNone(Predicate<? super T> predicate, Function0<? extends T> function)
 
162
    {
 
163
        T result = this.detect(predicate);
 
164
        return result == null ? function.value() : result;
 
165
    }
 
166
 
 
167
    public int count(Predicate<? super T> predicate)
 
168
    {
 
169
        return Iterate.count(this.getDelegate(), predicate);
 
170
    }
 
171
 
 
172
    public boolean anySatisfy(Predicate<? super T> predicate)
 
173
    {
 
174
        return Iterate.anySatisfy(this.getDelegate(), predicate);
 
175
    }
 
176
 
 
177
    public boolean allSatisfy(Predicate<? super T> predicate)
 
178
    {
 
179
        return Iterate.allSatisfy(this.getDelegate(), predicate);
 
180
    }
 
181
 
 
182
    public boolean noneSatisfy(Predicate<? super T> predicate)
 
183
    {
 
184
        return Iterate.noneSatisfy(this.getDelegate(), predicate);
 
185
    }
 
186
 
 
187
    public <IV> IV injectInto(IV injectedValue, Function2<? super IV, ? super T, ? extends IV> function)
 
188
    {
 
189
        return Iterate.injectInto(injectedValue, this.getDelegate(), function);
 
190
    }
 
191
 
 
192
    public int injectInto(int injectedValue, IntObjectToIntFunction<? super T> function)
 
193
    {
 
194
        return Iterate.injectInto(injectedValue, this.getDelegate(), function);
 
195
    }
 
196
 
 
197
    public long injectInto(long injectedValue, LongObjectToLongFunction<? super T> function)
 
198
    {
 
199
        return Iterate.injectInto(injectedValue, this.getDelegate(), function);
 
200
    }
 
201
 
 
202
    public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? super T> function)
 
203
    {
 
204
        return Iterate.injectInto(injectedValue, this.getDelegate(), function);
 
205
    }
 
206
 
 
207
    public float injectInto(float injectedValue, FloatObjectToFloatFunction<? super T> function)
 
208
    {
 
209
        return Iterate.injectInto(injectedValue, this.getDelegate(), function);
 
210
    }
 
211
 
 
212
    public long sumOfInt(IntFunction<? super T> function)
 
213
    {
 
214
        return Iterate.sumOfInt(this.getDelegate(), function);
 
215
    }
 
216
 
 
217
    public double sumOfFloat(FloatFunction<? super T> function)
 
218
    {
 
219
        return Iterate.sumOfFloat(this.getDelegate(), function);
 
220
    }
 
221
 
 
222
    public long sumOfLong(LongFunction<? super T> function)
 
223
    {
 
224
        return Iterate.sumOfLong(this.getDelegate(), function);
 
225
    }
 
226
 
 
227
    public double sumOfDouble(DoubleFunction<? super T> function)
 
228
    {
 
229
        return Iterate.sumOfDouble(this.getDelegate(), function);
 
230
    }
 
231
 
 
232
    public MutableCollection<T> select(Predicate<? super T> predicate)
 
233
    {
 
234
        return this.wrap(Iterate.select(this.getDelegate(), predicate));
 
235
    }
 
236
 
 
237
    public <R extends Collection<T>> R select(Predicate<? super T> predicate, R target)
 
238
    {
 
239
        return Iterate.select(this.getDelegate(), predicate, target);
 
240
    }
 
241
 
 
242
    public MutableCollection<T> reject(Predicate<? super T> predicate)
 
243
    {
 
244
        return this.wrap(Iterate.reject(this.getDelegate(), predicate));
 
245
    }
 
246
 
 
247
    public <R extends Collection<T>> R reject(Predicate<? super T> predicate, R target)
 
248
    {
 
249
        return Iterate.reject(this.getDelegate(), predicate, target);
 
250
    }
 
251
 
 
252
    public <S> MutableCollection<S> selectInstancesOf(Class<S> clazz)
 
253
    {
 
254
        return this.wrap(Iterate.selectInstancesOf(this.getDelegate(), clazz));
 
255
    }
 
256
 
 
257
    public <V> MutableCollection<V> collect(Function<? super T, ? extends V> function)
 
258
    {
 
259
        return this.wrap(Iterate.collect(this.getDelegate(), function));
 
260
    }
 
261
 
 
262
    public MutableBooleanCollection collectBoolean(BooleanFunction<? super T> booleanFunction)
 
263
    {
 
264
        return Iterate.collectBoolean(this.getDelegate(), booleanFunction);
 
265
    }
 
266
 
 
267
    public <R extends MutableBooleanCollection> R collectBoolean(BooleanFunction<? super T> booleanFunction, R target)
 
268
    {
 
269
        return Iterate.collectBoolean(this.getDelegate(), booleanFunction, target);
 
270
    }
 
271
 
 
272
    public MutableByteCollection collectByte(ByteFunction<? super T> byteFunction)
 
273
    {
 
274
        return Iterate.collectByte(this.getDelegate(), byteFunction);
 
275
    }
 
276
 
 
277
    public <R extends MutableByteCollection> R collectByte(ByteFunction<? super T> byteFunction, R target)
 
278
    {
 
279
        return Iterate.collectByte(this.getDelegate(), byteFunction, target);
 
280
    }
 
281
 
 
282
    public MutableCharCollection collectChar(CharFunction<? super T> charFunction)
 
283
    {
 
284
        return Iterate.collectChar(this.getDelegate(), charFunction);
 
285
    }
 
286
 
 
287
    public <R extends MutableCharCollection> R collectChar(CharFunction<? super T> charFunction, R target)
 
288
    {
 
289
        return Iterate.collectChar(this.getDelegate(), charFunction, target);
 
290
    }
 
291
 
 
292
    public MutableDoubleCollection collectDouble(DoubleFunction<? super T> doubleFunction)
 
293
    {
 
294
        return Iterate.collectDouble(this.getDelegate(), doubleFunction);
 
295
    }
 
296
 
 
297
    public <R extends MutableDoubleCollection> R collectDouble(DoubleFunction<? super T> doubleFunction, R target)
 
298
    {
 
299
        return Iterate.collectDouble(this.getDelegate(), doubleFunction, target);
 
300
    }
 
301
 
 
302
    public MutableFloatCollection collectFloat(FloatFunction<? super T> floatFunction)
 
303
    {
 
304
        return Iterate.collectFloat(this.getDelegate(), floatFunction);
 
305
    }
 
306
 
 
307
    public <R extends MutableFloatCollection> R collectFloat(FloatFunction<? super T> floatFunction, R target)
 
308
    {
 
309
        return Iterate.collectFloat(this.getDelegate(), floatFunction, target);
 
310
    }
 
311
 
 
312
    public MutableIntCollection collectInt(IntFunction<? super T> intFunction)
 
313
    {
 
314
        return Iterate.collectInt(this.getDelegate(), intFunction);
 
315
    }
 
316
 
 
317
    public <R extends MutableIntCollection> R collectInt(IntFunction<? super T> intFunction, R target)
 
318
    {
 
319
        return Iterate.collectInt(this.getDelegate(), intFunction, target);
 
320
    }
 
321
 
 
322
    public MutableLongCollection collectLong(LongFunction<? super T> longFunction)
 
323
    {
 
324
        return Iterate.collectLong(this.getDelegate(), longFunction);
 
325
    }
 
326
 
 
327
    public <R extends MutableLongCollection> R collectLong(LongFunction<? super T> longFunction, R target)
 
328
    {
 
329
        return Iterate.collectLong(this.getDelegate(), longFunction, target);
 
330
    }
 
331
 
 
332
    public MutableShortCollection collectShort(ShortFunction<? super T> shortFunction)
 
333
    {
 
334
        return Iterate.collectShort(this.getDelegate(), shortFunction);
 
335
    }
 
336
 
 
337
    public <R extends MutableShortCollection> R collectShort(ShortFunction<? super T> shortFunction, R target)
 
338
    {
 
339
        return Iterate.collectShort(this.getDelegate(), shortFunction, target);
 
340
    }
 
341
 
 
342
    public <V, R extends Collection<V>> R collect(Function<? super T, ? extends V> function, R target)
 
343
    {
 
344
        return Iterate.collect(this.getDelegate(), function, target);
 
345
    }
 
346
 
 
347
    public <V> MutableCollection<V> flatCollect(Function<? super T, ? extends Iterable<V>> function)
 
348
    {
 
349
        return this.wrap(Iterate.flatCollect(this.getDelegate(), function));
 
350
    }
 
351
 
 
352
    public <V, R extends Collection<V>> R flatCollect(
 
353
            Function<? super T, ? extends Iterable<V>> function,
 
354
            R target)
 
355
    {
 
356
        return Iterate.flatCollect(this.getDelegate(), function, target);
 
357
    }
 
358
 
 
359
    public <V> MutableCollection<V> collectIf(
 
360
            Predicate<? super T> predicate,
 
361
            Function<? super T, ? extends V> function)
 
362
    {
 
363
        return this.wrap(Iterate.collectIf(this.getDelegate(), predicate, function));
 
364
    }
 
365
 
 
366
    public <V, R extends Collection<V>> R collectIf(
 
367
            Predicate<? super T> predicate,
 
368
            Function<? super T, ? extends V> function,
 
369
            R target)
 
370
    {
 
371
        return Iterate.collectIf(this.getDelegate(), predicate, function, target);
 
372
    }
 
373
 
 
374
    public <P> Twin<MutableList<T>> selectAndRejectWith(
 
375
            Predicate2<? super T, ? super P> predicate,
 
376
            P parameter)
 
377
    {
 
378
        return Iterate.selectAndRejectWith(this.getDelegate(), predicate, parameter);
 
379
    }
 
380
 
 
381
    public PartitionMutableCollection<T> partition(Predicate<? super T> predicate)
 
382
    {
 
383
        return (PartitionMutableCollection<T>) Iterate.partition(this.getDelegate(), predicate);
 
384
    }
 
385
 
 
386
    public <P> PartitionMutableCollection<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter)
 
387
    {
 
388
        return (PartitionMutableCollection<T>) Iterate.partitionWith(this.getDelegate(), predicate, parameter);
 
389
    }
 
390
 
 
391
    public int size()
 
392
    {
 
393
        return this.getDelegate().size();
 
394
    }
 
395
 
 
396
    public boolean isEmpty()
 
397
    {
 
398
        return this.getDelegate().isEmpty();
 
399
    }
 
400
 
 
401
    public boolean contains(Object o)
 
402
    {
 
403
        return this.getDelegate().contains(o);
 
404
    }
 
405
 
 
406
    public Iterator<T> iterator()
 
407
    {
 
408
        return this.getDelegate().iterator();
 
409
    }
 
410
 
 
411
    public Object[] toArray()
 
412
    {
 
413
        return this.getDelegate().toArray();
 
414
    }
 
415
 
 
416
    public <E> E[] toArray(E[] a)
 
417
    {
 
418
        return this.getDelegate().toArray(a);
 
419
    }
 
420
 
 
421
    public boolean add(T o)
 
422
    {
 
423
        return this.getDelegate().add(o);
 
424
    }
 
425
 
 
426
    public boolean remove(Object o)
 
427
    {
 
428
        return this.getDelegate().remove(o);
 
429
    }
 
430
 
 
431
    public boolean containsAll(Collection<?> collection)
 
432
    {
 
433
        return this.getDelegate().containsAll(collection);
 
434
    }
 
435
 
 
436
    public boolean containsAllIterable(Iterable<?> source)
 
437
    {
 
438
        return Iterate.allSatisfyWith(source, Predicates2.in(), this.getDelegate());
 
439
    }
 
440
 
 
441
    public boolean containsAllArguments(Object... elements)
 
442
    {
 
443
        return ArrayIterate.allSatisfyWith(elements, Predicates2.in(), this.getDelegate());
 
444
    }
 
445
 
 
446
    public boolean addAll(Collection<? extends T> collection)
 
447
    {
 
448
        boolean result = false;
 
449
        for (T each : collection)
 
450
        {
 
451
            result |= this.add(each);
 
452
        }
 
453
        return result;
 
454
    }
 
455
 
 
456
    public boolean addAllIterable(Iterable<? extends T> iterable)
 
457
    {
 
458
        return Iterate.addAllIterable(iterable, this);
 
459
    }
 
460
 
 
461
    public boolean removeAll(Collection<?> collection)
 
462
    {
 
463
        int currentSize = this.size();
 
464
        this.removeIfWith(Predicates2.in(), collection);
 
465
        return currentSize != this.size();
 
466
    }
 
467
 
 
468
    public boolean removeAllIterable(Iterable<?> iterable)
 
469
    {
 
470
        return this.removeAll(CollectionAdapter.wrapSet(iterable));
 
471
    }
 
472
 
 
473
    public boolean retainAll(Collection<?> collection)
 
474
    {
 
475
        int currentSize = this.size();
 
476
        this.removeIfWith(Predicates2.notIn(), collection);
 
477
        return currentSize != this.size();
 
478
    }
 
479
 
 
480
    public boolean retainAllIterable(Iterable<?> iterable)
 
481
    {
 
482
        return this.retainAll(CollectionAdapter.wrapSet(iterable));
 
483
    }
 
484
 
 
485
    public void clear()
 
486
    {
 
487
        this.getDelegate().clear();
 
488
    }
 
489
 
 
490
    public <P> void forEachWith(Procedure2<? super T, ? super P> procedure, P parameter)
 
491
    {
 
492
        Iterate.forEachWith(this.getDelegate(), procedure, parameter);
 
493
    }
 
494
 
 
495
    public <P> MutableCollection<T> selectWith(
 
496
            Predicate2<? super T, ? super P> predicate,
 
497
            P parameter)
 
498
    {
 
499
        return this.wrap(Iterate.selectWith(this.getDelegate(), predicate, parameter));
 
500
    }
 
501
 
 
502
    public <P, R extends Collection<T>> R selectWith(
 
503
            Predicate2<? super T, ? super P> predicate,
 
504
            P parameter,
 
505
            R targetCollection)
 
506
    {
 
507
        return Iterate.selectWith(this.getDelegate(), predicate, parameter, targetCollection);
 
508
    }
 
509
 
 
510
    public <P> MutableCollection<T> rejectWith(
 
511
            Predicate2<? super T, ? super P> predicate,
 
512
            P parameter)
 
513
    {
 
514
        return this.wrap(Iterate.rejectWith(this.getDelegate(), predicate, parameter));
 
515
    }
 
516
 
 
517
    public <P, R extends Collection<T>> R rejectWith(
 
518
            Predicate2<? super T, ? super P> predicate,
 
519
            P parameter,
 
520
            R targetCollection)
 
521
    {
 
522
        return Iterate.rejectWith(this.getDelegate(), predicate, parameter, targetCollection);
 
523
    }
 
524
 
 
525
    public <P, V> MutableCollection<V> collectWith(
 
526
            Function2<? super T, ? super P, ? extends V> function,
 
527
            P parameter)
 
528
    {
 
529
        return this.wrap(Iterate.collectWith(this.getDelegate(), function, parameter));
 
530
    }
 
531
 
 
532
    public <P, A, R extends Collection<A>> R collectWith(
 
533
            Function2<? super T, ? super P, ? extends A> function,
 
534
            P parameter,
 
535
            R targetCollection)
 
536
    {
 
537
        return Iterate.collectWith(this.getDelegate(), function, parameter, targetCollection);
 
538
    }
 
539
 
 
540
    public <IV, P> IV injectIntoWith(
 
541
            IV injectValue,
 
542
            Function3<? super IV, ? super T, ? super P, ? extends IV> function,
 
543
            P parameter)
 
544
    {
 
545
        return Iterate.injectIntoWith(injectValue, this.getDelegate(), function, parameter);
 
546
    }
 
547
 
 
548
    public MutableList<T> toList()
 
549
    {
 
550
        return Lists.mutable.ofAll(this.getDelegate());
 
551
    }
 
552
 
 
553
    public MutableList<T> toSortedList()
 
554
    {
 
555
        return this.toList().sortThis();
 
556
    }
 
557
 
 
558
    public MutableList<T> toSortedList(Comparator<? super T> comparator)
 
559
    {
 
560
        return this.toList().sortThis(comparator);
 
561
    }
 
562
 
 
563
    public <V extends Comparable<? super V>> MutableList<T> toSortedListBy(Function<? super T, ? extends V> function)
 
564
    {
 
565
        return this.toSortedList(Comparators.byFunction(function));
 
566
    }
 
567
 
 
568
    public MutableSortedSet<T> toSortedSet()
 
569
    {
 
570
        return TreeSortedSet.newSet(null, this);
 
571
    }
 
572
 
 
573
    public MutableSortedSet<T> toSortedSet(Comparator<? super T> comparator)
 
574
    {
 
575
        return TreeSortedSet.newSet(comparator, this);
 
576
    }
 
577
 
 
578
    public <V extends Comparable<? super V>> MutableSortedSet<T> toSortedSetBy(
 
579
            Function<? super T, ? extends V> function)
 
580
    {
 
581
        return this.toSortedSet(Comparators.byFunction(function));
 
582
    }
 
583
 
 
584
    public MutableSet<T> toSet()
 
585
    {
 
586
        return UnifiedSet.newSet(this.getDelegate());
 
587
    }
 
588
 
 
589
    public MutableBag<T> toBag()
 
590
    {
 
591
        return HashBag.newBag(this.getDelegate());
 
592
    }
 
593
 
 
594
    public <K, V> MutableMap<K, V> toMap(
 
595
            Function<? super T, ? extends K> keyFunction,
 
596
            Function<? super T, ? extends V> valueFunction)
 
597
    {
 
598
        UnifiedMap<K, V> map = UnifiedMap.newMap(this.size());
 
599
        map.collectKeysAndValues(this.getDelegate(), keyFunction, valueFunction);
 
600
        return map;
 
601
    }
 
602
 
 
603
    public <K, V> MutableSortedMap<K, V> toSortedMap(
 
604
            Function<? super T, ? extends K> keyFunction,
 
605
            Function<? super T, ? extends V> valueFunction)
 
606
    {
 
607
        return TreeSortedMap.<K, V>newMap().collectKeysAndValues(this.getDelegate(), keyFunction, valueFunction);
 
608
    }
 
609
 
 
610
    public <K, V> MutableSortedMap<K, V> toSortedMap(
 
611
            Comparator<? super K> comparator,
 
612
            Function<? super T, ? extends K> keyFunction,
 
613
            Function<? super T, ? extends V> valueFunction)
 
614
    {
 
615
        return TreeSortedMap.<K, V>newMap(comparator).collectKeysAndValues(this.getDelegate(), keyFunction, valueFunction);
 
616
    }
 
617
 
 
618
    public LazyIterable<T> asLazy()
 
619
    {
 
620
        return LazyIterate.adapt(this);
 
621
    }
 
622
 
 
623
    public <P> T detectWith(Predicate2<? super T, ? super P> predicate, P parameter)
 
624
    {
 
625
        return Iterate.detectWith(this.getDelegate(), predicate, parameter);
 
626
    }
 
627
 
 
628
    public <P> T detectWithIfNone(
 
629
            Predicate2<? super T, ? super P> predicate,
 
630
            P parameter,
 
631
            Function0<? extends T> function)
 
632
    {
 
633
        T result = this.detectWith(predicate, parameter);
 
634
        return result == null ? function.value() : result;
 
635
    }
 
636
 
 
637
    public <P> int countWith(Predicate2<? super T, ? super P> predicate, P parameter)
 
638
    {
 
639
        return Iterate.countWith(this.getDelegate(), predicate, parameter);
 
640
    }
 
641
 
 
642
    public <P> boolean anySatisfyWith(Predicate2<? super T, ? super P> predicate, P parameter)
 
643
    {
 
644
        return Iterate.anySatisfyWith(this.getDelegate(), predicate, parameter);
 
645
    }
 
646
 
 
647
    public <P> boolean allSatisfyWith(Predicate2<? super T, ? super P> predicate, P parameter)
 
648
    {
 
649
        return Iterate.allSatisfyWith(this.getDelegate(), predicate, parameter);
 
650
    }
 
651
 
 
652
    public <P> boolean noneSatisfyWith(Predicate2<? super T, ? super P> predicate, P parameter)
 
653
    {
 
654
        return Iterate.noneSatisfyWith(this.getDelegate(), predicate, parameter);
 
655
    }
 
656
 
 
657
    @Override
 
658
    public String toString()
 
659
    {
 
660
        return this.makeString("[", ", ", "]");
 
661
    }
 
662
 
 
663
    public String makeString()
 
664
    {
 
665
        return this.makeString(", ");
 
666
    }
 
667
 
 
668
    public String makeString(String separator)
 
669
    {
 
670
        return this.makeString("", separator, "");
 
671
    }
 
672
 
 
673
    public String makeString(String start, String separator, String end)
 
674
    {
 
675
        Appendable stringBuilder = new StringBuilder();
 
676
        this.appendString(stringBuilder, start, separator, end);
 
677
        return stringBuilder.toString();
 
678
    }
 
679
 
 
680
    public void appendString(Appendable appendable)
 
681
    {
 
682
        this.appendString(appendable, ", ");
 
683
    }
 
684
 
 
685
    public void appendString(Appendable appendable, String separator)
 
686
    {
 
687
        this.appendString(appendable, "", separator, "");
 
688
    }
 
689
 
 
690
    public void appendString(Appendable appendable, String start, String separator, String end)
 
691
    {
 
692
        IterableIterate.appendString(this, appendable, start, separator, end);
 
693
    }
 
694
 
 
695
    public <V> MutableMultimap<V, T> groupBy(
 
696
            Function<? super T, ? extends V> function)
 
697
    {
 
698
        return Iterate.groupBy(this.getDelegate(), function);
 
699
    }
 
700
 
 
701
    public <V, R extends MutableMultimap<V, T>> R groupBy(
 
702
            Function<? super T, ? extends V> function,
 
703
            R target)
 
704
    {
 
705
        return Iterate.groupBy(this.getDelegate(), function, target);
 
706
    }
 
707
 
 
708
    public <V> MutableMultimap<V, T> groupByEach(
 
709
            Function<? super T, ? extends Iterable<V>> function)
 
710
    {
 
711
        return Iterate.groupByEach(this.getDelegate(), function);
 
712
    }
 
713
 
 
714
    public <V> MutableMap<V, T> groupByUniqueKey(Function<? super T, ? extends V> function)
 
715
    {
 
716
        throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet");
 
717
    }
 
718
 
 
719
    public <V, R extends MutableMultimap<V, T>> R groupByEach(
 
720
            Function<? super T, ? extends Iterable<V>> function,
 
721
            R target)
 
722
    {
 
723
        return Iterate.groupByEach(this.getDelegate(), function, target);
 
724
    }
 
725
 
 
726
    public <S> MutableCollection<Pair<T, S>> zip(Iterable<S> that)
 
727
    {
 
728
        return this.wrap(Iterate.zip(this.getDelegate(), that));
 
729
    }
 
730
 
 
731
    public <S, R extends Collection<Pair<T, S>>> R zip(Iterable<S> that, R target)
 
732
    {
 
733
        return Iterate.zip(this.getDelegate(), that, target);
 
734
    }
 
735
 
 
736
    public MutableCollection<Pair<T, Integer>> zipWithIndex()
 
737
    {
 
738
        return this.wrap(Iterate.zipWithIndex(this.getDelegate()));
 
739
    }
 
740
 
 
741
    public <R extends Collection<Pair<T, Integer>>> R zipWithIndex(R target)
 
742
    {
 
743
        return Iterate.zipWithIndex(this.getDelegate(), target);
 
744
    }
 
745
 
 
746
    public RichIterable<RichIterable<T>> chunk(int size)
 
747
    {
 
748
        return MutableCollectionIterate.chunk(this, size);
 
749
    }
 
750
 
 
751
    public <K, V> MutableMap<K, V> aggregateInPlaceBy(
 
752
            Function<? super T, ? extends K> groupBy,
 
753
            Function0<? extends V> zeroValueFactory,
 
754
            Procedure2<? super V, ? super T> mutatingAggregator)
 
755
    {
 
756
        MutableMap<K, V> map = UnifiedMap.newMap();
 
757
        this.forEach(new MutatingAggregationProcedure<T, K, V>(map, groupBy, zeroValueFactory, mutatingAggregator));
 
758
        return map;
 
759
    }
 
760
 
 
761
    public <K, V> MutableMap<K, V> aggregateBy(
 
762
            Function<? super T, ? extends K> groupBy,
 
763
            Function0<? extends V> zeroValueFactory,
 
764
            Function2<? super V, ? super T, ? extends V> nonMutatingAggregator)
 
765
    {
 
766
        MutableMap<K, V> map = UnifiedMap.newMap();
 
767
        this.forEach(new NonMutatingAggregationProcedure<T, K, V>(map, groupBy, zeroValueFactory, nonMutatingAggregator));
 
768
        return map;
 
769
    }
 
770
}