1package com.osroyale.game.world.entity.mob.npc.drop;
3import java.util.NavigableMap;
4import java.util.Random;
5import java.util.TreeMap;
7public class WeightedCollection<E> {
8 private final NavigableMap<Double, E> map =
new TreeMap<>();
9 private final Random random;
10 private double total = 0;
12 public double getTotal() {
16 public WeightedCollection() {
20 public WeightedCollection(Random random) {
24 public WeightedCollection<E> add(
double weight, E result) {
25 if (weight <= 0)
return this;
27 map.put(total, result);
32 double value = random.nextDouble() * total;
33 return map.higherEntry(value).getValue();