Class UnmodifiableWeightedTable<T>
- java.lang.Object
-
- org.spongepowered.api.util.weighted.RandomObjectTable<T>
-
- org.spongepowered.api.util.weighted.WeightedTable<T>
-
- org.spongepowered.api.util.weighted.UnmodifiableWeightedTable<T>
-
- Type Parameters:
T- Item type
- All Implemented Interfaces:
Iterable<TableEntry<T>>,Collection<TableEntry<T>>
public class UnmodifiableWeightedTable<T> extends WeightedTable<T>
Creates a WeightedTable that is completely immutable, but still is able to be changed via its proxy table.
-
-
Field Summary
-
Fields inherited from class org.spongepowered.api.util.weighted.RandomObjectTable
entries
-
-
Constructor Summary
Constructors Constructor Description UnmodifiableWeightedTable(WeightedTable<T> table)Creates a newUnmodifiableWeightedTablewith the providedWeightedTable.UnmodifiableWeightedTable(WeightedTable<T> table, int rolls)UnmodifiableWeightedTable(WeightedTable<T> table, VariableAmount rolls)
-
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()booleancontains(Object o)booleancontainsAll(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.booleanequals(Object o)voidforEach(Consumer<? super TableEntry<T>> action)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()booleanisEmpty()Iterator<TableEntry<T>>iterator()Stream<TableEntry<T>>parallelStream()booleanremove(Object entry)booleanremoveAll(Collection<?> c)booleanremoveIf(Predicate<? super TableEntry<T>> filter)booleanremoveObject(Object entry)Removes the first instance of an entry in this table which is aWeightedObjectentry and contains the given object.booleanretainAll(Collection<?> c)VariableAmountrolls()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()Spliterator<TableEntry<T>>spliterator()Stream<TableEntry<T>>stream()Object[]toArray()<R> R[]toArray(R[] a)StringtoString()-
Methods inherited from class org.spongepowered.api.util.weighted.WeightedTable
recalculateWeight
-
-
-
-
Constructor Detail
-
UnmodifiableWeightedTable
public UnmodifiableWeightedTable(WeightedTable<T> table)
Creates a newUnmodifiableWeightedTablewith the providedWeightedTable.- Parameters:
table- The table to provide
-
UnmodifiableWeightedTable
public UnmodifiableWeightedTable(WeightedTable<T> table, int rolls)
- Parameters:
table- The tablerolls- The rolls
-
UnmodifiableWeightedTable
public UnmodifiableWeightedTable(WeightedTable<T> table, VariableAmount rolls)
- Parameters:
table- The tablerolls- The rolls
-
-
Method Detail
-
add
public boolean add(TableEntry<T> entry)
- Specified by:
addin interfaceCollection<T>- Overrides:
addin classWeightedTable<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 classWeightedTable<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 classWeightedTable<T>
-
setRolls
public void setRolls(VariableAmount rolls)
Description copied from class:RandomObjectTableSets the number of times this table will roll while retrieving items.- Overrides:
setRollsin classRandomObjectTable<T>- Parameters:
rolls- The new roll count
-
setRolls
public void setRolls(int rolls)
Description copied from class:RandomObjectTableSets the number of times this table will roll while retrieving items.- Overrides:
setRollsin classRandomObjectTable<T>- Parameters:
rolls- The new roll count
-
remove
public boolean remove(Object entry)
- Specified by:
removein interfaceCollection<T>- Overrides:
removein classWeightedTable<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 classWeightedTable<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 classWeightedTable<T>
-
removeIf
public boolean removeIf(Predicate<? super TableEntry<T>> filter)
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<T>- Overrides:
retainAllin classWeightedTable<T>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<T>- Overrides:
clearin classWeightedTable<T>
-
iterator
public Iterator<TableEntry<T>> iterator()
- Specified by:
iteratorin interfaceCollection<T>- Specified by:
iteratorin interfaceIterable<T>- Overrides:
iteratorin classWeightedTable<T>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<T>- Overrides:
containsin classRandomObjectTable<T>
-
rolls
public VariableAmount rolls()
Description copied from class:RandomObjectTableGets the number of times this table will roll while retrieving items. For each roll a complete pass through of the table will occur.- Overrides:
rollsin classRandomObjectTable<T>- Returns:
- The number of rolls
-
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.- Overrides:
getin classWeightedTable<T>- Parameters:
rand- The random object to use- Returns:
- The returned items, may be empty but not null
-
containsObject
public boolean containsObject(Object obj)
Description copied from class:RandomObjectTableGets if this table contains the given object, the object may either be aTableEntryor the object contained within.- Overrides:
containsObjectin classRandomObjectTable<T>- Parameters:
obj- The object to check for- Returns:
- If the object is contained within the table
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<T>- Overrides:
containsAllin classRandomObjectTable<T>
-
containsAllObjects
public boolean containsAllObjects(Collection<?> c)
Description copied from class:RandomObjectTableGets if this table contains all of the given objects, the objects may either beTableEntrys or the objects contained within the entries.- Overrides:
containsAllObjectsin classRandomObjectTable<T>- Parameters:
c- The objects to check for- Returns:
- If all of the objects are contained within the table
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<T>- Overrides:
isEmptyin classRandomObjectTable<T>
-
size
public int size()
- Specified by:
sizein interfaceCollection<T>- Overrides:
sizein classRandomObjectTable<T>
-
entries
public List<TableEntry<T>> entries()
Description copied from class:RandomObjectTableGets 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).- Overrides:
entriesin classRandomObjectTable<T>- Returns:
- The raw entries
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<T>- Overrides:
toArrayin classRandomObjectTable<T>
-
toArray
public <R> R[] toArray(R[] a)
- Specified by:
toArrayin interfaceCollection<T>- Overrides:
toArrayin classRandomObjectTable<T>
-
spliterator
public Spliterator<TableEntry<T>> spliterator()
-
stream
public Stream<TableEntry<T>> stream()
-
parallelStream
public Stream<TableEntry<T>> parallelStream()
-
forEach
public void forEach(Consumer<? super TableEntry<T>> action)
-
toString
public String toString()
- Overrides:
toStringin classWeightedTable<T>
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<T>- Overrides:
hashCodein classWeightedTable<T>
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceCollection<T>- Overrides:
equalsin classWeightedTable<T>
-
-