Class WeightedTable<T>
- java.lang.Object
-
- org.spongepowered.api.util.weighted.RandomObjectTable<T>
-
- org.spongepowered.api.util.weighted.WeightedTable<T>
-
- Type Parameters:
T- The entry type
- All Implemented Interfaces:
Iterable<TableEntry<T>>,Collection<TableEntry<T>>
- Direct Known Subclasses:
UnmodifiableWeightedTable
public class WeightedTable<T> extends RandomObjectTable<T>
A table of weighted entry, each entry is given a weight, the higher the weight the more likely the chance that the entry is chosen. Each roll will only return a single entries value.
-
-
Field Summary
-
Fields inherited from class org.spongepowered.api.util.weighted.RandomObjectTable
entries
-
-
Constructor Summary
Constructors Constructor Description WeightedTable()Creates a newWeightedTablewith a default roll count of1.WeightedTable(int rolls)Creates a newWeightedTablewith the provided number ofrolls.WeightedTable(VariableAmount rolls)Creates a newWeightedTablewith the providedVariableAmountfor the amount of rolls and variance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(TableEntry<T> entry)booleanadd(T object, double weight)Adds the given object to the table with the given weight.booleanaddAll(Collection<? extends TableEntry<T>> c)voidclear()booleanequals(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.inthashCode()Iterator<TableEntry<T>>iterator()protected voidrecalculateWeight()Recalculates the total weight of all entries in this table.booleanremove(Object entry)booleanremoveAll(Collection<?> c)booleanremoveObject(Object entry)Removes the first instance of an entry in this table which is aWeightedObjectentry and contains the given object.booleanretainAll(Collection<?> c)StringtoString()-
Methods inherited from class org.spongepowered.api.util.weighted.RandomObjectTable
contains, containsAll, containsAllObjects, containsObject, entries, isEmpty, 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
-
WeightedTable
public WeightedTable()
Creates a newWeightedTablewith a default roll count of1.
-
WeightedTable
public WeightedTable(int rolls)
Creates a newWeightedTablewith the provided number ofrolls.- Parameters:
rolls- The rolls for variance
-
WeightedTable
public WeightedTable(VariableAmount rolls)
Creates a newWeightedTablewith the providedVariableAmountfor the amount of rolls and variance.- Parameters:
rolls- The rolls for variance
-
-
Method Detail
-
add
public boolean add(TableEntry<T> entry)
- Specified by:
addin interfaceCollection<T>- Overrides:
addin classRandomObjectTable<T>
-
add
public boolean add(T object, double weight)
Description copied from class:RandomObjectTableAdds the given object to the table with the given weight.- Overrides:
addin classRandomObjectTable<T>- Parameters:
object- The new objectweight- The weight of the object- Returns:
- If the object was successfully added
-
addAll
public boolean addAll(Collection<? extends TableEntry<T>> c)
- Specified by:
addAllin interfaceCollection<T>- Overrides:
addAllin classRandomObjectTable<T>
-
remove
public boolean remove(Object entry)
- Specified by:
removein interfaceCollection<T>- Overrides:
removein classRandomObjectTable<T>
-
removeObject
public boolean removeObject(Object entry)
Description copied from class:RandomObjectTableRemoves the first instance of an entry in this table which is aWeightedObjectentry and contains the given object.- Overrides:
removeObjectin classRandomObjectTable<T>- Parameters:
entry- The object to remove- Returns:
- If the table was changed as a result
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<T>- Overrides:
removeAllin classRandomObjectTable<T>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<T>- Overrides:
retainAllin classRandomObjectTable<T>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<T>- Overrides:
clearin classRandomObjectTable<T>
-
recalculateWeight
protected void recalculateWeight()
Recalculates the total weight of all entries in this table.
-
get
public List<T> get(Random rand)
Description copied from class:RandomObjectTablePerforms a number of rolls according to the number of rolls defined byRandomObjectTable.rolls()and returns items from the table for each roll.- Specified by:
getin classRandomObjectTable<T>- Parameters:
rand- The random object to use- Returns:
- The returned items, may be empty but not null
-
iterator
public Iterator<TableEntry<T>> iterator()
- Specified by:
iteratorin interfaceCollection<T>- Specified by:
iteratorin interfaceIterable<T>- Overrides:
iteratorin classRandomObjectTable<T>
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceCollection<T>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<T>- Overrides:
hashCodein classObject
-
-