Skip to content

Commit cbdeeeb

Browse files
committed
IteratorUtil: Add generic method to return sorted list out of a collection
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
1 parent 8273af7 commit cbdeeeb

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

utils/src/com/cloud/utils/IteratorUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
// under the License.
1717
package com.cloud.utils;
1818

19+
import java.util.ArrayList;
20+
import java.util.Collection;
1921
import java.util.Enumeration;
2022
import java.util.Iterator;
23+
import java.util.List;
2124

2225
public class IteratorUtil {
2326
public static <T> Iterable<T> enumerationAsIterable(final Enumeration<T> e) {
@@ -51,4 +54,11 @@ public T nextElement() {
5154
}
5255
};
5356
}
57+
58+
public static
59+
<T extends Comparable<? super T>> List<T> asSortedList(Collection<T> c) {
60+
List<T> list = new ArrayList<T>(c);
61+
java.util.Collections.sort(list);
62+
return list;
63+
}
5464
}

0 commit comments

Comments
 (0)