From 7261b45159b79cf2c6fbd417a9e6e9b27eff13f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 11 Jan 2016 12:09:20 +0100 Subject: extract IterableStack, IterableSet and IterableQueue out of IterableArray --- .../rustanddust/engine/util/IterableArray.java | 27 ---------------------- .../rustanddust/engine/util/IterableQueue.java | 19 +++++++++++++++ .../asynk/rustanddust/engine/util/IterableSet.java | 17 ++++++++++++++ .../rustanddust/engine/util/IterableStack.java | 26 +++++++++++++++++++++ 4 files changed, 62 insertions(+), 27 deletions(-) create mode 100644 core/src/ch/asynk/rustanddust/engine/util/IterableQueue.java create mode 100644 core/src/ch/asynk/rustanddust/engine/util/IterableSet.java create mode 100644 core/src/ch/asynk/rustanddust/engine/util/IterableStack.java 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 extends ArrayList 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 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 extends IterableArray +{ + 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 extends IterableArray +{ + 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 extends IterableArray +{ + 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); + } +} -- cgit v1.1-2-g2b99