org.mars_sim.msp.simulation
Class Unit

java.lang.Object
  extended by org.mars_sim.msp.simulation.Unit
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Equipment, MockUnit1, MockUnit2, Person, Structure, Vehicle

public abstract class Unit
extends java.lang.Object
implements java.io.Serializable

The Unit class is the abstract parent class to all units in the Simulation. Units include people, vehicles and settlements. This class provides data members and methods common to all units.

See Also:
Serialized Form

Field Summary
static java.lang.String CONTAINER_UNIT_EVENT
           
static java.lang.String DESCRIPTION_EVENT
           
static java.lang.String LOCATION_EVENT
           
static java.lang.String MASS_EVENT
           
static java.lang.String NAME_EVENT
           
 
Constructor Summary
Unit(java.lang.String name, Coordinates location)
          Constructor
 
Method Summary
 void addUnitListener(UnitListener newListener)
          Adds a unit listener
 void fireUnitUpdate(java.lang.String updateType)
          Fire a unit update event.
 void fireUnitUpdate(java.lang.String updateType, java.lang.Object target)
          Fire a unit update event.
 double getBaseMass()
          Gets the base mass of the unit.
 Unit getContainerUnit()
          Gets the unit's container unit.
 Coordinates getCoordinates()
          Gets the unit's location
 java.lang.String getDescription()
          Gets the unit's description
 Inventory getInventory()
          Gets the unit's inventory
 double getMass()
          Gets the unit's mass including inventory mass.
 java.lang.String getName()
          Gets the unit's name
 Unit getTopContainerUnit()
          Gets the topmost container unit that owns this unit.
 UnitManager getUnitManager()
          Gets the unit's UnitManager
 void removeUnitListener(UnitListener oldListener)
          Removes a unit listener
protected  void setBaseMass(double baseMass)
          Sets the unit's base mass.
 void setContainerUnit(Unit containerUnit)
          Sets the unit's container unit.
 void setCoordinates(Coordinates newLocation)
          Sets unit's location coordinates
protected  void setDescription(java.lang.String description)
          Sets the unit's description.
 void setName(java.lang.String name)
          Sets the unit's name
 void timePassing(double time)
          Time passing for unit.
 java.lang.String toString()
          String representation of this Unit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME_EVENT

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

DESCRIPTION_EVENT

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

MASS_EVENT

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

LOCATION_EVENT

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

CONTAINER_UNIT_EVENT

public static final java.lang.String CONTAINER_UNIT_EVENT
See Also:
Constant Field Values
Constructor Detail

Unit

public Unit(java.lang.String name,
            Coordinates location)
Constructor

Parameters:
name - the name of the unit
location - the unit's location
Method Detail

getUnitManager

public UnitManager getUnitManager()
Gets the unit's UnitManager

Returns:
the unit's unit manager

getName

public java.lang.String getName()
Gets the unit's name

Returns:
the unit's name

setName

public final void setName(java.lang.String name)
Sets the unit's name

Parameters:
name - new name

getDescription

public java.lang.String getDescription()
Gets the unit's description

Returns:
description

setDescription

protected final void setDescription(java.lang.String description)
Sets the unit's description.

Parameters:
description - new description.

getCoordinates

public Coordinates getCoordinates()
Gets the unit's location

Returns:
the unit's location

setCoordinates

public void setCoordinates(Coordinates newLocation)
Sets unit's location coordinates

Parameters:
newLocation - the new location of the unit

timePassing

public void timePassing(double time)
                 throws java.lang.Exception
Time passing for unit. Unit should take action or be modified by time as appropriate.

Parameters:
time - the amount of time passing (in millisols)
Throws:
java.lang.Exception - if error during time passing.

getInventory

public Inventory getInventory()
Gets the unit's inventory

Returns:
the unit's inventory object

getContainerUnit

public Unit getContainerUnit()
Gets the unit's container unit. Returns null if unit has no container unit.

Returns:
the unit's container unit

getTopContainerUnit

public Unit getTopContainerUnit()
Gets the topmost container unit that owns this unit. Returns null if unit has no container unit.

Returns:
the unit's topmost container unit

setContainerUnit

public void setContainerUnit(Unit containerUnit)
Sets the unit's container unit.

Parameters:
containerUnit - the unit to contain this unit.

getMass

public double getMass()
               throws java.lang.Exception
Gets the unit's mass including inventory mass.

Returns:
mass of unit and inventory
Throws:
java.lang.Exception - if error getting the mass.

setBaseMass

protected final void setBaseMass(double baseMass)
Sets the unit's base mass.

Parameters:
baseMass - mass (kg)

getBaseMass

public double getBaseMass()
Gets the base mass of the unit.

Returns:
base mass (kg).

toString

public java.lang.String toString()
String representation of this Unit.

Overrides:
toString in class java.lang.Object
Returns:
The units name.

addUnitListener

public final void addUnitListener(UnitListener newListener)
Adds a unit listener

Parameters:
newListener - the listener to add.

removeUnitListener

public final void removeUnitListener(UnitListener oldListener)
Removes a unit listener

Parameters:
oldListener - the listener to remove.

fireUnitUpdate

public final void fireUnitUpdate(java.lang.String updateType)
Fire a unit update event.

Parameters:
updateType - the update type.

fireUnitUpdate

public final void fireUnitUpdate(java.lang.String updateType,
                                 java.lang.Object target)
Fire a unit update event.

Parameters:
updateType - the update type.
target - the event target object or null if none.