diff options
author | Alexdoru <57050655+Alexdoru@users.noreply.github.com> | 2024-10-09 18:11:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-09 18:11:00 +0200 |
commit | d2a9ed7be356fda78de11a5bceedec501a9f1ffc (patch) | |
tree | 68e0141f05d6f52b53c2906c2a6deeacfac05d36 /src/main/java/gtPlusPlus/api | |
parent | b27b4c35fb01bdabe29abf780486475e2d758e9c (diff) | |
download | GT5-Unofficial-d2a9ed7be356fda78de11a5bceedec501a9f1ffc.tar.gz GT5-Unofficial-d2a9ed7be356fda78de11a5bceedec501a9f1ffc.tar.bz2 GT5-Unofficial-d2a9ed7be356fda78de11a5bceedec501a9f1ffc.zip |
Remove tremendous and useless RAM allocation from GT++ algae pond recipes (#3338)
Diffstat (limited to 'src/main/java/gtPlusPlus/api')
-rw-r--r-- | src/main/java/gtPlusPlus/api/objects/data/WeightedCollection.java | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/src/main/java/gtPlusPlus/api/objects/data/WeightedCollection.java b/src/main/java/gtPlusPlus/api/objects/data/WeightedCollection.java deleted file mode 100644 index 6a14b97e0b..0000000000 --- a/src/main/java/gtPlusPlus/api/objects/data/WeightedCollection.java +++ /dev/null @@ -1,102 +0,0 @@ -package gtPlusPlus.api.objects.data; - -import java.util.Collection; -import java.util.Map; -import java.util.NavigableMap; -import java.util.Random; -import java.util.Set; -import java.util.TreeMap; - -import gregtech.api.objects.XSTR; - -public class WeightedCollection<E> implements Map<Integer, E> { - - private final NavigableMap<Integer, E> map = new TreeMap<>(); - private final Random random; - private int total = 0; - - public WeightedCollection() { - this(new XSTR()); - } - - public WeightedCollection(Random random) { - this.random = random; - } - - public E add(int weight, E object) { - if (weight <= 0) return null; - total += weight; - return map.put(total, object); - } - - private E next() { - int value = random.nextInt(total) + 1; // Can also use floating-point weights - return map.ceilingEntry(value) - .getValue(); - } - - @Override - public int size() { - return map.size(); - } - - @Override - public boolean isEmpty() { - return map.isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return map.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return map.containsValue(value); - } - - public E get() { - return next(); - } - - @Override - public E get(Object key) { - return next(); - } - - @Override - public void putAll(Map m) { - map.putAll(m); - } - - @Override - public void clear() { - map.clear(); - this.total = 0; - } - - @Override - public Set keySet() { - return map.keySet(); - } - - @Override - public Collection values() { - return map.values(); - } - - @Override - public Set entrySet() { - return map.entrySet(); - } - - @Override - public E put(Integer key, E value) { - return add(key, value); - } - - @Override - public E remove(Object key) { - return map.remove(key); - } -} |