Skip to content

Commit 7806bc9

Browse files
committed
Add object version of the method sort().
1 parent 1a0c3f3 commit 7806bc9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/java/com/github/underscore/$.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,8 +1718,8 @@ public static <E> List<E> union(final List<E> ... lists) {
17181718
return newArrayList(union);
17191719
}
17201720

1721-
public static <T extends Comparable<T>> List<T> sort(final List<T> list) {
1722-
final List<T> localList = newArrayList(list);
1721+
public static <T extends Comparable<T>> List<T> sort(final Iterable<T> iterable) {
1722+
final List<T> localList = newArrayList(iterable);
17231723
Collections.<T>sort(localList);
17241724
return localList;
17251725
}
@@ -1730,6 +1730,10 @@ public static <T extends Comparable<T>> T[] sort(final T[] array) {
17301730
return localArray;
17311731
}
17321732

1733+
public List<T> sort() {
1734+
return sort((Iterable<Comparable>) iterable);
1735+
}
1736+
17331737
public static <T> String join(final Iterable<T> iterable, final String separator) {
17341738
final StringBuilder sb = new StringBuilder();
17351739
each(iterable, new Block<T>() {

src/test/java/com/github/underscore/UnderscoreTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void main() {
5151
@Test
5252
public void sort() {
5353
assertEquals("[example, some, words]", $.sort(asList("some", "words", "example")).toString());
54+
assertEquals("[example, some, words]", new $(asList("some", "words", "example")).sort().toString());
5455
assertEquals("[example, some, words]", $.chain(asList("some", "words", "example")).sort().value().toString());
5556
assertEquals("[4, 5, 7]", $.chain(asList("some", "words", "example"))
5657
.map(new Function1<String, Integer>() {

0 commit comments

Comments
 (0)