summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/engine/util
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-02-10 11:21:13 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-02-10 11:21:13 +0100
commitce99297b3e4e46070d4f0eb4f5d05ee9c090dd53 (patch)
tree96515aa6bb6976ef903551598b19ce914213d706 /core/src/ch/asynk/rustanddust/engine/util
parent3719043c562e6235f2f62f5b9ac79320fad7f6ae (diff)
downloadRustAndDust-ce99297b3e4e46070d4f0eb4f5d05ee9c090dd53.zip
RustAndDust-ce99297b3e4e46070d4f0eb4f5d05ee9c090dd53.tar.gz
Collection,IterableArray: add indexOf(E)
Diffstat (limited to 'core/src/ch/asynk/rustanddust/engine/util')
-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 a7b5a02..67ea169 100644
--- a/core/src/ch/asynk/rustanddust/engine/util/Collection.java
+++ b/core/src/ch/asynk/rustanddust/engine/util/Collection.java
@@ -16,6 +16,8 @@ public interface Collection<E> extends Iterator, Iterable<E>
public E get(int idx);
+ public int indexOf(E e);
+
public boolean add(E e);
public E remove(int idx);
diff --git a/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java b/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java
index 1b965fc..f1473dd 100644
--- a/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java
+++ b/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java
@@ -72,6 +72,16 @@ public class IterableArray<E> implements Collection<E>
}
@Override
+ public int indexOf(E e)
+ {
+ for (int i = 0; i < data.length; i++) {
+ if (data[i] != null && data[i].equals(e))
+ return i;
+ }
+ return -1;
+ }
+
+ @Override
public boolean add(E e)
{
ensureCapacity(s + 1);