IteratorUtil: Add generic method to return sorted list out of a collection Signed-off-by: Rohit Yadav <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/c47c6990 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/c47c6990 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/c47c6990 Branch: refs/heads/marvin-refactor Commit: c47c6990de97d44c6f79101e50183f219225ae5b Parents: d587e24 Author: Rohit Yadav <[email protected]> Authored: Wed Jan 23 13:47:56 2013 -0800 Committer: Prasanna Santhanam <[email protected]> Committed: Thu Jan 24 17:48:35 2013 +0530 ---------------------------------------------------------------------- utils/src/com/cloud/utils/IteratorUtil.java | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c47c6990/utils/src/com/cloud/utils/IteratorUtil.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/IteratorUtil.java b/utils/src/com/cloud/utils/IteratorUtil.java index d7a85f1..0a7fd72 100644 --- a/utils/src/com/cloud/utils/IteratorUtil.java +++ b/utils/src/com/cloud/utils/IteratorUtil.java @@ -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; + } }
