Class ChanceTable<T>
- java.lang.Object
-
- org.spongepowered.api.util.weighted.RandomObjectTable<T>
-
- org.spongepowered.api.util.weighted.ChanceTable<T>
-
- Type Parameters:
T
- The entry type
- All Implemented Interfaces:
Iterable<TableEntry<T>>
,Collection<TableEntry<T>>
public class ChanceTable<T> extends RandomObjectTable<T>
This is a variant of theRandomObjectTable
which uses a 0-1 chance attached to every entry. When rolled the a chance roll is calculated for each entry and all entries which pass are returned.
-
-
Field Summary
-
Fields inherited from class org.spongepowered.api.util.weighted.RandomObjectTable
entries
-
-
Constructor Summary
Constructors Constructor Description ChanceTable()
Creates a newChanceTable
with a default roll count of 1.ChanceTable(int rolls)
Creates a newChanceTable
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
List<T>
get(Random rand)
Performs a number of rolls according to the number of rolls defined byRandomObjectTable.rolls()
and returns items from the table for each roll.int
hashCode()
String
toString()
-
Methods inherited from class org.spongepowered.api.util.weighted.RandomObjectTable
add, add, addAll, clear, contains, containsAll, containsAllObjects, containsObject, entries, isEmpty, iterator, remove, removeAll, removeObject, retainAll, rolls, setRolls, setRolls, size, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream
-
-
-
-
Constructor Detail
-
ChanceTable
public ChanceTable()
Creates a newChanceTable
with a default roll count of 1.
-
ChanceTable
public ChanceTable(int rolls)
Creates a newChanceTable
.- Parameters:
rolls
- The number of rolls to perform
-
-
Method Detail
-
get
public List<T> get(Random rand)
Description copied from class:RandomObjectTable
Performs a number of rolls according to the number of rolls defined byRandomObjectTable.rolls()
and returns items from the table for each roll.- Specified by:
get
in classRandomObjectTable<T>
- Parameters:
rand
- The random object to use- Returns:
- The returned items, may be empty but not null
-
equals
public boolean equals(Object o)
- Specified by:
equals
in interfaceCollection<T>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<T>
- Overrides:
hashCode
in classObject
-
-