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 SummaryFields inherited from class org.spongepowered.api.util.weighted.RandomObjectTableentries
- 
Constructor SummaryConstructorsConstructorDescriptionCreates 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 SummaryModifier and TypeMethodDescriptionbooleanadd(TableEntry<T> entry) booleanAdds the given object to the table with the given weight.booleanaddAll(Collection<? extends TableEntry<T>> c) voidclear()booleanPerforms a number of rolls according to the number of rolls defined byRandomObjectTable.rolls()and returns items from the table for each roll.inthashCode()iterator()protected voidRecalculates the total weight of all entries in this table.booleanbooleanremoveAll(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) toString()Methods inherited from class org.spongepowered.api.util.weighted.RandomObjectTablecontains, containsAll, containsAllObjects, containsObject, entries, isEmpty, rolls, setRolls, setRolls, size, toArray, toArrayMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, removeIf, spliterator, stream, toArray
- 
Constructor Details- 
WeightedTablepublic WeightedTable()Creates a newWeightedTablewith a default roll count of1.
- 
WeightedTablepublic WeightedTable(int rolls) Creates a newWeightedTablewith the provided number ofrolls.- Parameters:
- rolls- The rolls for variance
 
- 
WeightedTableCreates a newWeightedTablewith the providedVariableAmountfor the amount of rolls and variance.- Parameters:
- rolls- The rolls for variance
 
 
- 
- 
Method Details- 
add- Specified by:
- addin interface- Collection<T>
- Overrides:
- addin class- RandomObjectTable<T>
 
- 
addDescription copied from class:RandomObjectTableAdds the given object to the table with the given weight.- Overrides:
- addin class- RandomObjectTable<T>
- Parameters:
- object- The new object
- weight- The weight of the object
- Returns:
- If the object was successfully added
 
- 
addAll- Specified by:
- addAllin interface- Collection<T>
- Overrides:
- addAllin class- RandomObjectTable<T>
 
- 
remove- Specified by:
- removein interface- Collection<T>
- Overrides:
- removein class- RandomObjectTable<T>
 
- 
removeObjectDescription copied from class:RandomObjectTableRemoves the first instance of an entry in this table which is aWeightedObjectentry and contains the given object.- Overrides:
- removeObjectin class- RandomObjectTable<T>
- Parameters:
- entry- The object to remove
- Returns:
- If the table was changed as a result
 
- 
removeAll- Specified by:
- removeAllin interface- Collection<T>
- Overrides:
- removeAllin class- RandomObjectTable<T>
 
- 
retainAll- Specified by:
- retainAllin interface- Collection<T>
- Overrides:
- retainAllin class- RandomObjectTable<T>
 
- 
clearpublic void clear()- Specified by:
- clearin interface- Collection<T>
- Overrides:
- clearin class- RandomObjectTable<T>
 
- 
recalculateWeightprotected void recalculateWeight()Recalculates the total weight of all entries in this table.
- 
getDescription 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 class- RandomObjectTable<T>
- Parameters:
- rand- The random object to use
- Returns:
- The returned items, may be empty but not null
 
- 
iterator- Specified by:
- iteratorin interface- Collection<T>
- Specified by:
- iteratorin interface- Iterable<T>
- Overrides:
- iteratorin class- RandomObjectTable<T>
 
- 
equals- Specified by:
- equalsin interface- Collection<T>
- Overrides:
- equalsin class- Object
 
- 
hashCodepublic int hashCode()- Specified by:
- hashCodein interface- Collection<T>
- Overrides:
- hashCodein class- Object
 
- 
toString
 
-