/* $Id$
 *
 * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
 *
 * This software is protected by copyright. You are hereby notified from
 * now by reading this message. This software is also the confidential 
 * and proprietary information of Xenonsoft Limited.  ("Confidential
 * Information"). 
 *
 * This software is distributed under the Xenonsoft Public end user 
 * License ("XPeL"), where the machine-readable source code is provided 
 * under the "Open Source" model.
 * For more information, please read the file "LICENSE-XPL.txt" 
 */

// File:`ObjectListCounter.java'
//
//
// DESCRIPTION
//	Object counter 
// 
// Author
//
//	Peter Pilgrim
//	Fri Jun 11 00:14:10 BST 1999
// 
// RCS HEADER ``ObjectListCounter.java''
// 
//	$Author$
//	$Date$
//	$Source$
//	$Revision$    $State$    $Locker$
//

package xenon.gamekit;

import java.util.Vector;
import java.util.Enumeration;
import java.awt.*;
import java.awt.image.*;

import xenon.gamekit.*;				// for GameEngine, WorldObject, etc

/**
 * an object counter
 */
public class ObjectListCounter 
{
    /** the default size */
    public final static int	DEFAULT_SIZE=32;
    
    private Vector		list;
    
    /** creates an object counter */
    public ObjectListCounter()
    {
	this( DEFAULT_SIZE );
    }
    
    /** creates an object counter */
    public ObjectListCounter( int total )
    {
	list = new Vector( total );
    }
    
    /** add an world object to the container 
     * @param object the world object
     */
    public synchronized void addWorldObject( WorldObject object ) 
    {
	if ( !list.contains( object ) )
	    list.addElement( object );
    }
    
    /** return true if this world object is contained
     * @param object the world object
     */
    public synchronized boolean contains( WorldObject object )
    {
	return list.contains(object);
    }
    
    /** removes an world object from the container 
     * @param object the world object
     */
    public synchronized void removeWorldObject( WorldObject object ) 
    {
	list.removeElement( object );
    }

    /** remove all elements */
    public synchronized void removeAllElements()
    {
	list.removeAllElements();
    }
    
    /**
     * get the enumeration object to iterate through the elements
     * in the list.
     */
    public synchronized Enumeration elements() 
    {
	return list.elements();
    }

    /**
     * get the object count
     */
    public synchronized int getCount() 
    {
	return list.size();
    }

    /**
     * returns true if the object counter is empty 
     */
    public synchronized boolean isEmpty() 
    {
	return ( list.size() == 0 );
    }
}

// fini
