From 068aac8e27237a59e40ac536167eef152a689f16 Mon Sep 17 00:00:00 2001 From: "ray.j.greenwell" Date: Mon, 4 Oct 2010 17:13:31 +0000 Subject: [PATCH] A more localized application of @SuppressWarnings is desireable. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2911 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/main/java/com/samskivert/util/Randoms.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/samskivert/util/Randoms.java b/src/main/java/com/samskivert/util/Randoms.java index 2ebb7dd1..463427d2 100644 --- a/src/main/java/com/samskivert/util/Randoms.java +++ b/src/main/java/com/samskivert/util/Randoms.java @@ -223,11 +223,11 @@ public class Randoms /** * Shared code for pick and pluck. */ - @SuppressWarnings("unchecked") protected T pickPluck (Iterable iterable, T ifEmpty, boolean remove) { if (iterable instanceof Collection) { // optimized path for Collection + @SuppressWarnings("unchecked") Collection coll = (Collection)iterable; int size = coll.size(); if (size == 0) { @@ -235,9 +235,13 @@ public class Randoms } if (coll instanceof List) { // extra-special optimized path for Lists + @SuppressWarnings("unchecked") List list = (List)coll; int idx = _r.nextInt(size); - return (T) (remove ? list.remove(idx) : list.get(idx)); + if (remove) { // ternary conditional causes warning here with javac 1.6, :( + return list.remove(idx); + } + return list.get(idx); } // for other Collections, we must iterate Iterator it = coll.iterator(); @@ -269,12 +273,13 @@ public class Randoms T next = it.next(); if (0 == _r.nextInt(count)) { pick = next; + // catch up lagIt so that it has just returned 'pick' as well for ( ; lag > 0; lag--) { lagIt.next(); } } } - lagIt.remove(); + lagIt.remove(); // remove 'pick' from the lagging iterator return pick; }