Class RandomCollection<E>

java.lang.Object
dev.selena.luacore.utils.RandomCollection<E>
Type Parameters:
E - The reward of any type

public class RandomCollection<E> extends Object
Used for weighted random item/object generation For examples check the wiki
  • Field Details

  • Constructor Details

    • RandomCollection

      public RandomCollection()
      Used to initialize the class using a new instance of random
    • RandomCollection

      public 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)
      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 over RandomCollection(Random)
      Parameters:
      seed - The seed you want to use
  • Method Details

    • add

      public RandomCollection<E> add(double weight, E result)
      Used for adding a weight
      Parameters:
      weight - The weight of the item added to the map
      result - The item itself
      Returns:
      This instance for further usage
    • getRandom

      public E getRandom()
      Gets a weighted random value
      Returns:
      The random value from the map
    • addAll

      public void addAll(Map<E,Double> results)
      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

      public void forEach(Function<E,E> function)
      Used for executing lambda function on each value
      Parameters:
      function - The function you want to execute on each entry
    • cloneTo

      public <T> RandomCollection<T> cloneTo(Class<T> elementType, Function<E,T> function)
      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 to
      function - The required data manipulation to make the conversion work
      Returns:
      The cloned and altered instance