org.mars_sim.msp.simulation
Class UnitManager

java.lang.Object
  extended by org.mars_sim.msp.simulation.UnitManager
All Implemented Interfaces:
java.io.Serializable

public class UnitManager
extends java.lang.Object
implements java.io.Serializable

The UnitManager class contains and manages all units in virtual Mars. It has methods for getting information about units. It is also responsible for creating all units on its construction. There should be only one instance of this class and it should be constructed and owned by the virtual Mars object.

See Also:
Serialized Form

Field Summary
static java.lang.String EQUIPMENT
           
static java.lang.String PERSON
           
static java.lang.String SETTLEMENT
           
static java.lang.String VEHICLE
           
 
Method Summary
 void addUnit(Unit unit)
          Adds a unit to the unit manager if it doesn't already have it.
 void addUnitManagerListener(UnitManagerListener newListener)
          Adds a unit manager listener
 Unit findUnit(java.lang.String name)
          Finds a unit in the simulation that has the given name.
 void fireUnitManagerUpdate(java.lang.String eventType, Unit unit)
          Fire a unit update event.
 java.util.Collection<Equipment> getEquipment()
          Get a collection of equipment.
 int getEquipmentNum()
          Get the number of equipment.
 java.lang.String getNewName(java.lang.String unitType, java.lang.String baseName, java.lang.String gender)
          Gets a new name for a unit.
 java.util.Collection<Person> getPeople()
          Get people in virtual Mars
 int getPeopleNum()
          Get number of people
 int getSettlementNum()
          Get number of settlements
 java.util.Collection<Settlement> getSettlements()
          Get settlements in vitual Mars
 int getUnitNum()
          The total number of units
 java.util.Collection<Unit> getUnits()
          Get all units in virtual Mars
 int getVehicleNum()
          Get number of vehicles
 java.util.Collection<Vehicle> getVehicles()
          Get vehicles in virtual Mars
 void removeUnitManagerListener(UnitManagerListener oldListener)
          Removes a unit manager listener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SETTLEMENT

public static final java.lang.String SETTLEMENT
See Also:
Constant Field Values

PERSON

public static final java.lang.String PERSON
See Also:
Constant Field Values

VEHICLE

public static final java.lang.String VEHICLE
See Also:
Constant Field Values

EQUIPMENT

public static final java.lang.String EQUIPMENT
See Also:
Constant Field Values
Method Detail

addUnit

public void addUnit(Unit unit)
Adds a unit to the unit manager if it doesn't already have it.

Parameters:
unit - new unit to add.

getNewName

public java.lang.String getNewName(java.lang.String unitType,
                                   java.lang.String baseName,
                                   java.lang.String gender)
Gets a new name for a unit.

Parameters:
unitType - the type of unit.
baseName - the base name or null if none.
gender - the gender of the person or null if not a person.
Returns:
new name
Throws:
java.lang.IllegalArgumentException - if unitType is not valid.

getSettlementNum

public int getSettlementNum()
Get number of settlements

Returns:
the number of settlements

getSettlements

public java.util.Collection<Settlement> getSettlements()
Get settlements in vitual Mars

Returns:
Collection of settlements

getVehicleNum

public int getVehicleNum()
Get number of vehicles

Returns:
the number of vehicles

getVehicles

public java.util.Collection<Vehicle> getVehicles()
Get vehicles in virtual Mars

Returns:
Collection of vehicles

getPeopleNum

public int getPeopleNum()
Get number of people

Returns:
the number of people

getPeople

public java.util.Collection<Person> getPeople()
Get people in virtual Mars

Returns:
Collection of people

getEquipmentNum

public int getEquipmentNum()
Get the number of equipment.

Returns:
number

getEquipment

public java.util.Collection<Equipment> getEquipment()
Get a collection of equipment.

Returns:
collection

getUnitNum

public int getUnitNum()
The total number of units

Returns:
the total number of units

getUnits

public java.util.Collection<Unit> getUnits()
Get all units in virtual Mars

Returns:
Colleciton of units

addUnitManagerListener

public final void addUnitManagerListener(UnitManagerListener newListener)
Adds a unit manager listener

Parameters:
newListener - the listener to add.

removeUnitManagerListener

public final void removeUnitManagerListener(UnitManagerListener oldListener)
Removes a unit manager listener

Parameters:
oldListener - the listener to remove.

fireUnitManagerUpdate

public final void fireUnitManagerUpdate(java.lang.String eventType,
                                        Unit unit)
Fire a unit update event.

Parameters:
eventType - the event type.
unit - the unit causing the event.

findUnit

public Unit findUnit(java.lang.String name)
Finds a unit in the simulation that has the given name.

Parameters:
name - the name to search for.
Returns:
unit or null if none.