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 newUnmodifiableWeightedTable
with 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 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
contains(Object o)
boolean
containsAll(Collection<?> c)
boolean
containsAllObjects(Collection<?> c)
Gets if this table contains all of the given objects, the objects may either beTableEntry
s or the objects contained within the entries.boolean
containsObject(Object obj)
Gets if this table contains the given object, the object may either be aTableEntry
or the object contained within.List<TableEntry<T>>
entries()
Gets the entries in the table.boolean
equals(Object o)
void
forEach(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.int
hashCode()
boolean
isEmpty()
Iterator<TableEntry<T>>
iterator()
Stream<TableEntry<T>>
parallelStream()
boolean
remove(Object entry)
boolean
removeAll(Collection<?> c)
boolean
removeIf(Predicate<? super TableEntry<T>> filter)
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)
VariableAmount
rolls()
Gets the number of times this table will roll while retrieving items.void
setRolls(int rolls)
Sets the number of times this table will roll while retrieving items.void
setRolls(VariableAmount rolls)
Sets the number of times this table will roll while retrieving items.int
size()
Spliterator<TableEntry<T>>
spliterator()
Stream<TableEntry<T>>
stream()
Object[]
toArray()
<R> R[]
toArray(R[] a)
String
toString()
-
Methods inherited from class org.spongepowered.api.util.weighted.WeightedTable
recalculateWeight
-
-
-
-
Constructor Detail
-
UnmodifiableWeightedTable
public UnmodifiableWeightedTable(WeightedTable<T> table)
Creates a newUnmodifiableWeightedTable
with 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:
add
in interfaceCollection<T>
- Overrides:
add
in classWeightedTable<T>
-
add
public boolean add(T object, double weight)
Description copied from class:RandomObjectTable
Adds the given object to the table with the given weight.- Overrides:
add
in 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:
addAll
in interfaceCollection<T>
- Overrides:
addAll
in classWeightedTable<T>
-
setRolls
public void setRolls(VariableAmount rolls)
Description copied from class:RandomObjectTable
Sets the number of times this table will roll while retrieving items.- Overrides:
setRolls
in classRandomObjectTable<T>
- Parameters:
rolls
- The new roll count
-
setRolls
public void setRolls(int rolls)
Description copied from class:RandomObjectTable
Sets the number of times this table will roll while retrieving items.- Overrides:
setRolls
in classRandomObjectTable<T>
- Parameters:
rolls
- The new roll count
-
remove
public boolean remove(Object entry)
- Specified by:
remove
in interfaceCollection<T>
- Overrides:
remove
in classWeightedTable<T>
-
removeObject
public boolean removeObject(Object entry)
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 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:
removeAll
in interfaceCollection<T>
- Overrides:
removeAll
in classWeightedTable<T>
-
removeIf
public boolean removeIf(Predicate<? super TableEntry<T>> filter)
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<T>
- Overrides:
retainAll
in classWeightedTable<T>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<T>
- Overrides:
clear
in classWeightedTable<T>
-
iterator
public Iterator<TableEntry<T>> iterator()
- Specified by:
iterator
in interfaceCollection<T>
- Specified by:
iterator
in interfaceIterable<T>
- Overrides:
iterator
in classWeightedTable<T>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<T>
- Overrides:
contains
in classRandomObjectTable<T>
-
rolls
public VariableAmount rolls()
Description copied from class:RandomObjectTable
Gets the number of times this table will roll while retrieving items. For each roll a complete pass through of the table will occur.- Overrides:
rolls
in classRandomObjectTable<T>
- Returns:
- The number of rolls
-
get
public List<T> get(Random rand)
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.- Overrides:
get
in 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:RandomObjectTable
Gets if this table contains the given object, the object may either be aTableEntry
or the object contained within.- Overrides:
containsObject
in 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:
containsAll
in interfaceCollection<T>
- Overrides:
containsAll
in classRandomObjectTable<T>
-
containsAllObjects
public boolean containsAllObjects(Collection<?> c)
Description copied from class:RandomObjectTable
Gets if this table contains all of the given objects, the objects may either beTableEntry
s or the objects contained within the entries.- Overrides:
containsAllObjects
in 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:
isEmpty
in interfaceCollection<T>
- Overrides:
isEmpty
in classRandomObjectTable<T>
-
size
public int size()
- Specified by:
size
in interfaceCollection<T>
- Overrides:
size
in classRandomObjectTable<T>
-
entries
public List<TableEntry<T>> entries()
Description copied from class:RandomObjectTable
Gets 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:
entries
in classRandomObjectTable<T>
- Returns:
- The raw entries
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<T>
- Overrides:
toArray
in classRandomObjectTable<T>
-
toArray
public <R> R[] toArray(R[] a)
- Specified by:
toArray
in interfaceCollection<T>
- Overrides:
toArray
in 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:
toString
in classWeightedTable<T>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<T>
- Overrides:
hashCode
in classWeightedTable<T>
-
equals
public boolean equals(Object o)
- Specified by:
equals
in interfaceCollection<T>
- Overrides:
equals
in classWeightedTable<T>
-
-