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
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
ConstructorDescriptionCreates a newWeightedTable
with a default roll count of1
.WeightedTable
(int rolls) Creates a newWeightedTable
with the provided number ofrolls
.WeightedTable
(VariableAmount rolls) Creates a newWeightedTable
with the providedVariableAmount
for the amount of rolls and variance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(TableEntry<T> entry) boolean
Adds the given object to the table with the given weight.boolean
addAll
(Collection<? extends TableEntry<T>> c) void
clear()
boolean
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()
iterator()
protected void
Recalculates the total weight of all entries in this table.boolean
boolean
removeAll
(Collection<?> c) boolean
removeObject
(Object entry) Removes the first instance of an entry in this table which is aWeightedObject
entry and contains the given object.boolean
retainAll
(Collection<?> c) toString()
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, toArray
-
Constructor Details
-
WeightedTable
public WeightedTable()Creates a newWeightedTable
with a default roll count of1
. -
WeightedTable
public WeightedTable(int rolls) Creates a newWeightedTable
with the provided number ofrolls
.- Parameters:
rolls
- The rolls for variance
-
WeightedTable
Creates a newWeightedTable
with the providedVariableAmount
for the amount of rolls and variance.- Parameters:
rolls
- The rolls for variance
-
-
Method Details
-
add
- Specified by:
add
in interfaceCollection<T>
- Overrides:
add
in classRandomObjectTable<T>
-
add
Description copied from class:RandomObjectTable
Adds the given object to the table with the given weight.- Overrides:
add
in classRandomObjectTable<T>
- Parameters:
object
- The new objectweight
- The weight of the object- Returns:
- If the object was successfully added
-
addAll
- Specified by:
addAll
in interfaceCollection<T>
- Overrides:
addAll
in classRandomObjectTable<T>
-
remove
- Specified by:
remove
in interfaceCollection<T>
- Overrides:
remove
in classRandomObjectTable<T>
-
removeObject
Description copied from class:RandomObjectTable
Removes the first instance of an entry in this table which is aWeightedObject
entry and contains the given object.- Overrides:
removeObject
in classRandomObjectTable<T>
- Parameters:
entry
- The object to remove- Returns:
- If the table was changed as a result
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
- Overrides:
removeAll
in classRandomObjectTable<T>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
- Overrides:
retainAll
in classRandomObjectTable<T>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<T>
- Overrides:
clear
in classRandomObjectTable<T>
-
recalculateWeight
protected void recalculateWeight()Recalculates the total weight of all entries in this table. -
get
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
-
iterator
- Specified by:
iterator
in interfaceCollection<T>
- Specified by:
iterator
in interfaceIterable<T>
- Overrides:
iterator
in classRandomObjectTable<T>
-
equals
- Specified by:
equals
in interfaceCollection<T>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<T>
- Overrides:
hashCode
in classObject
-
toString
-