From 6e4739870abbaee45f3072e658593cdd3efb9c15 Mon Sep 17 00:00:00 2001 From: "ray.j.greenwell" Date: Mon, 29 Nov 2010 20:35:46 +0000 Subject: [PATCH] You put T in, you get T out. I'm open to suggestions as to whether this is the right thing. I think if it were returning a view, we'd definitely want it like this. You don't want a List to look like a List and have it break something when someone stuffs a Float in it. But the argument could be made that returning a new List can surely be seen as a List because it is not referenced anywhere else as something more specific. Many of the guava methods allow a "re-typing" like this, although I think they have admitted that it was a mistake and newly added methods don't allow it. In any case, I think that it's most proper to retain things as specifically as possible. Why would you turn a List into a List? Why would you want to throw away the information? If you need to pass it to a method that expects List then that method should be modified to correctly accept List. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2958 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/main/java/com/samskivert/util/CollectionUtil.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/samskivert/util/CollectionUtil.java b/src/main/java/com/samskivert/util/CollectionUtil.java index 20b9f3a0..32b546f2 100644 --- a/src/main/java/com/samskivert/util/CollectionUtil.java +++ b/src/main/java/com/samskivert/util/CollectionUtil.java @@ -135,7 +135,7 @@ public class CollectionUtil * * @throws NoSuchElementException if the Iterable is empty. */ - public static > List maxList (Iterable iterable) + public static > List maxList (Iterable iterable) { return maxList(iterable, new Comparator() { public int compare (T o1, T o2) { @@ -150,9 +150,9 @@ public class CollectionUtil * * @throws NoSuchElementException if the Iterable is empty. */ - public static List maxList (Iterable iterable, Comparator comp) + public static List maxList (Iterable iterable, Comparator comp) { - Iterator itr = iterable.iterator(); + Iterator itr = iterable.iterator(); T max = itr.next(); List maxes = new ArrayList(); maxes.add(max); @@ -186,7 +186,7 @@ public class CollectionUtil * * @throws NoSuchElementException if the Iterable is empty. */ - public static > List minList (Iterable iterable) + public static > List minList (Iterable iterable) { return maxList(iterable, java.util.Collections.reverseOrder()); } @@ -197,7 +197,7 @@ public class CollectionUtil * * @throws NoSuchElementException if the Iterable is empty. */ - public static List minList (Iterable iterable, Comparator comp) + public static List minList (Iterable iterable, Comparator comp) { return maxList(iterable, java.util.Collections.reverseOrder(comp)); }