diff options
Diffstat (limited to 'core/src')
4 files changed, 62 insertions, 27 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java b/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java index a8701a2..f310a60 100644 --- a/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java +++ b/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java @@ -18,33 +18,6 @@ public class IterableArray<E> extends ArrayList<E> implements Iterator, Iterable super(n); } - public void push(E e) - { - add(e); - } - - public E pop() - { - return remove(size() - 1); - } - - public void enqueue(E e) - { - add(e); - } - - public E dequeue() - { - return remove(0); - } - - public boolean addUnique(E e) - { - if (contains(e)) return false; - super.add(e); - return true; - } - @Override @SuppressWarnings("unchecked") public Iterator<E> iterator() diff --git a/core/src/ch/asynk/rustanddust/engine/util/IterableQueue.java b/core/src/ch/asynk/rustanddust/engine/util/IterableQueue.java new file mode 100644 index 0000000..7e560e2 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/engine/util/IterableQueue.java @@ -0,0 +1,19 @@ +package ch.asynk.rustanddust.engine.util; + +public class IterableQueue<E> extends IterableArray<E> +{ + public IterableQueue(int n) + { + super(n); + } + + public void enqueue(E e) + { + add(e); + } + + public E dequeue() + { + return remove(0); + } +} diff --git a/core/src/ch/asynk/rustanddust/engine/util/IterableSet.java b/core/src/ch/asynk/rustanddust/engine/util/IterableSet.java new file mode 100644 index 0000000..1078e62 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/engine/util/IterableSet.java @@ -0,0 +1,17 @@ +package ch.asynk.rustanddust.engine.util; + +public class IterableSet<E> extends IterableArray<E> +{ + public IterableSet(int n) + { + super(n); + } + + @Override + public boolean add(E e) + { + if (contains(e)) return false; + super.add(e); + return true; + } +} diff --git a/core/src/ch/asynk/rustanddust/engine/util/IterableStack.java b/core/src/ch/asynk/rustanddust/engine/util/IterableStack.java new file mode 100644 index 0000000..4668840 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/engine/util/IterableStack.java @@ -0,0 +1,26 @@ +package ch.asynk.rustanddust.engine.util; + +public class IterableStack<E> extends IterableArray<E> +{ + public IterableStack(int n) + { + super(n); + } + + public void push(E e) + { + add(e); + } + + public E pop() + { + if (size() <= 0) return null; + return remove(size() - 1); + } + + public E getTop() + { + if (size() <= 0) return null; + return get(size() - 1); + } +} |