package com.editev.chess;
import com.editev.util.Lists;
/** A growing, unsynchronized list of Boards.
*
* @see See the source here.
*/
public class Boards extends Lists {
/** Actually allocates a new list of the right class and size. */
protected Object newList( int capacity ) { return new Board[ capacity ]; }
/** @return the list as an array of Board Objects. */
protected Board[] getList() { return (Board[]) list; }
/** @return the possibly capacity of the list -- if you want the length, use Lists.getLength(). */
protected int getCapacity() { return getList().length; }
/** @return the Board at a given integer index.
*
* @param i index of the Board.
*
* @throws ArrayIndexOutOfBoundsException if the index is not less than getLength()
*/
public Board getAt( int i ) {
Board[] boards = ((Board[]) Boards.this.checkList( i ) );
if (boards[ i ] == null) boards[ i ] = new Board();
return boards[ i ];
}
/** Puts a Board at the end of the list.
*
* @param board Board to append.
*
*/
public void append( Board board ) {
int l = getLength();
setLength( l+1 );
getAt( l ).copyFrom( board );
}
/** Clears the list of Boards. */
public void clear( ) { setLength( 0 ); }
/** Creates an empty Board with the default capacity. */
public Boards() { }
/** Creates an empty Board with the specified capacity. */
public Boards( int capacity ) { super( capacity ); }
/** Represent all these boards for debugging purposes. */
public String toString() {
StringBuffer s = new StringBuffer();
s.append(getLength() + " boards\n" );
for (int i=0; i