IteratorUtil: Add generic method to return sorted list out of a collection

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Rohit Yadav 2013-01-23 13:47:56 -08:00
parent 8273af7cbf
commit cbdeeebc6c

View File

@ -16,8 +16,11 @@
// under the License.
package com.cloud.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
public class IteratorUtil {
public static <T> Iterable<T> enumerationAsIterable(final Enumeration<T> e) {
@ -51,4 +54,11 @@ public class IteratorUtil {
}
};
}
public static
<T extends Comparable<? super T>> List<T> asSortedList(Collection<T> c) {
List<T> list = new ArrayList<T>(c);
java.util.Collections.sort(list);
return list;
}
}