Package dev.selena.luacore.utils
Class RandomCollection<E>
java.lang.Object
dev.selena.luacore.utils.RandomCollection<E>
- Type Parameters:
E
- The reward of any type
Used for weighted random item/object generation
For examples check the wiki
-
Field Summary
-
Constructor Summary
ConstructorDescriptionUsed to initialize the class using a new instance of randomRandomCollection
(long seed) Used to initialize the class using a new instance of random.RandomCollection
(Random random) Used to initialize the class using a fixed instance of random (Note the seed will be the next long generated this is for serialization reason) -
Method Summary
Modifier and TypeMethodDescriptionUsed for adding a weightvoid
Used for appending the collection map with another existing map<T> RandomCollection
<T> Used for cloning a collection instance to another type and doing the required entry manipulationvoid
Used for executing lambda function on each valueGets a weighted random valueboolean
isEmpty()
Used for checking if the collection is empty
-
Field Details
-
map
-
-
Constructor Details
-
RandomCollection
public RandomCollection()Used to initialize the class using a new instance of random -
RandomCollection
Used to initialize the class using a fixed instance of random (Note the seed will be the next long generated this is for serialization reason)- Parameters:
random
- The random instance you want to parse in- See Also:
-
RandomCollection
public RandomCollection(long seed) Used to initialize the class using a new instance of random. You should use this overRandomCollection(Random)
- Parameters:
seed
- The seed you want to use
-
-
Method Details
-
add
Used for adding a weight- Parameters:
weight
- The weight of the item added to the mapresult
- The item itself- Returns:
- This instance for further usage
-
getRandom
Gets a weighted random value- Returns:
- The random value from the map
-
addAll
Used for appending the collection map with another existing map- Parameters:
results
- The map of results/loot you want to append to the existing collection
-
isEmpty
public boolean isEmpty()Used for checking if the collection is empty- Returns:
- True if empty
-
forEach
Used for executing lambda function on each value- Parameters:
function
- The function you want to execute on each entry
-
cloneTo
Used for cloning a collection instance to another type and doing the required entry manipulation- Type Parameters:
T
- The element Type of the new collection- Parameters:
elementType
- The element type you want to convert tofunction
- The required data manipulation to make the conversion work- Returns:
- The cloned and altered instance
-