org.mars_sim.msp.simulation.structure.building
Class BuildingManager

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

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

The BuildingManager manages the settlement's buildings.

See Also:
Serialized Form

Field Summary
static java.lang.String ADD_BUILDING_EVENT
           
 
Constructor Summary
BuildingManager(Settlement settlement)
          Constructor to construct buildings from settlement config template.
BuildingManager(Settlement settlement, java.util.List<java.lang.String> buildingNames)
          Constructor to construct buildings from name list.
 
Method Summary
 void addBuilding(Building newBuilding)
          Adds a new building to the settlement.
 void addBuilding(java.lang.String buildingType)
          Adds a building of a specific building type to the settlement.
static void addPersonToBuilding(Person person, Building building)
          Adds the person to the building if possible.
static void addToRandomBuilding(GroundVehicle vehicle, Settlement settlement)
          Adds a ground vehicle to a random ground vehicle maintenance building within a settlement.
static void addToRandomBuilding(Person person, Settlement settlement)
          Adds a person to a random inhabitable building within a settlement.
static java.util.List<Building> getBestRelationshipBuildings(Person person, java.util.List<Building> buildingList)
          Gets a list of buildings with the best relationships for a given person from a list of buildings.
static Building getBuilding(Person person)
          Gets the building a given person is in.
static Building getBuilding(Vehicle vehicle)
          Gets the vehicle maintenance building a given vehicle is in.
 int getBuildingNum()
          Gets the number of buildings at the settlement.
 java.util.List<Building> getBuildings()
          Gets the settlement's collection of buildings.
 java.util.List<Building> getBuildings(java.lang.String functionName)
          Gets the buildings in a settlement that has a given function.
static java.util.List<Building> getLeastCrowdedBuildings(java.util.List<Building> buildingList)
          Gets a list of the least crowded buildings from a given list of buildings with life support.
static java.util.List<Building> getNonMalfunctioningBuildings(java.util.List<Building> buildingList)
          Gets a list of buildings that don't have any malfunctions from a list of buildings.
 Settlement getSettlement()
          Gets the building manager's settlement.
static java.util.List<Building> getUncrowdedBuildings(java.util.List<Building> buildingList)
          Gets a list of uncrowded buildings from a given list of buildings with life support.
 void timePassing(double time)
          Time passing for all buildings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADD_BUILDING_EVENT

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

BuildingManager

public BuildingManager(Settlement settlement)
                throws java.lang.Exception
Constructor to construct buildings from settlement config template.

Parameters:
settlement - the manager's settlement.
Throws:
java.lang.Exception - if buildings cannot be constructed.

BuildingManager

public BuildingManager(Settlement settlement,
                       java.util.List<java.lang.String> buildingNames)
                throws java.lang.Exception
Constructor to construct buildings from name list.

Parameters:
settlement - the manager's settlement
buildingNames - the names of the settlement's buildings.
Throws:
java.lang.Exception - if buildings cannot be constructed.
Method Detail

getSettlement

public Settlement getSettlement()
Gets the building manager's settlement.

Returns:
settlement

addBuilding

public void addBuilding(Building newBuilding)
Adds a new building to the settlement.

Parameters:
newBuilding - the building to add.

addBuilding

public void addBuilding(java.lang.String buildingType)
                 throws java.lang.Exception
Adds a building of a specific building type to the settlement.

Parameters:
buildingType - the type of building.
Throws:
java.lang.Exception - if error creating or adding building.

getBuildings

public java.util.List<Building> getBuildings()
Gets the settlement's collection of buildings.

Returns:
collection of buildings

getBuildings

public java.util.List<Building> getBuildings(java.lang.String functionName)
Gets the buildings in a settlement that has a given function.

Parameters:
functionName - the name of the building.
Returns:
list of buildings.

getBuildingNum

public int getBuildingNum()
Gets the number of buildings at the settlement.

Returns:
number of buildings

timePassing

public void timePassing(double time)
                 throws java.lang.Exception
Time passing for all buildings.

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

addToRandomBuilding

public static void addToRandomBuilding(Person person,
                                       Settlement settlement)
                                throws BuildingException
Adds a person to a random inhabitable building within a settlement.

Parameters:
person - the person to add.
settlement - the settlement to find a building.
Throws:
BuildingException - if person cannot be added to any building.

addToRandomBuilding

public static void addToRandomBuilding(GroundVehicle vehicle,
                                       Settlement settlement)
                                throws BuildingException
Adds a ground vehicle to a random ground vehicle maintenance building within a settlement.

Parameters:
vehicle - the ground vehicle to add.
settlement - the settlement to find a building.
Throws:
BuildingException - if vehicle cannot be added to any building.

getBuilding

public static Building getBuilding(Person person)
Gets the building a given person is in.

Returns:
building or null if none.

getBuilding

public static Building getBuilding(Vehicle vehicle)
Gets the vehicle maintenance building a given vehicle is in.

Returns:
building or null if none.

getUncrowdedBuildings

public static java.util.List<Building> getUncrowdedBuildings(java.util.List<Building> buildingList)
                                                      throws BuildingException
Gets a list of uncrowded buildings from a given list of buildings with life support.

Parameters:
buildingList - list of buildings with the life support function.
Returns:
list of buildings that are not at or above maximum occupant capacity.
Throws:
BuildingException - if building in list does not have the life support function.

getLeastCrowdedBuildings

public static java.util.List<Building> getLeastCrowdedBuildings(java.util.List<Building> buildingList)
                                                         throws BuildingException
Gets a list of the least crowded buildings from a given list of buildings with life support.

Parameters:
buildingList - list of buildings with the life support function.
Returns:
list of least crowded buildings.
Throws:
BuildingException - if building in list does not have the life support function.

getBestRelationshipBuildings

public static java.util.List<Building> getBestRelationshipBuildings(Person person,
                                                                    java.util.List<Building> buildingList)
                                                             throws BuildingException
Gets a list of buildings with the best relationships for a given person from a list of buildings.

Parameters:
person - the person to check for.
buildingList - the list of buildings to filter.
Returns:
list of buildings with the best relationships.
Throws:
BuildingException - if building in list does not have the life support function.if building in list does not have the life support function.

getNonMalfunctioningBuildings

public static java.util.List<Building> getNonMalfunctioningBuildings(java.util.List<Building> buildingList)
Gets a list of buildings that don't have any malfunctions from a list of buildings.

Parameters:
buildingList - the list of buildings.
Returns:
list of buildings without malfunctions.

addPersonToBuilding

public static void addPersonToBuilding(Person person,
                                       Building building)
                                throws BuildingException
Adds the person to the building if possible.

Parameters:
person - the person to add.
building - the building to add the person to.
Throws:
BuildingException - if person could not be added to the building.