aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/api/objects/data/WeightedCollection.java
diff options
context:
space:
mode:
authorMartin Robertz <dream-master@gmx.net>2021-12-15 16:11:54 +0100
committerGitHub <noreply@github.com>2021-12-15 16:11:54 +0100
commit128c74faa99dfef8d056c1d82c6e4388b9d470e8 (patch)
tree2c84162154ba681232f86dffd4106db530236814 /src/Java/gtPlusPlus/api/objects/data/WeightedCollection.java
parent47ce336f288a45aa3244c8ae1177499fa5080942 (diff)
parentff4b8c7068c2ea7d654e9beda00646d23e62b314 (diff)
downloadGT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.tar.gz
GT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.tar.bz2
GT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.zip
Merge pull request #65 from GTNewHorizons/unified-build-script2
Move sources and resources
Diffstat (limited to 'src/Java/gtPlusPlus/api/objects/data/WeightedCollection.java')
-rw-r--r--src/Java/gtPlusPlus/api/objects/data/WeightedCollection.java102
1 files changed, 0 insertions, 102 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/data/WeightedCollection.java b/src/Java/gtPlusPlus/api/objects/data/WeightedCollection.java
deleted file mode 100644
index f9966474b0..0000000000
--- a/src/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 gtPlusPlus.api.objects.random.XSTR;
-
-public class WeightedCollection<E> implements Map<Integer, E> {
-
- private NavigableMap<Integer, E> map = new TreeMap<Integer, E>();
- private 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);
- }
-
-} \ No newline at end of file