summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-01-11 12:09:20 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-01-11 12:09:20 +0100
commit7261b45159b79cf2c6fbd417a9e6e9b27eff13f8 (patch)
treec92631872a1e47e222fce4e726bee88ed9fcd8a8
parent432fb6f91d186dd7dad12982d24aa66a4ae80ec0 (diff)
downloadRustAndDust-7261b45159b79cf2c6fbd417a9e6e9b27eff13f8.zip
RustAndDust-7261b45159b79cf2c6fbd417a9e6e9b27eff13f8.tar.gz
extract IterableStack, IterableSet and IterableQueue out of IterableArray
-rw-r--r--core/src/ch/asynk/rustanddust/engine/util/IterableArray.java27
-rw-r--r--core/src/ch/asynk/rustanddust/engine/util/IterableQueue.java19
-rw-r--r--core/src/ch/asynk/rustanddust/engine/util/IterableSet.java17
-rw-r--r--core/src/ch/asynk/rustanddust/engine/util/IterableStack.java26
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);
+ }
+}