Class RandomObjectTable<T>
java.lang.Object
org.spongepowered.api.util.weighted.RandomObjectTable<T>
- Type Parameters:
- T- The type of entry
- All Implemented Interfaces:
- Iterable<TableEntry<T>>,- Collection<TableEntry<T>>
- Direct Known Subclasses:
- ChanceTable,- WeightedTable
An abstract table holding weighted objects. Objects may be retrieved from the
 table according to weight or chance.
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedRandomObjectTable(int rolls) Creates a newRandomObjectTablewith the provided number of rolls.protectedRandomObjectTable(VariableAmount rolls) Creates a newRandomObjectTablewith the provided number of rolls.
- 
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()booleanbooleancontainsAll(Collection<?> c) booleancontainsAllObjects(Collection<?> c) Gets if this table contains all of the given objects, the objects may either beTableEntrys or the objects contained within the entries.booleancontainsObject(Object obj) Gets if this table contains the given object, the object may either be aTableEntryor the object contained within.List<TableEntry<T>>entries()Gets the entries in the table.Performs a number of rolls according to the number of rolls defined byrolls()and returns items from the table for each roll.booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> c) booleanremoveObject(Object object) Removes the first instance of an entry in this table which is aWeightedObjectentry and contains the given object.booleanretainAll(Collection<?> c) rolls()Gets the number of times this table will roll while retrieving items.voidsetRolls(int rolls) Sets the number of times this table will roll while retrieving items.voidsetRolls(VariableAmount rolls) Sets the number of times this table will roll while retrieving items.intsize()Object[]toArray()<R> R[]toArray(R[] a) Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collectionequals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
- 
Field Details- 
entries
 
- 
- 
Constructor Details- 
RandomObjectTableprotected RandomObjectTable(int rolls) Creates a newRandomObjectTablewith the provided number of rolls.- Parameters:
- rolls- the rolls
- See Also:
 
- 
RandomObjectTableCreates a newRandomObjectTablewith the provided number of rolls.- Parameters:
- rolls- the rolls
- See Also:
 
 
- 
- 
Method Details- 
rollsGets the number of times this table will roll while retrieving items. For each roll a complete pass through of the table will occur.- Returns:
- The number of rolls
 
- 
setRollsSets the number of times this table will roll while retrieving items.- Parameters:
- rolls- The new roll count
 
- 
setRollspublic void setRolls(int rolls) Sets the number of times this table will roll while retrieving items.- Parameters:
- rolls- The new roll count
 
- 
add- Specified by:
- addin interface- Collection<T>
 
- 
addAdds the given object to the table with the given weight.- 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>
 
- 
contains- Specified by:
- containsin interface- Collection<T>
 
- 
containsObjectGets if this table contains the given object, the object may either be aTableEntryor the object contained within.- Parameters:
- obj- The object to check for
- Returns:
- If the object is contained within the table
 
- 
containsAll- Specified by:
- containsAllin interface- Collection<T>
 
- 
containsAllObjectsGets if this table contains all of the given objects, the objects may either beTableEntrys or the objects contained within the entries.- Parameters:
- c- The objects to check for
- Returns:
- If all of the objects are contained within the table
 
- 
isEmptypublic boolean isEmpty()- Specified by:
- isEmptyin interface- Collection<T>
 
- 
remove- Specified by:
- removein interface- Collection<T>
 
- 
removeObjectRemoves the first instance of an entry in this table which is aWeightedObjectentry and contains the given object.- Parameters:
- object- The object to remove
- Returns:
- If the table was changed as a result
 
- 
removeAll- Specified by:
- removeAllin interface- Collection<T>
 
- 
retainAll- Specified by:
- retainAllin interface- Collection<T>
 
- 
clearpublic void clear()- Specified by:
- clearin interface- Collection<T>
 
- 
sizepublic int size()- Specified by:
- sizein interface- Collection<T>
 
- 
getPerforms a number of rolls according to the number of rolls defined byrolls()and returns items from the table for each roll.- Parameters:
- rand- The random object to use
- Returns:
- The returned items, may be empty but not null
 
- 
entriesGets the entries in the table. Note that the specific sub class of this abstract table will determine the context that the entry weights should be interpreted in (either weights or chances).- Returns:
- The raw entries
 
- 
iterator
- 
toArray- Specified by:
- toArrayin interface- Collection<T>
 
- 
toArraypublic <R> R[] toArray(R[] a) - Specified by:
- toArrayin interface- Collection<T>
 
 
-