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:
java.lang.Iterable<TableEntry<T>>
,java.util.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(java.util.Collection<? extends TableEntry<T>> c)
void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
boolean
containsAllObjects(java.util.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(java.lang.Object obj)
Gets if this table contains the given object, the object may either be aTableEntry
or the object contained within.java.util.List<TableEntry<T>>
entries()
Gets the entries in the table.boolean
equals(java.lang.Object o)
void
forEach(java.util.function.Consumer<? super TableEntry<T>> action)
java.util.List<T>
get(java.util.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()
java.util.Iterator<TableEntry<T>>
iterator()
java.util.stream.Stream<TableEntry<T>>
parallelStream()
boolean
remove(java.lang.Object entry)
boolean
removeAll(java.util.Collection<?> c)
boolean
removeIf(java.util.function.Predicate<? super TableEntry<T>> filter)
boolean
removeObject(java.lang.Object entry)
Removes the first instance of an entry in this table which is aWeightedObject
entry and contains the given object.boolean
retainAll(java.util.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()
java.util.Spliterator<TableEntry<T>>
spliterator()
java.util.stream.Stream<TableEntry<T>>
stream()
java.lang.Object[]
toArray()
<R> R[]
toArray(R[] a)
java.lang.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 interfacejava.util.Collection<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(java.util.Collection<? extends TableEntry<T>> c)
- Specified by:
addAll
in interfacejava.util.Collection<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(java.lang.Object entry)
- Specified by:
remove
in interfacejava.util.Collection<T>
- Overrides:
remove
in classWeightedTable<T>
-
removeObject
public boolean removeObject(java.lang.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(java.util.Collection<?> c)
- Specified by:
removeAll
in interfacejava.util.Collection<T>
- Overrides:
removeAll
in classWeightedTable<T>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super TableEntry<T>> filter)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAll
in interfacejava.util.Collection<T>
- Overrides:
retainAll
in classWeightedTable<T>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<T>
- Overrides:
clear
in classWeightedTable<T>
-
iterator
public java.util.Iterator<TableEntry<T>> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<T>
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
- Overrides:
iterator
in classWeightedTable<T>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<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 java.util.List<T> get(java.util.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(java.lang.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(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<T>
- Overrides:
containsAll
in classRandomObjectTable<T>
-
containsAllObjects
public boolean containsAllObjects(java.util.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 interfacejava.util.Collection<T>
- Overrides:
isEmpty
in classRandomObjectTable<T>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<T>
- Overrides:
size
in classRandomObjectTable<T>
-
entries
public java.util.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 java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection<T>
- Overrides:
toArray
in classRandomObjectTable<T>
-
toArray
public <R> R[] toArray(R[] a)
- Specified by:
toArray
in interfacejava.util.Collection<T>
- Overrides:
toArray
in classRandomObjectTable<T>
-
spliterator
public java.util.Spliterator<TableEntry<T>> spliterator()
-
stream
public java.util.stream.Stream<TableEntry<T>> stream()
-
parallelStream
public java.util.stream.Stream<TableEntry<T>> parallelStream()
-
forEach
public void forEach(java.util.function.Consumer<? super TableEntry<T>> action)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classWeightedTable<T>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<T>
- Overrides:
hashCode
in classWeightedTable<T>
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Collection<T>
- Overrides:
equals
in classWeightedTable<T>
-
-