ArrayList replaces Vector master remote/master
authorMarkus Bröker <mbroeker@largo.homelinux.org>
Fri, 17 Dec 2010 22:44:27 +0100
changeset 15 d4b2b9a87d80
parent 14 f12f77aa13b2
child 16 55b0d5006e7b
ArrayList replaces Vector
org/homelinux/largo/games/board/Board.java
org/homelinux/largo/games/board/checkersboard/CheckersBoard.java
--- a/org/homelinux/largo/games/board/Board.java
+++ b/org/homelinux/largo/games/board/Board.java
@@ -9,7 +9,7 @@
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Image;
-import java.util.Vector;
+import java.util.ArrayList;
 
 import javax.swing.JPanel;
 
@@ -21,7 +21,7 @@
     protected Piece board_pieces[];
     private Piece pieces[];
 
-    protected Vector<History> stack;
+    protected ArrayList<History> stack;
     protected int moveNr;
 
     protected static final int EMPTY = 0;
@@ -56,7 +56,7 @@
         black = false;
         blacksTurn = false;
         board_pieces = getPieces(pieces);
-        stack = new Vector<History>();
+        stack = new ArrayList<History>();
         moveNr = 0;
     }
 
@@ -286,8 +286,8 @@
 
         moveNr -= 2;
 
-        h1 = stack.elementAt(moveNr);
-        h2 = stack.elementAt(moveNr + 1);
+        h1 = stack.get(moveNr);
+        h2 = stack.get(moveNr + 1);
 
         board_pieces[h1.pos] = h1.piece;
         board_pieces[h2.pos] = h2.piece;
@@ -305,8 +305,8 @@
         if (moveNr > stack.size() - 2)
             return;
 
-        h1 = stack.elementAt(moveNr);
-        h2 = stack.elementAt(moveNr + 1);
+        h1 = stack.get(moveNr);
+        h2 = stack.get(moveNr + 1);
 
         board_pieces[h1.pos] = h2.piece;
         board_pieces[h2.pos] = new Piece(null, null, EMPTY, 0);
@@ -334,14 +334,12 @@
         if (size < 2)
             return;
 
-        h1 = stack.elementAt(size - 1);
-        h2 = stack.elementAt(size - 2);
+        h1 = stack.remove(size - 1);
+        h2 = stack.remove(size - 2);
 
         pieces[h1.pos] = h1.piece;
         pieces[h2.pos] = h2.piece;
 
-        stack.setSize(size - 2);
-
         /* Reset the current player */
         setBlacksTurn(h2.turn);
     }
--- a/org/homelinux/largo/games/board/checkersboard/CheckersBoard.java
+++ b/org/homelinux/largo/games/board/checkersboard/CheckersBoard.java
@@ -181,8 +181,8 @@
         if (size < 2)
             return;
 
-        h1 = stack.elementAt(size - 1);
-        h2 = stack.elementAt(size - 2);
+        h1 = stack.remove(size - 1);
+        h2 = stack.remove(size - 2);
 
         setPiece(h1.pos(), h1.piece());
         setPiece(h2.pos(), h2.piece());
@@ -193,8 +193,6 @@
                 setPiece(pos, new Piece(null, null, EMPTY, 0));
         }
 
-        stack.setSize(size - 2);
-
         /* Reset the current player */
         setBlacksTurn(h2.turn());
     }