summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-05-02 10:58:10 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-05-02 10:58:10 +0200
commit7ccc8701b4b02cc6fa0fd5e69afac58240593b92 (patch)
treed3841717e7e769901f85678946b2f213edcf800a
parentb23abb2bd9dbcfa2296e80aee81ea6cf9cafe611 (diff)
downloadRustAndDust-7ccc8701b4b02cc6fa0fd5e69afac58240593b92.zip
RustAndDust-7ccc8701b4b02cc6fa0fd5e69afac58240593b92.tar.gz
Collection,IterableArray: add insert(E, int)
-rw-r--r--core/src/ch/asynk/rustanddust/engine/util/Collection.java2
-rw-r--r--core/src/ch/asynk/rustanddust/engine/util/IterableArray.java10
2 files changed, 12 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/util/Collection.java b/core/src/ch/asynk/rustanddust/engine/util/Collection.java
index 67ea169..1feb937 100644
--- a/core/src/ch/asynk/rustanddust/engine/util/Collection.java
+++ b/core/src/ch/asynk/rustanddust/engine/util/Collection.java
@@ -20,6 +20,8 @@ public interface Collection<E> extends Iterator, Iterable<E>
public boolean add(E e);
+ public boolean insert(E e, int idx);
+
public E remove(int idx);
public boolean remove(E e);
diff --git a/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java b/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java
index f1473dd..08acb78 100644
--- a/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java
+++ b/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java
@@ -91,6 +91,16 @@ public class IterableArray<E> implements Collection<E>
}
@Override
+ public boolean insert(E e, int idx)
+ {
+ ensureCapacity(s + 1);
+ System.arraycopy(data, idx, data, idx+1, (s - idx));
+ data[idx] = e;
+ s += 1;
+ return true;
+ }
+
+ @Override
public E remove(int i)
{
E e = data[i];