Actually, it was stupid of me to handle a non-RandomAccess list differently,
as they still implement get() and however they do that internally is bound to be more efficient than doing the same thing through an Iterator. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3367 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -24,7 +24,6 @@ package com.threerings.util;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.RandomAccess;
|
|
||||||
|
|
||||||
import com.samskivert.util.IntListUtil;
|
import com.samskivert.util.IntListUtil;
|
||||||
|
|
||||||
@@ -152,10 +151,6 @@ public class RandomUtil
|
|||||||
public static Object pickRandom (List values)
|
public static Object pickRandom (List values)
|
||||||
{
|
{
|
||||||
int size = values.size();
|
int size = values.size();
|
||||||
if (!(values instanceof RandomAccess)) {
|
|
||||||
return pickRandom(values.iterator(), size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Must have at least one element [size=" + size + "]");
|
"Must have at least one element [size=" + size + "]");
|
||||||
@@ -173,10 +168,6 @@ public class RandomUtil
|
|||||||
public static Object pickRandom (List values, Object skip)
|
public static Object pickRandom (List values, Object skip)
|
||||||
{
|
{
|
||||||
int size = values.size();
|
int size = values.size();
|
||||||
if (!(values instanceof RandomAccess)) {
|
|
||||||
return pickRandom(values.iterator(), size, skip);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size < 2) {
|
if (size < 2) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Must have at least one element [size=" + size + "]");
|
"Must have at least one element [size=" + size + "]");
|
||||||
|
|||||||
Reference in New Issue
Block a user