-
Notifications
You must be signed in to change notification settings - Fork 585
/
RichIterable.java
2475 lines (2316 loc) · 91.7 KB
/
RichIterable.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2018 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.api;
import java.util.Collection;
import java.util.Comparator;
import java.util.DoubleSummaryStatistics;
import java.util.IntSummaryStatistics;
import java.util.LongSummaryStatistics;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Stream;
import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.MutableBagIterable;
import org.eclipse.collections.api.bag.sorted.MutableSortedBag;
import org.eclipse.collections.api.bimap.MutableBiMap;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
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.DoubleObjectToDoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.IntObjectToIntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.LongObjectToLongFunction;
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.block.procedure.Procedure2;
import org.eclipse.collections.api.collection.primitive.MutableBooleanCollection;
import org.eclipse.collections.api.collection.primitive.MutableByteCollection;
import org.eclipse.collections.api.collection.primitive.MutableCharCollection;
import org.eclipse.collections.api.collection.primitive.MutableDoubleCollection;
import org.eclipse.collections.api.collection.primitive.MutableFloatCollection;
import org.eclipse.collections.api.collection.primitive.MutableIntCollection;
import org.eclipse.collections.api.collection.primitive.MutableLongCollection;
import org.eclipse.collections.api.collection.primitive.MutableShortCollection;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.MutableMapIterable;
import org.eclipse.collections.api.map.primitive.ObjectDoubleMap;
import org.eclipse.collections.api.map.primitive.ObjectLongMap;
import org.eclipse.collections.api.map.sorted.MutableSortedMap;
import org.eclipse.collections.api.multimap.Multimap;
import org.eclipse.collections.api.multimap.MutableMultimap;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.partition.PartitionIterable;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.sorted.MutableSortedSet;
import org.eclipse.collections.api.tuple.Pair;
/**
* RichIterable is an interface which extends the InternalIterable interface with several internal iterator methods, from
* the Smalltalk Collection protocol. These include select, reject, detect, collect, injectInto, anySatisfy,
* allSatisfy. The API also includes converter methods to convert a RichIterable to a List (toList), to a sorted
* List (toSortedList), to a Set (toSet), and to a Map (toMap).
*
* @since 1.0
*/
public interface RichIterable<T>
extends InternalIterable<T>
{
@Override
default void forEach(Procedure<? super T> procedure)
{
this.each(procedure);
}
/**
* Returns the number of items in this iterable.
*
* @since 1.0
*/
int size();
/**
* Returns true if this iterable has zero items.
*
* @since 1.0
*/
boolean isEmpty();
/**
* The English equivalent of !this.isEmpty()
*
* @since 1.0
*/
default boolean notEmpty()
{
return !this.isEmpty();
}
/**
* Returns any element of an iterable.
*
* @return an element of an iterable.
* @since 10.0
*/
default T getAny()
{
return this.getFirst();
}
/**
* Returns the first element of an iterable. In the case of a List it is the element at the first index. In the
* case of any other Collection, it is the first element that would be returned during an iteration. If the
* iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to
* check to see if the iterable is empty to validate that a null result was not due to the container being empty.
* <p>
* The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use
* this method, the first element could be any element from the Set.
*
* @since 1.0
* @deprecated in 6.0. Use {@link OrderedIterable#getFirst()} instead.
*/
@Deprecated
T getFirst();
/**
* Returns the last element of an iterable. In the case of a List it is the element at the last index. In the case
* of any other Collection, it is the last element that would be returned during an iteration. If the iterable is
* empty, null is returned. If null is a valid element of the container, then a developer would need to check to
* see if the iterable is empty to validate that a null result was not due to the container being empty.
* <p>
* The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use
* this method, the last element could be any element from the Set.
*
* @since 1.0
* @deprecated in 6.0. Use {@link OrderedIterable#getLast()} instead.
*/
@Deprecated
T getLast();
/**
* Returns the element if the iterable has exactly one element. Otherwise, throw {@link IllegalStateException}.
*
* @return an element of an iterable.
* @throws IllegalStateException if iterable is empty or has multiple elements.
* @since 8.0
*/
default T getOnly()
{
if (this.size() == 1)
{
return this.getFirst();
}
throw new IllegalStateException("Size must be 1 but was " + this.size());
}
/**
* Returns true if the iterable has an element which responds true to element.equals(object).
*
* @since 1.0
*/
boolean contains(Object object);
/**
* Returns true if all elements in source are contained in this collection.
*
* @since 1.0
*/
boolean containsAllIterable(Iterable<?> source);
/**
* Returns true if all elements in source are contained in this collection.
*
* @see Collection#containsAll(Collection)
* @since 1.0
*/
boolean containsAll(Collection<?> source);
/**
* Returns true if all elements in the specified var arg array are contained in this collection.
*
* @since 1.0
*/
boolean containsAllArguments(Object... elements);
/**
* Executes the Procedure for each element in the iterable and returns {@code this}.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* RichIterable<Person> tapped =
* people.<b>tap</b>(person -> LOGGER.info(person.getName()));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* RichIterable<Person> tapped =
* people.<b>tap</b>(new Procedure<Person>()
* {
* public void value(Person person)
* {
* LOGGER.info(person.getName());
* }
* });
* </pre>
*
* @see #each(Procedure)
* @see #forEach(Procedure)
* @since 6.0
*/
RichIterable<T> tap(Procedure<? super T> procedure);
/**
* The procedure is executed for each element in the iterable.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* people.each(person -> LOGGER.info(person.getName()));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* people.each(new Procedure<Person>()
* {
* public void value(Person person)
* {
* LOGGER.info(person.getName());
* }
* });
* </pre>
* This method is a variant of {@link InternalIterable#forEach(Procedure)}
* that has a signature conflict with {@link Iterable#forEach(java.util.function.Consumer)}.
*
* @see InternalIterable#forEach(Procedure)
* @see Iterable#forEach(java.util.function.Consumer)
* @since 6.0
*/
@SuppressWarnings("UnnecessaryFullyQualifiedName")
void each(Procedure<? super T> procedure);
/**
* Returns all elements of the source collection that return true when evaluating the predicate. This method is also
* commonly called filter.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* RichIterable<Person> selected =
* people.<b>select</b>(person -> person.getAddress().getCity().equals("London"));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* RichIterable<Person> selected =
* people.<b>select</b>(new Predicate<Person>()
* {
* public boolean accept(Person person)
* {
* return person.getAddress().getCity().equals("London");
* }
* });
* </pre>
*
* @since 1.0
*/
RichIterable<T> select(Predicate<? super T> predicate);
/**
* Same as the select method with one parameter but uses the specified target collection for the results.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* MutableList<Person> selected =
* people.select(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* MutableList<Person> selected =
* people.select(new Predicate<Person>()
* {
* public boolean accept(Person person)
* {
* return person.person.getLastName().equals("Smith");
* }
* }, Lists.mutable.empty());
* </pre>
* <p>
*
* @param predicate a {@link Predicate} to use as the select criteria
* @param target the Collection to append to for all elements in this {@code RichIterable} that meet select criteria {@code predicate}
* @return {@code target}, which contains appended elements as a result of the select criteria
* @see #select(Predicate)
* @since 1.0
*/
<R extends Collection<T>> R select(Predicate<? super T> predicate, R target);
/**
* Similar to {@link #select(Predicate)}, except with an evaluation parameter for the second generic argument in {@link Predicate2}.
* <p>
* E.g. return a {@link Collection} of Person elements where the person has an age <b>greater than or equal to</b> 18 years
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* RichIterable<Person> selected =
* people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* RichIterable<Person> selected =
* people.selectWith(new Predicate2<Person, Integer>()
* {
* public boolean accept(Person person, Integer age)
* {
* return person.getAge()>= age;
* }
* }, Integer.valueOf(18));
* </pre>
*
* @param predicate a {@link Predicate2} to use as the select criteria
* @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code predicate}
* @see #select(Predicate)
* @since 5.0
*/
<P> RichIterable<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter);
/**
* Similar to {@link #select(Predicate, Collection)}, except with an evaluation parameter for the second generic argument in {@link Predicate2}.
* <p>
* E.g. return a {@link Collection} of Person elements where the person has an age <b>greater than or equal to</b> 18 years
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* MutableList<Person> selected =
* people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18), Lists.mutable.empty());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* MutableList<Person> selected =
* people.selectWith(new Predicate2<Person, Integer>()
* {
* public boolean accept(Person person, Integer age)
* {
* return person.getAge()>= age;
* }
* }, Integer.valueOf(18), Lists.mutable.empty());
* </pre>
*
* @param predicate a {@link Predicate2} to use as the select criteria
* @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code predicate}
* @param targetCollection the Collection to append to for all elements in this {@code RichIterable} that meet select criteria {@code predicate}
* @return {@code targetCollection}, which contains appended elements as a result of the select criteria
* @see #select(Predicate)
* @see #select(Predicate, Collection)
* @since 1.0
*/
<P, R extends Collection<T>> R selectWith(
Predicate2<? super T, ? super P> predicate,
P parameter,
R targetCollection);
/**
* Returns all elements of the source collection that return false when evaluating of the predicate. This method is also
* sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)).
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* RichIterable<Person> rejected =
* people.reject(person -> person.person.getLastName().equals("Smith"));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* RichIterable<Person> rejected =
* people.reject(new Predicate<Person>()
* {
* public boolean accept(Person person)
* {
* return person.person.getLastName().equals("Smith");
* }
* });
* </pre>
*
* @param predicate a {@link Predicate} to use as the reject criteria
* @return a RichIterable that contains elements that cause {@link Predicate#accept(Object)} method to evaluate to false
* @since 1.0
*/
RichIterable<T> reject(Predicate<? super T> predicate);
/**
* Similar to {@link #reject(Predicate)}, except with an evaluation parameter for the second generic argument in {@link Predicate2}.
* <p>
* E.g. return a {@link Collection} of Person elements where the person has an age <b>greater than or equal to</b> 18 years
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* RichIterable<Person> rejected =
* people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* MutableList<Person> rejected =
* people.rejectWith(new Predicate2<Person, Integer>()
* {
* public boolean accept(Person person, Integer age)
* {
* return person.getAge() < age;
* }
* }, Integer.valueOf(18));
* </pre>
*
* @param predicate a {@link Predicate2} to use as the select criteria
* @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code predicate}
* @see #select(Predicate)
* @since 5.0
*/
<P> RichIterable<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter);
/**
* Same as the reject method with one parameter but uses the specified target collection for the results.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* MutableList<Person> rejected =
* people.reject(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* MutableList<Person> rejected =
* people.reject(new Predicate<Person>()
* {
* public boolean accept(Person person)
* {
* return person.person.getLastName().equals("Smith");
* }
* }, Lists.mutable.empty());
* </pre>
*
* @param predicate a {@link Predicate} to use as the reject criteria
* @param target the Collection to append to for all elements in this {@code RichIterable} that cause {@code Predicate#accept(Object)} method to evaluate to false
* @return {@code target}, which contains appended elements as a result of the reject criteria
* @since 1.0
*/
<R extends Collection<T>> R reject(Predicate<? super T> predicate, R target);
/**
* Similar to {@link #reject(Predicate, Collection)}, except with an evaluation parameter for the second generic argument in {@link Predicate2}.
* <p>
* E.g. return a {@link Collection} of Person elements where the person has an age <b>greater than or equal to</b> 18 years
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* MutableList<Person> rejected =
* people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18), Lists.mutable.empty());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* MutableList<Person> rejected =
* people.rejectWith(new Predicate2<Person, Integer>()
* {
* public boolean accept(Person person, Integer age)
* {
* return person.getAge() < age;
* }
* }, Integer.valueOf(18), Lists.mutable.empty());
* </pre>
*
* @param predicate a {@link Predicate2} to use as the reject criteria
* @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code predicate}
* @param targetCollection the Collection to append to for all elements in this {@code RichIterable} that cause {@code Predicate#accept(Object)} method to evaluate to false
* @return {@code targetCollection}, which contains appended elements as a result of the reject criteria
* @see #reject(Predicate)
* @see #reject(Predicate, Collection)
* @since 1.0
*/
<P, R extends Collection<T>> R rejectWith(
Predicate2<? super T, ? super P> predicate,
P parameter,
R targetCollection);
/**
* Filters a collection into a PartitionedIterable based on the evaluation of the predicate.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* PartitionIterable<Person> newYorkersAndNonNewYorkers =
* people.<b>partition</b>(person -> person.getAddress().getState().getName().equals("New York"));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* PartitionIterable<Person> newYorkersAndNonNewYorkers =
* people.<b>partition</b>(new Predicate<Person>()
* {
* public boolean accept(Person person)
* {
* return person.getAddress().getState().getName().equals("New York");
* }
* });
* </pre>
*
* @since 1.0.
*/
PartitionIterable<T> partition(Predicate<? super T> predicate);
/**
* Filters a collection into a PartitionIterable based on the evaluation of the predicate.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* PartitionIterable<Person> newYorkersAndNonNewYorkers =
* people.<b>partitionWith</b>((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* PartitionIterable<Person> newYorkersAndNonNewYorkers =
* people.<b>partitionWith</b>(new Predicate2<Person, String>()
* {
* public boolean accept(Person person, String state)
* {
* return person.getAddress().getState().getName().equals(state);
* }
* }, "New York");
* </pre>
*
* @since 5.0.
*/
<P> PartitionIterable<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter);
/**
* Returns all elements of the source collection that are instances of the Class {@code clazz}.
*
* <pre>
* RichIterable<Integer> integers =
* List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
* </pre>
*
* @since 2.0
*/
<S> RichIterable<S> selectInstancesOf(Class<S> clazz);
/**
* Returns a new collection with the results of applying the specified function on each element of the source
* collection. This method is also commonly called transform or map.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* RichIterable<String> names =
* people.collect(person -> person.getFirstName() + " " + person.getLastName());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* RichIterable<String> names =
* people.collect(new Function<Person, String>()
* {
* public String valueOf(Person person)
* {
* return person.getFirstName() + " " + person.getLastName();
* }
* });
* </pre>
*
* @since 1.0
*/
<V> RichIterable<V> collect(Function<? super T, ? extends V> function);
/**
* Same as {@link #collect(Function)}, except that the results are gathered into the specified {@code target}
* collection.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* MutableList<String> names =
* people.collect(person -> person.getFirstName() + " " + person.getLastName(), Lists.mutable.empty());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* MutableList<String> names =
* people.collect(new Function<Person, String>()
* {
* public String valueOf(Person person)
* {
* return person.getFirstName() + " " + person.getLastName();
* }
* }, Lists.mutable.empty());
* </pre>
*
* @param function a {@link Function} to use as the collect transformation function
* @param target the Collection to append to for all elements in this {@code RichIterable} that meet select criteria {@code function}
* @return {@code target}, which contains appended elements as a result of the collect transformation
* @see #collect(Function)
* @since 1.0
*/
<V, R extends Collection<V>> R collect(Function<? super T, ? extends V> function, R target);
/**
* Returns a new primitive {@code boolean} iterable with the results of applying the specified function on each element
* of the source collection. This method is also commonly called transform or map.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* BooleanIterable licenses =
* people.collectBoolean(person -> person.hasDrivingLicense());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* BooleanIterable licenses =
* people.collectBoolean(new BooleanFunction<Person>()
* {
* public boolean booleanValueOf(Person person)
* {
* return person.hasDrivingLicense();
* }
* });
* </pre>
*
* @since 4.0
*/
BooleanIterable collectBoolean(BooleanFunction<? super T> booleanFunction);
/**
* Same as {@link #collectBoolean(BooleanFunction)}, except that the results are gathered into the specified {@code target}
* collection.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* BooleanArrayList licenses =
* people.collectBoolean(person -> person.hasDrivingLicense(), new BooleanArrayList());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* BooleanArrayList licenses =
* people.collectBoolean(new BooleanFunction<Person>()
* {
* public boolean booleanValueOf(Person person)
* {
* return person.hasDrivingLicense();
* }
* }, new BooleanArrayList());
* </pre>
*
* @param booleanFunction a {@link BooleanFunction} to use as the collect transformation function
* @param target the MutableBooleanCollection to append to for all elements in this {@code RichIterable}
* @return {@code target}, which contains appended elements as a result of the collect transformation
* @since 5.0
*/
<R extends MutableBooleanCollection> R collectBoolean(BooleanFunction<? super T> booleanFunction, R target);
/**
* Returns a new primitive {@code byte} iterable with the results of applying the specified function on each element
* of the source collection. This method is also commonly called transform or map.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* ByteIterable bytes =
* people.collectByte(person -> person.getCode());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* ByteIterable bytes =
* people.collectByte(new ByteFunction<Person>()
* {
* public byte byteValueOf(Person person)
* {
* return person.getCode();
* }
* });
* </pre>
*
* @since 4.0
*/
ByteIterable collectByte(ByteFunction<? super T> byteFunction);
/**
* Same as {@link #collectByte(ByteFunction)}, except that the results are gathered into the specified {@code target}
* collection.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* ByteArrayList bytes =
* people.collectByte(person -> person.getCode(), new ByteArrayList());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* ByteArrayList bytes =
* people.collectByte(new ByteFunction<Person>()
* {
* public byte byteValueOf(Person person)
* {
* return person.getCode();
* }
* }, new ByteArrayList());
* </pre>
*
* @param byteFunction a {@link ByteFunction} to use as the collect transformation function
* @param target the MutableByteCollection to append to for all elements in this {@code RichIterable}
* @return {@code target}, which contains appended elements as a result of the collect transformation
* @since 5.0
*/
<R extends MutableByteCollection> R collectByte(ByteFunction<? super T> byteFunction, R target);
/**
* Returns a new primitive {@code char} iterable with the results of applying the specified function on each element
* of the source collection. This method is also commonly called transform or map.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* CharIterable chars =
* people.collectChar(person -> person.getMiddleInitial());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* CharIterable chars =
* people.collectChar(new CharFunction<Person>()
* {
* public char charValueOf(Person person)
* {
* return person.getMiddleInitial();
* }
* });
* </pre>
*
* @since 4.0
*/
CharIterable collectChar(CharFunction<? super T> charFunction);
/**
* Same as {@link #collectChar(CharFunction)}, except that the results are gathered into the specified {@code target}
* collection.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* CharArrayList chars =
* people.collectChar(person -> person.getMiddleInitial(), new CharArrayList());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* CharArrayList chars =
* people.collectChar(new CharFunction<Person>()
* {
* public char charValueOf(Person person)
* {
* return person.getMiddleInitial();
* }
* }, new CharArrayList());
* </pre>
*
* @param charFunction a {@link CharFunction} to use as the collect transformation function
* @param target the MutableCharCollection to append to for all elements in this {@code RichIterable}
* @return {@code target}, which contains appended elements as a result of the collect transformation
* @since 5.0
*/
<R extends MutableCharCollection> R collectChar(CharFunction<? super T> charFunction, R target);
/**
* Returns a new primitive {@code double} iterable with the results of applying the specified function on each element
* of the source collection. This method is also commonly called transform or map.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* DoubleIterable doubles =
* people.collectDouble(person -> person.getMilesFromNorthPole());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* DoubleIterable doubles =
* people.collectDouble(new DoubleFunction<Person>()
* {
* public double doubleValueOf(Person person)
* {
* return person.getMilesFromNorthPole();
* }
* });
* </pre>
*
* @since 4.0
*/
DoubleIterable collectDouble(DoubleFunction<? super T> doubleFunction);
/**
* Same as {@link #collectDouble(DoubleFunction)}, except that the results are gathered into the specified {@code target}
* collection.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* DoubleArrayList doubles =
* people.collectDouble(person -> person.getMilesFromNorthPole(), new DoubleArrayList());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* DoubleArrayList doubles =
* people.collectDouble(new DoubleFunction<Person>()
* {
* public double doubleValueOf(Person person)
* {
* return person.getMilesFromNorthPole();
* }
* }, new DoubleArrayList());
* </pre>
*
* @param doubleFunction a {@link DoubleFunction} to use as the collect transformation function
* @param target the MutableDoubleCollection to append to for all elements in this {@code RichIterable}
* @return {@code target}, which contains appended elements as a result of the collect transformation
* @since 5.0
*/
<R extends MutableDoubleCollection> R collectDouble(DoubleFunction<? super T> doubleFunction, R target);
/**
* Returns a new primitive {@code float} iterable with the results of applying the specified function on each element
* of the source collection. This method is also commonly called transform or map.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* FloatIterable floats =
* people.collectFloat(person -> person.getHeightInInches());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* FloatIterable floats =
* people.collectFloat(new FloatFunction<Person>()
* {
* public float floatValueOf(Person person)
* {
* return person.getHeightInInches();
* }
* });
* </pre>
*
* @since 4.0
*/
FloatIterable collectFloat(FloatFunction<? super T> floatFunction);
/**
* Same as {@link #collectFloat(FloatFunction)}, except that the results are gathered into the specified {@code target}
* collection.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* FloatArrayList floats =
* people.collectFloat(person -> person.getHeightInInches(), new FloatArrayList());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* FloatArrayList floats =
* people.collectFloat(new FloatFunction<Person>()
* {
* public float floatValueOf(Person person)
* {
* return person.getHeightInInches();
* }
* }, new FloatArrayList());
* </pre>
*
* @param floatFunction a {@link FloatFunction} to use as the collect transformation function
* @param target the MutableFloatCollection to append to for all elements in this {@code RichIterable}
* @return {@code target}, which contains appended elements as a result of the collect transformation
* @since 5.0
*/
<R extends MutableFloatCollection> R collectFloat(FloatFunction<? super T> floatFunction, R target);
/**
* Returns a new primitive {@code int} iterable with the results of applying the specified function on each element
* of the source collection. This method is also commonly called transform or map.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* IntIterable ints =
* people.collectInt(person -> person.getAge());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* IntIterable ints =
* people.collectInt(new IntFunction<Person>()
* {
* public int intValueOf(Person person)
* {
* return person.getAge();
* }
* });
* </pre>
*
* @since 4.0
*/
IntIterable collectInt(IntFunction<? super T> intFunction);
/**
* Same as {@link #collectInt(IntFunction)}, except that the results are gathered into the specified {@code target}
* collection.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* IntArrayList ints =
* people.collectInt(person -> person.getAge(), new IntArrayList());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* IntArrayList ints =
* people.collectInt(new IntFunction<Person>()
* {
* public int intValueOf(Person person)
* {
* return person.getAge();
* }
* }, new IntArrayList());
* </pre>
*
* @param intFunction a {@link IntFunction} to use as the collect transformation function
* @param target the MutableIntCollection to append to for all elements in this {@code RichIterable}
* @return {@code target}, which contains appended elements as a result of the collect transformation
* @since 5.0
*/
<R extends MutableIntCollection> R collectInt(IntFunction<? super T> intFunction, R target);
/**
* Returns a new primitive {@code long} iterable with the results of applying the specified function on each element
* of the source collection. This method is also commonly called transform or map.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* LongIterable longs =
* people.collectLong(person -> person.getGuid());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* LongIterable longs =
* people.collectLong(new LongFunction<Person>()
* {
* public long longValueOf(Person person)
* {
* return person.getGuid();
* }
* });
* </pre>
*
* @since 4.0
*/
LongIterable collectLong(LongFunction<? super T> longFunction);
/**
* Same as {@link #collectLong(LongFunction)}, except that the results are gathered into the specified {@code target}
* collection.
* <p>
* Example using a Java 8 lambda expression:
* <pre>
* LongArrayList longs =
* people.collectLong(person -> person.getGuid(), new LongArrayList());
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* LongArrayList longs =
* people.collectLong(new LongFunction<Person>()
* {
* public long longValueOf(Person person)
* {
* return person.getGuid();
* }
* }, new LongArrayList());
* </pre>
*
* @param longFunction a {@link LongFunction} to use as the collect transformation function
* @param target the MutableLongCollection to append to for all elements in this {@code RichIterable}