mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
made randomutil method generic
This commit is contained in:
parent
4b43ad09f0
commit
5e569b597a
1 changed files with 6 additions and 6 deletions
|
@ -1,9 +1,9 @@
|
|||
package mage.util;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by IGOUDT on 5-9-2016.
|
||||
|
@ -43,13 +43,13 @@ public final class RandomUtil {
|
|||
random.setSeed(newSeed);
|
||||
}
|
||||
|
||||
public static UUID randomFromSet(Set<UUID> uuids) {
|
||||
if (uuids.size() < 2) {
|
||||
return uuids.stream().findFirst().orElse(null);
|
||||
public static <T extends Serializable> T randomFromSet(Set<T> collection) {
|
||||
if (collection.size() < 2) {
|
||||
return collection.stream().findFirst().orElse(null);
|
||||
}
|
||||
int rand = nextInt(uuids.size());
|
||||
int rand = nextInt(collection.size());
|
||||
int count = 0;
|
||||
for (UUID currentId : uuids) {
|
||||
for (T currentId : collection) {
|
||||
if (count == rand) {
|
||||
return currentId;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue