diff options
author | Thinkofdeath <thinkofdeath@spigotmc.org> | 2015-04-13 11:04:38 +0100 |
---|---|---|
committer | Thinkofdeath <thinkofdeath@spigotmc.org> | 2015-04-13 11:04:38 +0100 |
commit | 35d953bac8222289e039fb2c736020e94699c195 (patch) | |
tree | 4fffc9c38c225a2df579a852e601a41a7491553a /src | |
parent | 501372f2c968a03be98e2d161c6228f4a5d856fb (diff) | |
download | craftbukkit-35d953bac8222289e039fb2c736020e94699c195.tar craftbukkit-35d953bac8222289e039fb2c736020e94699c195.tar.gz craftbukkit-35d953bac8222289e039fb2c736020e94699c195.tar.lz craftbukkit-35d953bac8222289e039fb2c736020e94699c195.tar.xz craftbukkit-35d953bac8222289e039fb2c736020e94699c195.zip |
Replace the two nextTickList sets with a single one that combines both
Should prevent them from going out of sync
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/util/HashTreeSet.java | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/util/HashTreeSet.java b/src/main/java/org/bukkit/craftbukkit/util/HashTreeSet.java new file mode 100644 index 00000000..80a5c29f --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/util/HashTreeSet.java @@ -0,0 +1,117 @@ +package org.bukkit.craftbukkit.util; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +public class HashTreeSet<V> implements Set<V> { + + private HashSet<V> hash = new HashSet<V>(); + private TreeSet<V> tree = new TreeSet<V>(); + + public HashTreeSet() { + + } + + @Override + public int size() { + return hash.size(); + } + + @Override + public boolean isEmpty() { + return hash.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return hash.contains(o); + } + + @Override + public Iterator<V> iterator() { + return new Iterator<V>() { + + private Iterator<V> it = tree.iterator(); + private V last; + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public V next() { + return last = it.next(); + } + + @Override + public void remove() { + if (last == null) { + throw new IllegalStateException(); + } + it.remove(); + hash.remove(last); + last = null; + } + }; + } + + @Override + public Object[] toArray() { + return hash.toArray(); + } + + @Override + public Object[] toArray(Object[] a) { + return hash.toArray(a); + } + + @Override + public boolean add(V e) { + hash.add(e); + return tree.add(e); + } + + @Override + public boolean remove(Object o) { + hash.remove(o); + return tree.remove(o); + } + + @Override + public boolean containsAll(Collection c) { + return hash.containsAll(c); + } + + @Override + public boolean addAll(Collection c) { + tree.addAll(c); + return hash.addAll(c); + } + + @Override + public boolean retainAll(Collection c) { + tree.retainAll(c); + return hash.retainAll(c); + } + + @Override + public boolean removeAll(Collection c) { + tree.removeAll(c); + return hash.removeAll(c); + } + + @Override + public void clear() { + hash.clear(); + tree.clear(); + } + + public V first() { + return tree.first(); + } + +} |