-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
CollectionUtils.java
774 lines (674 loc) · 25.9 KB
/
CollectionUtils.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
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.util;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.gradle.api.Action;
import org.gradle.api.Transformer;
import org.gradle.api.specs.Spec;
import org.gradle.internal.Factory;
import org.gradle.internal.Pair;
import org.gradle.internal.Transformers;
import org.gradle.internal.deprecation.DeprecationLogger;
import javax.annotation.Nullable;
import java.lang.reflect.Array;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import static org.gradle.internal.Cast.cast;
import static org.gradle.internal.Cast.castNullable;
import static org.gradle.internal.Cast.uncheckedNonnullCast;
/**
* This class is only here to maintain binary compatibility with existing plugins.
* <p>
* Plugins should prefer external collection frameworks over this class.
* Internally, all code should use {@link org.gradle.util.internal.CollectionUtils}.
*
* @deprecated Will be removed in Gradle 9.0.
*/
@Deprecated
public abstract class CollectionUtils {
private static void logDeprecation(int upgradeGuideMajorVersion) {
DeprecationLogger.deprecateType(CollectionUtils.class)
.willBeRemovedInGradle9()
.withUpgradeGuideSection(upgradeGuideMajorVersion, "org_gradle_util_reports_deprecations")
.nagUser();
}
public CollectionUtils() {
logDeprecation(7);
}
/**
* Returns null if the collection is empty otherwise expects a {@link #single(Iterable)} element to be found.
*/
@Nullable
public static <T> T findSingle(Iterable<T> source) {
logDeprecation(7);
return Iterables.isEmpty(source) ? null : singleInternal(source);
}
/**
* Returns the single element in the collection or throws.
*/
public static <T> T single(Iterable<? extends T> source) {
logDeprecation(7);
return singleInternal(source);
}
private static <T> T singleInternal(Iterable<? extends T> source) {
Iterator<? extends T> iterator = source.iterator();
if (!iterator.hasNext()) {
throw new NoSuchElementException("Expecting collection with single element, got none.");
}
T element = iterator.next();
if (iterator.hasNext()) {
throw new IllegalArgumentException("Expecting collection with single element, got multiple.");
}
return element;
}
public static <T> Collection<? extends T> checkedCast(Class<T> type, Collection<?> input) {
logDeprecation(7);
for (Object o : input) {
castNullable(type, o);
}
return uncheckedNonnullCast(input);
}
@Nullable
public static <T> T findFirst(Iterable<? extends T> source, Spec<? super T> filter) {
logDeprecation(7);
for (T item : source) {
if (filter.isSatisfiedBy(item)) {
return item;
}
}
return null;
}
@Nullable
public static <T> T findFirst(T[] source, Spec<? super T> filter) {
logDeprecation(7);
for (T thing : source) {
if (filter.isSatisfiedBy(thing)) {
return thing;
}
}
return null;
}
public static <T> T first(Iterable<? extends T> source) {
logDeprecation(7);
return source.iterator().next();
}
public static <T> boolean any(Iterable<? extends T> source, Spec<? super T> filter) {
return findFirst(source, filter) != null;
}
public static <T> boolean any(T[] source, Spec<? super T> filter) {
return findFirst(source, filter) != null;
}
public static <T> Set<T> filter(Set<? extends T> set, Spec<? super T> filter) {
return filter(set, new LinkedHashSet<T>(), filter);
}
public static <T> List<T> filter(List<? extends T> list, Spec<? super T> filter) {
return filter(list, Lists.<T>newArrayListWithCapacity(list.size()), filter);
}
public static <T> List<T> filter(T[] array, Spec<? super T> filter) {
return filter(Arrays.asList(array), Lists.<T>newArrayListWithCapacity(array.length), filter);
}
/**
* Returns a sorted copy of the provided collection of things. Uses the provided comparator to sort.
*/
public static <T> List<T> sort(Iterable<? extends T> things, Comparator<? super T> comparator) {
List<T> copy = toMutableList(things);
Collections.sort(copy, comparator);
return copy;
}
/**
* Returns a sorted copy of the provided collection of things. Uses the natural ordering of the things.
*/
public static <T extends Comparable<T>> List<T> sort(Iterable<T> things) {
List<T> copy = toMutableList(things);
Collections.sort(copy);
return copy;
}
public static <T, C extends Collection<T>> C filter(Iterable<? extends T> source, C destination, Spec<? super T> filter) {
logDeprecation(7);
for (T item : source) {
if (filter.isSatisfiedBy(item)) {
destination.add(item);
}
}
return destination;
}
public static <K, V> Map<K, V> filter(Map<K, V> map, Spec<Map.Entry<K, V>> filter) {
return filter(map, new HashMap<K, V>(), filter);
}
public static <K, V> Map<K, V> filter(Map<K, V> map, Map<K, V> destination, Spec<Map.Entry<K, V>> filter) {
logDeprecation(7);
for (Map.Entry<K, V> entry : map.entrySet()) {
if (filter.isSatisfiedBy(entry)) {
destination.put(entry.getKey(), entry.getValue());
}
}
return destination;
}
public static <R, I> R[] collectArray(I[] list, Class<R> newType, Transformer<? extends R, ? super I> transformer) {
@SuppressWarnings("unchecked") R[] destination = (R[]) Array.newInstance(newType, list.length);
return collectArray(list, destination, transformer);
}
public static <R, I> R[] collectArray(I[] list, R[] destination, Transformer<? extends R, ? super I> transformer) {
logDeprecation(7);
assert list.length <= destination.length;
for (int i = 0; i < list.length; ++i) {
destination[i] = transformer.transform(list[i]);
}
return destination;
}
public static <R, I> List<R> collect(I[] list, Transformer<? extends R, ? super I> transformer) {
return collect(Arrays.asList(list), transformer);
}
public static <R, I> Set<R> collect(Set<? extends I> set, Transformer<? extends R, ? super I> transformer) {
return collect(set, new HashSet<R>(set.size()), transformer);
}
public static <R, I> List<R> collect(Iterable<? extends I> source, Transformer<? extends R, ? super I> transformer) {
if (source instanceof Collection<?>) {
Collection<? extends I> collection = uncheckedNonnullCast(source);
return collect(source, new ArrayList<R>(collection.size()), transformer);
} else {
return collect(source, new LinkedList<R>(), transformer);
}
}
public static <R, I, C extends Collection<R>> C collect(Iterable<? extends I> source, C destination, Transformer<? extends R, ? super I> transformer) {
logDeprecation(7);
return collectInternal(source, destination, transformer);
}
private static <R, I, C extends Collection<R>> C collectInternal(Iterable<? extends I> source, C destination, Transformer<? extends R, ? super I> transformer) {
for (I item : source) {
destination.add(transformer.transform(item));
}
return destination;
}
public static List<String> toStringList(Iterable<?> iterable) {
return collect(iterable, new LinkedList<String>(), String::valueOf);
}
/**
* Recursively unpacks all the given things into a flat list.
*
* Nulls are not removed, they are left intact.
*
* @param things The things to flatten
* @return A flattened list of the given things
*/
public static List<?> flattenCollections(Object... things) {
return flattenCollections(Object.class, things);
}
/**
* Recursively unpacks all the given things into a flat list, ensuring they are of a certain type.
*
* Nulls are not removed, they are left intact.
*
* If a non null object cannot be cast to the target type, a ClassCastException will be thrown.
*
* @param things The things to flatten
* @param <T> The target type in the flattened list
* @return A flattened list of the given things
*/
public static <T> List<T> flattenCollections(Class<T> type, Object... things) {
logDeprecation(7);
return flattenCollectionsInternal(type, things);
}
private static <T> List<T> flattenCollectionsInternal(Class<T> type, Object... things) {
if (things == null) {
return Collections.singletonList(null);
} else if (things.length == 0) {
return Collections.emptyList();
} else if (things.length == 1) {
Object thing = things[0];
if (thing == null) {
return Collections.singletonList(null);
}
// Casts to Class below are to workaround Eclipse compiler bug
// See: https://github.com/gradle/gradle/pull/200
if (thing.getClass().isArray()) {
Object[] thingArray = (Object[]) thing;
List<T> list = new ArrayList<T>(thingArray.length);
for (Object thingThing : thingArray) {
list.addAll(flattenCollections(type, thingThing));
}
return list;
}
if (thing instanceof Collection) {
Collection<?> collection = (Collection<?>) thing;
List<T> list = new ArrayList<T>();
for (Object element : collection) {
list.addAll(flattenCollections(type, element));
}
return list;
}
return Collections.singletonList(cast(type, thing));
} else {
List<T> list = new ArrayList<T>();
for (Object thing : things) {
list.addAll(flattenCollections(type, thing));
}
return list;
}
}
public static <T> List<T> toList(Iterable<? extends T> things) {
if (things instanceof List) {
logDeprecation(7);
@SuppressWarnings("unchecked") List<T> castThings = (List<T>) things;
return castThings;
}
return toMutableList(things);
}
public static <T> List<T> toList(Enumeration<? extends T> things) {
logDeprecation(7);
AbstractList<T> list = new ArrayList<T>();
while (things.hasMoreElements()) {
list.add(things.nextElement());
}
return list;
}
private static <T> List<T> toMutableList(Iterable<? extends T> things) {
logDeprecation(7);
if (things == null) {
return new ArrayList<T>(0);
}
List<T> list = new ArrayList<T>();
for (T thing : things) {
list.add(thing);
}
return list;
}
public static <T> List<T> intersection(Collection<? extends Collection<T>> availableValuesByDescriptor) {
logDeprecation(7);
List<T> result = new ArrayList<T>();
Iterator<? extends Collection<T>> iterator = availableValuesByDescriptor.iterator();
if (iterator.hasNext()) {
Collection<T> firstSet = iterator.next();
result.addAll(firstSet);
while (iterator.hasNext()) {
Collection<T> next = iterator.next();
result.retainAll(next);
}
}
return result;
}
public static <T> List<T> toList(T[] things) {
logDeprecation(7);
if (things == null || things.length == 0) {
return new ArrayList<T>(0);
}
List<T> list = new ArrayList<T>(things.length);
Collections.addAll(list, things);
return list;
}
public static <T> Set<T> toSet(Iterable<? extends T> things) {
logDeprecation(7);
if (things == null) {
return new HashSet<T>(0);
}
if (things instanceof Set) {
@SuppressWarnings("unchecked") Set<T> castThings = (Set<T>) things;
return castThings;
}
Set<T> set = new LinkedHashSet<T>();
for (T thing : things) {
set.add(thing);
}
return set;
}
public static <E> List<E> compact(List<E> list) {
logDeprecation(7);
boolean foundAtLeastOneNull = false;
List<E> compacted = null;
int i = 0;
for (E element : list) {
if (element == null) {
if (!foundAtLeastOneNull) {
compacted = new ArrayList<E>(list.size());
if (i > 0) {
compacted.addAll(list.subList(0, i));
}
}
foundAtLeastOneNull = true;
} else if (foundAtLeastOneNull) {
compacted.add(element);
}
++i;
}
return foundAtLeastOneNull ? compacted : list;
}
public static <C extends Collection<String>> C stringize(Iterable<?> source, C destination) {
logDeprecation(7);
return stringizeInternal(source, destination);
}
public static List<String> stringize(Collection<?> source) {
logDeprecation(8);
return stringizeInternal(source, new ArrayList<String>(source.size()));
}
private static <C extends Collection<String>> C stringizeInternal(Iterable<?> source, C destination) {
return collectInternal(source, destination, String::valueOf);
}
public static <E> boolean replace(List<E> list, Spec<? super E> filter, Transformer<? extends E, ? super E> transformer) {
logDeprecation(7);
boolean replaced = false;
int i = 0;
for (E it : list) {
if (filter.isSatisfiedBy(it)) {
list.set(i, transformer.transform(it));
replaced = true;
}
++i;
}
return replaced;
}
public static <K, V> void collectMap(Map<K, V> destination, Iterable<? extends V> items, Transformer<? extends K, ? super V> keyGenerator) {
logDeprecation(7);
for (V item : items) {
destination.put(keyGenerator.transform(item), item);
}
}
/**
* Given a set of values, derive a set of keys and return a map
*/
public static <K, V> Map<K, V> collectMap(Iterable<? extends V> items, Transformer<? extends K, ? super V> keyGenerator) {
Map<K, V> map = new LinkedHashMap<K, V>();
collectMap(map, items, keyGenerator);
return map;
}
public static <K, V> void collectMapValues(Map<K, V> destination, Iterable<? extends K> keys, Transformer<? extends V, ? super K> keyGenerator) {
logDeprecation(7);
for (K item : keys) {
destination.put(item, keyGenerator.transform(item));
}
}
/**
* Given a set of keys, derive a set of values and return a map
*/
public static <K, V> Map<K, V> collectMapValues(Iterable<? extends K> keys, Transformer<? extends V, ? super K> keyGenerator) {
Map<K, V> map = new LinkedHashMap<K, V>();
collectMapValues(map, keys, keyGenerator);
return map;
}
public static <T> boolean every(Iterable<? extends T> things, Spec<? super T> predicate) {
logDeprecation(7);
for (T thing : things) {
if (!predicate.isSatisfiedBy(thing)) {
return false;
}
}
return true;
}
/**
* Utility for adding an iterable to a collection.
*
* @param t1 The collection to add to
* @param t2 The iterable to add each item of to the collection
* @param <T> The element type of t1
* @return t1
*/
public static <T, C extends Collection<? super T>> C addAll(C t1, Iterable<? extends T> t2) {
logDeprecation(7);
for (T t : t2) {
t1.add(t);
}
return t1;
}
/**
* Utility for adding an array to a collection.
*
* @param t1 The collection to add to
* @param t2 The iterable to add each item of to the collection
* @param <T> The element type of t1
* @return t1
*/
public static <T, C extends Collection<? super T>> C addAll(C t1, T... t2) {
logDeprecation(7);
Collections.addAll(t1, t2);
return t1;
}
/**
* The result of diffing two sets.
*
* @param <T> The type of element the sets contain
* @see CollectionUtils#diffSetsBy(java.util.Set, java.util.Set, org.gradle.api.Transformer)
*/
public static class SetDiff<T> {
public Set<T> leftOnly = new HashSet<T>();
public Set<Pair<T, T>> common = new HashSet<Pair<T, T>>();
public Set<T> rightOnly = new HashSet<T>();
public SetDiff() {
this(true);
}
private SetDiff(boolean logDeprecation) {
if (logDeprecation) {
logDeprecation(7);
}
}
}
/**
* Provides a “diff report” of how the two sets are similar and how they are different, comparing the entries by some aspect.
*
* The transformer is used to generate the value to use to compare the entries by. That is, the entries are not compared by equals by an attribute or characteristic.
*
* The transformer is expected to produce a unique value for each entry in a single set. Behaviour is undefined if this condition is not met.
*
* @param left The set on the “left” side of the comparison.
* @param right The set on the “right” side of the comparison.
* @param compareBy Provides the value to compare entries from either side by
* @param <T> The type of the entry objects
* @return A representation of the difference
*/
public static <T> SetDiff<T> diffSetsBy(Set<? extends T> left, Set<? extends T> right, Transformer<?, T> compareBy) {
logDeprecation(7);
if (left == null) {
throw new NullPointerException("'left' set is null");
}
if (right == null) {
throw new NullPointerException("'right' set is null");
}
SetDiff<T> setDiff = new SetDiff<T>(false);
Map<Object, T> indexedLeft = collectMap(left, compareBy);
Map<Object, T> indexedRight = collectMap(right, compareBy);
for (Map.Entry<Object, T> leftEntry : indexedLeft.entrySet()) {
T rightValue = indexedRight.remove(leftEntry.getKey());
if (rightValue == null) {
setDiff.leftOnly.add(leftEntry.getValue());
} else {
Pair<T, T> pair = Pair.of(leftEntry.getValue(), rightValue);
setDiff.common.add(pair);
}
}
for (T rightValue : indexedRight.values()) {
setDiff.rightOnly.add(rightValue);
}
return setDiff;
}
/**
* Creates a string with {@code toString()} of each object with the given separator.
*
* <pre>
* expect:
* join(",", new Object[]{"a"}) == "a"
* join(",", new Object[]{"a", "b", "c"}) == "a,b,c"
* join(",", new Object[]{}) == ""
* </pre>
*
* The {@code separator} must not be null and {@code objects} must not be null.
*
* @param separator The string by which to join each string representation
* @param objects The objects to join the string representations of
* @return The joined string
*/
public static String join(String separator, Object[] objects) {
return join(separator, objects == null ? null : Arrays.asList(objects));
}
/**
* Creates a string with {@code toString()} of each object with the given separator.
*
* <pre>
* expect:
* join(",", ["a"]) == "a"
* join(",", ["a", "b", "c"]) == "a,b,c"
* join(",", []) == ""
* </pre>
*
* The {@code separator} must not be null and {@code objects} must not be null.
*
* @param separator The string by which to join each string representation
* @param objects The objects to join the string representations of
* @return The joined string
*/
public static String join(String separator, Iterable<?> objects) {
logDeprecation(7);
if (separator == null) {
throw new NullPointerException("The 'separator' cannot be null");
}
if (objects == null) {
throw new NullPointerException("The 'objects' cannot be null");
}
StringBuilder string = new StringBuilder();
Iterator<?> iterator = objects.iterator();
if (iterator.hasNext()) {
string.append(iterator.next().toString());
while (iterator.hasNext()) {
string.append(separator);
string.append(iterator.next().toString());
}
}
return string.toString();
}
/**
* Partition given Collection into a Pair of Collections.
*
* <pre>Left</pre> Collection containing entries that satisfy the given predicate
* <pre>Right</pre> Collection containing entries that do NOT satisfy the given predicate
*/
public static <T> Pair<Collection<T>, Collection<T>> partition(Iterable<T> items, Spec<? super T> predicate) {
logDeprecation(7);
Preconditions.checkNotNull(items, "Cannot partition null Collection");
Preconditions.checkNotNull(predicate, "Cannot apply null Spec when partitioning");
Collection<T> left = new LinkedList<T>();
Collection<T> right = new LinkedList<T>();
for (T item : items) {
if (predicate.isSatisfiedBy(item)) {
left.add(item);
} else {
right.add(item);
}
}
return Pair.of(left, right);
}
/**
* Injection step.
*
* @param <T> target type.
* @param <I> item type.
*/
@Deprecated
public static class InjectionStep<T, I> {
private final T target;
private final I item;
public InjectionStep(T target, I item) {
this(target, item, true);
}
private InjectionStep(T target, I item, boolean logDeprecation) {
this.target = target;
this.item = item;
if (logDeprecation) {
logDeprecation(7);
}
}
public T getTarget() {
return target;
}
public I getItem() {
return item;
}
}
public static <T, I> T inject(T target, Iterable<? extends I> items, Action<InjectionStep<T, I>> action) {
logDeprecation(7);
if (target == null) {
throw new NullPointerException("The 'target' cannot be null");
}
if (items == null) {
throw new NullPointerException("The 'items' cannot be null");
}
if (action == null) {
throw new NullPointerException("The 'action' cannot be null");
}
for (I item : items) {
action.execute(new InjectionStep<T, I>(target, item, false));
}
return target;
}
public static <K, V> Map<K, Collection<V>> groupBy(Iterable<? extends V> iterable, Transformer<? extends K, V> grouper) {
logDeprecation(7);
ImmutableListMultimap.Builder<K, V> builder = ImmutableListMultimap.builder();
for (V element : iterable) {
K key = grouper.transform(element);
builder.put(key, element);
}
return builder.build().asMap();
}
public static <T> Iterable<? extends T> unpack(final Iterable<? extends Factory<? extends T>> factories) {
logDeprecation(7);
return new Iterable<T>() {
private final Iterator<? extends Factory<? extends T>> delegate = factories.iterator();
@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
@Override
public boolean hasNext() {
return delegate.hasNext();
}
@Override
public T next() {
return delegate.next().create();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
@Nullable
public static <T> List<T> nonEmptyOrNull(Iterable<T> iterable) {
logDeprecation(7);
ImmutableList<T> list = ImmutableList.copyOf(iterable);
return list.isEmpty() ? null : list;
}
public static String asCommandLine(Iterable<String> arguments) {
logDeprecation(7);
return Joiner.on(" ").join(collect(arguments, Transformers.asSafeCommandLineArgument()));
}
}