T
- The entry typepublic class WeightedTable<T> extends RandomObjectTable<T>
entries
Constructor and Description |
---|
WeightedTable()
Creates a new
WeightedTable with a default roll
count of 1 . |
WeightedTable(int rolls)
Creates a new
WeightedTable with the provided
number of rolls . |
WeightedTable(VariableAmount rolls)
Creates a new
WeightedTable with the provided
VariableAmount for the amount of rolls and variance. |
Modifier and Type | Method and Description |
---|---|
boolean |
add(TableEntry<T> entry) |
boolean |
add(T object,
double weight)
Adds the given object to the table with the given weight.
|
boolean |
addAll(Collection<? extends TableEntry<T>> c) |
void |
clear() |
boolean |
equals(Object o) |
List<T> |
get(Random rand)
Performs a number of rolls according to the number of rolls defined by
RandomObjectTable.getRolls() and returns items from the table for each roll. |
int |
hashCode() |
Iterator<TableEntry<T>> |
iterator() |
protected void |
recalculateWeight()
Recalculates the total weight of all entries in this table.
|
boolean |
remove(Object entry) |
boolean |
removeAll(Collection<?> c) |
boolean |
removeObject(Object entry)
Removes the first instance of an entry in this table which is a
WeightedObject entry and contains the given object. |
boolean |
retainAll(Collection<?> c) |
String |
toString() |
contains, containsAll, containsAllObjects, containsObject, getEntries, getRolls, isEmpty, setRolls, setRolls, size, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
parallelStream, removeIf, spliterator, stream
public WeightedTable()
WeightedTable
with a default roll
count of 1
.public WeightedTable(int rolls)
WeightedTable
with the provided
number of rolls
.rolls
- The rolls for variancepublic WeightedTable(VariableAmount rolls)
WeightedTable
with the provided
VariableAmount
for the amount of rolls and variance.rolls
- The rolls for variancepublic boolean add(TableEntry<T> entry)
add
in interface Collection<TableEntry<T>>
add
in class RandomObjectTable<T>
public boolean add(T object, double weight)
RandomObjectTable
add
in class RandomObjectTable<T>
object
- The new objectweight
- The weight of the objectpublic boolean addAll(Collection<? extends TableEntry<T>> c)
addAll
in interface Collection<TableEntry<T>>
addAll
in class RandomObjectTable<T>
public boolean remove(Object entry)
remove
in interface Collection<TableEntry<T>>
remove
in class RandomObjectTable<T>
public boolean removeObject(Object entry)
RandomObjectTable
WeightedObject
entry and contains the given object.removeObject
in class RandomObjectTable<T>
entry
- The object to removepublic boolean removeAll(Collection<?> c)
removeAll
in interface Collection<TableEntry<T>>
removeAll
in class RandomObjectTable<T>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<TableEntry<T>>
retainAll
in class RandomObjectTable<T>
public void clear()
clear
in interface Collection<TableEntry<T>>
clear
in class RandomObjectTable<T>
protected void recalculateWeight()
public List<T> get(Random rand)
RandomObjectTable
RandomObjectTable.getRolls()
and returns items from the table for each roll.get
in class RandomObjectTable<T>
rand
- The random object to usepublic Iterator<TableEntry<T>> iterator()
iterator
in interface Iterable<TableEntry<T>>
iterator
in interface Collection<TableEntry<T>>
iterator
in class RandomObjectTable<T>
public boolean equals(Object o)
equals
in interface Collection<TableEntry<T>>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<TableEntry<T>>
hashCode
in class Object