mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce sorted(Comparator)
This commit is contained in:
@@ -478,6 +478,12 @@ public class TreeTraverserTest extends TestCase {
|
||||
assertEquals(Arrays.asList(1, 2, 3, 4, 5), uniqueMod5.toList()); // same results again
|
||||
}
|
||||
|
||||
public void testSorted() {
|
||||
JBIterable<Integer> it1 = JBIterable.generate(1, INCREMENT).take(30);
|
||||
JBIterable<Integer> it2 = JBIterable.generate(30, o -> o - 1).take(30).sorted(Integer::compareTo);
|
||||
assertEquals(it1.toList(), it2.unique().toList());
|
||||
}
|
||||
|
||||
// TreeTraversal ----------------------------------------------
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -844,15 +844,26 @@ public abstract class JBIterable<E> implements Iterable<E> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all items into an {@link ArrayList} and returns them as the new {@code JBIterable}.
|
||||
* Collects all items into an {@link ArrayList} and returns it wrapped in a new {@code JBIterable}.
|
||||
* @see JBIterable#collect(Collection)
|
||||
*/
|
||||
@NotNull
|
||||
public final JBIterable<E> collect() {
|
||||
if (content instanceof ArrayList) return this;
|
||||
if (content instanceof Collection) return this;
|
||||
return collect(ContainerUtilRt.<E>newArrayList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all items into an {@link ArrayList}, sorts it and returns it wrapped in a new {@code JBIterable}.
|
||||
* @see JBIterable#collect(Collection)
|
||||
*/
|
||||
@NotNull
|
||||
public final JBIterable<E> sorted(@NotNull Comparator<E> comparator) {
|
||||
ArrayList<E> list = addAllTo(ContainerUtilRt.<E>newArrayList());
|
||||
Collections.sort(list, comparator);
|
||||
return from(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code List} containing all the elements from this iterable in
|
||||
* proper sequence.
|
||||
|
||||
Reference in New Issue
Block a user