Package org.spongepowered.api.data.value
Interface WeightedCollectionValue<E>
-
- All Superinterfaces:
CollectionValue<TableEntry<E>,WeightedTable<E>>
,Iterable<TableEntry<E>>
,Value<WeightedTable<E>>
- All Known Subinterfaces:
WeightedCollectionValue.Immutable<E>
,WeightedCollectionValue.Mutable<E>
public interface WeightedCollectionValue<E> extends CollectionValue<TableEntry<E>,WeightedTable<E>>
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
WeightedCollectionValue.Immutable<E>
Represents a particular type ofCollectionValue.Immutable
that is backed by aWeightedTable
.static interface
WeightedCollectionValue.Mutable<E>
Represents a particular type ofCollectionValue.Mutable
that is backed by aWeightedTable
.-
Nested classes/interfaces inherited from interface org.spongepowered.api.data.value.Value
Value.Factory
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description WeightedCollectionValue.Immutable<E>
asImmutable()
Retrieves an immutable form of this value.WeightedCollectionValue.Mutable<E>
asMutable()
Retrieves a mutable form of this value.WeightedCollectionValue.Mutable<E>
asMutableCopy()
Retrieves a copy in the mutable form of this value.List<E>
get(Random random)
Selects random valued from this list based on their weight.static <E> WeightedCollectionValue.Immutable<E>
immutableOf(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element)
Constructs an immutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.static <E> WeightedCollectionValue.Immutable<E>
immutableOf(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element)
Constructs an immutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.Key<? extends WeightedCollectionValue<E>>
key()
Gets the key for thisValue
.static <E> WeightedCollectionValue.Mutable<E>
mutableOf(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element)
Constructs a mutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.static <E> WeightedCollectionValue.Mutable<E>
mutableOf(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element)
Constructs a mutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.-
Methods inherited from interface org.spongepowered.api.data.value.CollectionValue
all, contains, containsAll, isEmpty, size
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
mutableOf
static <E> WeightedCollectionValue.Mutable<E> mutableOf(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element)
Constructs a mutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
static <E> WeightedCollectionValue.Mutable<E> mutableOf(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element)
Constructs a mutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
static <E> WeightedCollectionValue.Immutable<E> immutableOf(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element)
Constructs an immutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <E> WeightedCollectionValue.Immutable<E> immutableOf(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element)
Constructs an immutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
key
Key<? extends WeightedCollectionValue<E>> key()
Description copied from interface:Value
Gets the key for thisValue
.
-
get
List<E> get(Random random)
Selects random valued from this list based on their weight.An empty list will be returned if there are no entries in the weighted table.
- Parameters:
random
- The random object to use for selection- Returns:
- The selected values
-
asMutable
WeightedCollectionValue.Mutable<E> asMutable()
Description copied from interface:Value
Retrieves a mutable form of this value. Due to the vague nature of the value itself, some cases can already provide aValue.Mutable
instance where this would simply return itself. In other cases, where the retrieved value is anValue.Immutable
instance, a new mutable value is created with the same key and values.- Specified by:
asMutable
in interfaceCollectionValue<TableEntry<E>,WeightedTable<E>>
- Specified by:
asMutable
in interfaceValue<E>
- Returns:
- A mutable value
-
asMutableCopy
WeightedCollectionValue.Mutable<E> asMutableCopy()
Description copied from interface:Value
Retrieves a copy in the mutable form of this value. The new is created with the same key and values.- Specified by:
asMutableCopy
in interfaceCollectionValue<TableEntry<E>,WeightedTable<E>>
- Specified by:
asMutableCopy
in interfaceValue<E>
- Returns:
- A mutable value
-
asImmutable
WeightedCollectionValue.Immutable<E> asImmutable()
Description copied from interface:Value
Retrieves an immutable form of this value. Due to the vague nature of the value itself, some cases can already provide aValue.Immutable
instance where this would simply return itself. In other cases, where the retrieved value is aValue.Mutable
instance, a new immutable value is created with the same key and values.- Specified by:
asImmutable
in interfaceCollectionValue<TableEntry<E>,WeightedTable<E>>
- Specified by:
asImmutable
in interfaceValue<E>
- Returns:
- An immutable value
-
-