Addition of generic getRandomEntry method.

This commit is contained in:
MobiusDevelopment
2019-10-29 13:52:24 +00:00
parent 60b7afe5e3
commit dde3a7274f
542 changed files with 1650 additions and 1309 deletions

View File

@@ -2052,4 +2052,45 @@ public class Quest extends ManagedScript
deleteQuestToOfflineMembers(player.getClanId());
}
}
/**
* Get a random entry.<br>
* @param <T>
* @param array of values.
* @return one value from array.
*/
@SuppressWarnings("unchecked")
public static <T> T getRandomEntry(T... array)
{
if (array.length == 0)
{
return null;
}
return array[Rnd.get(array.length)];
}
/**
* Get a random entry.<br>
* @param <T>
* @param list of values.
* @return one value from list.
*/
public static <T> T getRandomEntry(List<T> list)
{
if (list.isEmpty())
{
return null;
}
return list.get(Rnd.get(list.size()));
}
/**
* Get a random entry.<br>
* @param array of Integers.
* @return one Integer from array.
*/
public static int getRandomEntry(int... array)
{
return array[Rnd.get(array.length)];
}
}