import java.util.Vector;
import java.awt.Point;

/**
  *Implements the Composite pattern for StationaryPieces
  *Allows a set of StationaryPieces to be treated as a group
  */
abstract class CompositePiece extends StationaryPiece{
	protected Vector _list;

	/**
	  *Constructor that initializes the list of Pieces
	  */
	public CompositePiece(PlayingField fieldPtr, Point atPoint){
		super(fieldPtr,atPoint);
      	_list = new Vector(10);
	}

	/**
	  *The finalizer method cleans up by removingitems from the list
	  */
	public void finalize(){
		_list.removeAllElements();
	}

	/**
	  *Behavior that propogates a collision with the Paddle to the
	  *individual members of the composition
	  *@param aPaddle The Piece that hit the composite
	  *@param atPoint where the collision ocurs
	  */
	public void collideWithPaddle(Paddle aPaddle, Point atPoint){
		ArcadeGamePiece itemPtr;
		if(!_list.isEmpty()){
			for(int i=0;i < _list.size(); i++){
				itemPtr = (ArcadeGamePiece)_list.elementAt(i);
				itemPtr.collideWithPaddle(aPaddle, atPoint);
			}
		}
	}

	/**
	  *Behavior that propogates a collision with the Puck to the
	  *individual members of the composition
	  *@param aPuck The Piece that hit the composite
	  *@param atPoint where the collision ocurs
	  */
	public void collideWithPuck(Puck aPuck, Point atPoint){
		ArcadeGamePiece itemPtr;
		if(!_list.isEmpty()){
			for(int i=0;i < _list.size(); i++){
				itemPtr = (ArcadeGamePiece)_list.elementAt(i);
				itemPtr.collideWithPuck(aPuck, atPoint);
			}
		}
	}

	/**
	  *Tests whether there are members in the composition
	  *@return returns true if there are no members
	  */
	public boolean isEmpty(){
		if(_list.isEmpty())
			return true;
		else
			return false;
	}


}