From 432fb6f91d186dd7dad12982d24aa66a4ae80ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 11 Jan 2016 10:37:38 +0100 Subject: ArrayListIt -> IterableArray --- core/src/ch/asynk/rustanddust/engine/Board.java | 8 +-- .../src/ch/asynk/rustanddust/engine/OrderList.java | 4 +- core/src/ch/asynk/rustanddust/engine/Path.java | 6 +- .../ch/asynk/rustanddust/engine/PathBuilder.java | 14 ++-- .../ch/asynk/rustanddust/engine/SearchBoard.java | 18 ++--- core/src/ch/asynk/rustanddust/engine/Tile.java | 6 +- core/src/ch/asynk/rustanddust/engine/TileSet.java | 4 +- .../engine/gfx/animations/AnimationSequence.java | 6 +- .../asynk/rustanddust/engine/util/ArrayListIt.java | 78 ---------------------- .../rustanddust/engine/util/IterableArray.java | 78 ++++++++++++++++++++++ core/src/ch/asynk/rustanddust/game/Engagement.java | 4 +- core/src/ch/asynk/rustanddust/game/UnitList.java | 4 +- .../rustanddust/game/battles/BattleCommon.java | 6 +- 13 files changed, 118 insertions(+), 118 deletions(-) delete mode 100644 core/src/ch/asynk/rustanddust/engine/util/ArrayListIt.java create mode 100644 core/src/ch/asynk/rustanddust/engine/util/IterableArray.java diff --git a/core/src/ch/asynk/rustanddust/engine/Board.java b/core/src/ch/asynk/rustanddust/engine/Board.java index 3bf909e..119e850 100644 --- a/core/src/ch/asynk/rustanddust/engine/Board.java +++ b/core/src/ch/asynk/rustanddust/engine/Board.java @@ -14,7 +14,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Matrix4; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; import ch.asynk.rustanddust.engine.gfx.Moveable; import ch.asynk.rustanddust.engine.gfx.Animation; import ch.asynk.rustanddust.engine.gfx.animations.AnimationSequence; @@ -59,9 +59,9 @@ public abstract class Board implements Disposable, Animation private int tileCount = 0; private int pawnCount = 0; private int animationCount = 0; - private final ArrayListIt animations = new ArrayListIt(10); - private final ArrayListIt nextAnimations = new ArrayListIt(10); - private final ArrayListIt tilesToDraw = new ArrayListIt(20); + private final IterableArray animations = new IterableArray(10); + private final IterableArray nextAnimations = new IterableArray(10); + private final IterableArray tilesToDraw = new IterableArray(20); protected SelectedTile selectedTile; diff --git a/core/src/ch/asynk/rustanddust/engine/OrderList.java b/core/src/ch/asynk/rustanddust/engine/OrderList.java index 92a85ea..9e4fe6c 100644 --- a/core/src/ch/asynk/rustanddust/engine/OrderList.java +++ b/core/src/ch/asynk/rustanddust/engine/OrderList.java @@ -6,9 +6,9 @@ import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.JsonValue; import com.badlogic.gdx.utils.JsonWriter.OutputType; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; -public class OrderList extends ArrayListIt implements Json.Serializable +public class OrderList extends IterableArray implements Json.Serializable { public OrderList(int capacity) { diff --git a/core/src/ch/asynk/rustanddust/engine/Path.java b/core/src/ch/asynk/rustanddust/engine/Path.java index 6fd3c47..bb772b3 100644 --- a/core/src/ch/asynk/rustanddust/engine/Path.java +++ b/core/src/ch/asynk/rustanddust/engine/Path.java @@ -3,7 +3,7 @@ package ch.asynk.rustanddust.engine; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.Disposable; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; public class Path implements Disposable, Pool.Poolable { @@ -29,7 +29,7 @@ public class Path implements Disposable, Pool.Poolable public int cost; public int fitness; public boolean roadMarch; - public ArrayListIt tiles; + public IterableArray tiles; public Path() { @@ -42,7 +42,7 @@ public class Path implements Disposable, Pool.Poolable protected void init(int size) { if (tiles == null) - tiles = new ArrayListIt(size); + tiles = new IterableArray(size); else tiles. ensureCapacity(size); cost = -1; diff --git a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java index aaaf399..d5c79d9 100644 --- a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java +++ b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java @@ -4,7 +4,7 @@ import java.util.List; import com.badlogic.gdx.utils.Disposable; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; public class PathBuilder implements Disposable { @@ -19,16 +19,16 @@ public class PathBuilder implements Disposable private List ctrlTiles; private List paths; private List filteredPaths; - private ArrayListIt tiles; + private IterableArray tiles; public PathBuilder(Board board, int tSize, int stSize, int ftSize, int psSize) { this.board = board; - this.tiles = new ArrayListIt(tSize); - this.stack = new ArrayListIt(stSize); - this.ctrlTiles = new ArrayListIt(ftSize); - this.paths = new ArrayListIt(psSize); - this.filteredPaths = new ArrayListIt(psSize); + this.tiles = new IterableArray(tSize); + this.stack = new IterableArray(stSize); + this.ctrlTiles = new IterableArray(ftSize); + this.paths = new IterableArray(psSize); + this.filteredPaths = new IterableArray(psSize); this.to = null; this.pawn = null; this.orientation = Orientation.KEEP; diff --git a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java index 9fd06ad..7fd2ef6 100644 --- a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java +++ b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java @@ -3,7 +3,7 @@ package ch.asynk.rustanddust.engine; import java.util.List; import java.util.Collection; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; public class SearchBoard { @@ -35,10 +35,10 @@ public class SearchBoard private int searchCount; private Node nodes[]; - private ArrayListIt stack; - private ArrayListIt queue; - private ArrayListIt roadMarch; - private ArrayListIt los; + private IterableArray stack; + private IterableArray queue; + private IterableArray roadMarch; + private IterableArray los; private boolean losBlocked; public SearchBoard(Board board, int cols, int rows) @@ -55,10 +55,10 @@ public class SearchBoard nodes[i + (j * cols)] = new Node((i + dx), j); } - this.queue = new ArrayListIt(30); - this.stack = new ArrayListIt(20); - this.roadMarch = new ArrayListIt(5); - this.los = new ArrayListIt(10); + this.queue = new IterableArray(30); + this.stack = new IterableArray(20); + this.roadMarch = new IterableArray(5); + this.los = new IterableArray(10); } private boolean inMap(int col, int row) diff --git a/core/src/ch/asynk/rustanddust/engine/Tile.java b/core/src/ch/asynk/rustanddust/engine/Tile.java index 7bb2fe7..20d8fd7 100644 --- a/core/src/ch/asynk/rustanddust/engine/Tile.java +++ b/core/src/ch/asynk/rustanddust/engine/Tile.java @@ -8,7 +8,7 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; import ch.asynk.rustanddust.engine.gfx.Drawable; import ch.asynk.rustanddust.engine.gfx.StackedImages; @@ -31,7 +31,7 @@ public abstract class Tile implements Drawable, Disposable, Iterable protected float x; protected float y; private StackedImages overlays; - private ArrayListIt stack; + private IterableArray stack; protected Faction curFaction; protected Faction prevFaction; @@ -51,7 +51,7 @@ public abstract class Tile implements Drawable, Disposable, Iterable { this.col = col; this.row = row; - this.stack = new ArrayListIt(capacity); + this.stack = new IterableArray(capacity); this.curFaction = defaultFaction; this.prevFaction = defaultFaction; this.objective = Objective.NONE; diff --git a/core/src/ch/asynk/rustanddust/engine/TileSet.java b/core/src/ch/asynk/rustanddust/engine/TileSet.java index 9531549..233232e 100644 --- a/core/src/ch/asynk/rustanddust/engine/TileSet.java +++ b/core/src/ch/asynk/rustanddust/engine/TileSet.java @@ -1,8 +1,8 @@ package ch.asynk.rustanddust.engine; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; -public class TileSet extends ArrayListIt +public class TileSet extends IterableArray { private final Board board; diff --git a/core/src/ch/asynk/rustanddust/engine/gfx/animations/AnimationSequence.java b/core/src/ch/asynk/rustanddust/engine/gfx/animations/AnimationSequence.java index d2feee8..49dd353 100644 --- a/core/src/ch/asynk/rustanddust/engine/gfx/animations/AnimationSequence.java +++ b/core/src/ch/asynk/rustanddust/engine/gfx/animations/AnimationSequence.java @@ -5,11 +5,11 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.rustanddust.engine.gfx.Animation; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; public class AnimationSequence implements Animation, Pool.Poolable { - private ArrayListIt animations; + private IterableArray animations; private static final Pool animationSequencePool = new Pool() { @Override @@ -22,7 +22,7 @@ public class AnimationSequence implements Animation, Pool.Poolable { AnimationSequence seq = animationSequencePool.obtain(); if (seq.animations == null) - seq.animations = new ArrayListIt(capacity); + seq.animations = new IterableArray(capacity); else seq.animations.ensureCapacity(capacity); diff --git a/core/src/ch/asynk/rustanddust/engine/util/ArrayListIt.java b/core/src/ch/asynk/rustanddust/engine/util/ArrayListIt.java deleted file mode 100644 index 16990eb..0000000 --- a/core/src/ch/asynk/rustanddust/engine/util/ArrayListIt.java +++ /dev/null @@ -1,78 +0,0 @@ -package ch.asynk.rustanddust.engine.util; - -import java.util.ArrayList; -import java.util.Iterator; - -public class ArrayListIt extends ArrayList implements Iterator, Iterable -{ - private int i; - private int s; - - public ArrayListIt() - { - super(); - } - - public ArrayListIt(int n) - { - 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() - { - this.i = 0; - this.s = size(); - return (Iterator) this; - } - - @Override - public boolean hasNext() - { - return (i < s); - } - - @Override - public E next() - { - E e = get(i); - i += 1; - return e; - } - - @Override - public void remove() - { - i -=1; - s -= 1; - remove(i); - } -} diff --git a/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java b/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java new file mode 100644 index 0000000..a8701a2 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/engine/util/IterableArray.java @@ -0,0 +1,78 @@ +package ch.asynk.rustanddust.engine.util; + +import java.util.ArrayList; +import java.util.Iterator; + +public class IterableArray extends ArrayList implements Iterator, Iterable +{ + private int i; + private int s; + + public IterableArray() + { + super(); + } + + public IterableArray(int n) + { + 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() + { + this.i = 0; + this.s = size(); + return (Iterator) this; + } + + @Override + public boolean hasNext() + { + return (i < s); + } + + @Override + public E next() + { + E e = get(i); + i += 1; + return e; + } + + @Override + public void remove() + { + i -=1; + s -= 1; + remove(i); + } +} diff --git a/core/src/ch/asynk/rustanddust/game/Engagement.java b/core/src/ch/asynk/rustanddust/game/Engagement.java index 858792e..937739e 100644 --- a/core/src/ch/asynk/rustanddust/game/Engagement.java +++ b/core/src/ch/asynk/rustanddust/game/Engagement.java @@ -6,7 +6,7 @@ import java.util.Random; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.Disposable; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; public class Engagement implements Disposable, Pool.Poolable { @@ -52,7 +52,7 @@ public class Engagement implements Disposable, Pool.Poolable public Engagement() { - assists = new ArrayListIt(10); + assists = new IterableArray(10); reset(); } diff --git a/core/src/ch/asynk/rustanddust/game/UnitList.java b/core/src/ch/asynk/rustanddust/game/UnitList.java index 834dd98..fde9a5c 100644 --- a/core/src/ch/asynk/rustanddust/game/UnitList.java +++ b/core/src/ch/asynk/rustanddust/game/UnitList.java @@ -1,11 +1,11 @@ package ch.asynk.rustanddust.game; import java.util.Collection; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; import ch.asynk.rustanddust.engine.Pawn; -public class UnitList extends ArrayListIt +public class UnitList extends IterableArray { public UnitList(int n) { diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java index 7b7904d..5023d5a 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java @@ -14,7 +14,7 @@ import ch.asynk.rustanddust.game.Unit.UnitId; import ch.asynk.rustanddust.game.Factory; import ch.asynk.rustanddust.game.State.StateType; import ch.asynk.rustanddust.engine.Orientation; -import ch.asynk.rustanddust.engine.util.ArrayListIt; +import ch.asynk.rustanddust.engine.util.IterableArray; public abstract class BattleCommon implements Battle { @@ -28,8 +28,8 @@ public abstract class BattleCommon implements Battle protected Player currentPlayer; protected Player usPlayer; protected Player gePlayer; - protected ArrayListIt entryZone = new ArrayListIt(); - protected ArrayListIt exitZone = new ArrayListIt(); + protected IterableArray entryZone = new IterableArray(); + protected IterableArray exitZone = new IterableArray(); protected HashMap unitEntry = new HashMap(); protected HashMap unitExit = new HashMap(); -- cgit v1.1-2-g2b99