org.mars_sim.msp.simulation
Class Inventory

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

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

The Inventory class represents what a unit contains in terms of resources and other units. It has methods for adding, removing and querying what the unit contains.

See Also:
Serialized Form

Field Summary
static java.lang.String INVENTORY_RESOURCE_EVENT
           
static java.lang.String INVENTORY_RETRIEVING_UNIT_EVENT
           
static java.lang.String INVENTORY_STORING_UNIT_EVENT
           
 
Constructor Summary
Inventory(Unit owner)
          Constructor
 
Method Summary
 void addAmountResourcePhaseCapacity(Phase phase, double capacity)
          Adds capacity for a resource phase.
 void addAmountResourceTypeCapacity(AmountResource resource, double capacity)
          Adds capacity for a resource type.
 void addGeneralCapacity(double capacity)
          Adds a capacity to general capacity.
 boolean canStoreUnit(Unit unit)
          Checks if a unit can be stored.
 Inventory clone(Unit owner)
          Creates a clone of this inventory (not including the inventory contents).
 boolean containsUnit(Unit unit)
          Checks if a unit is in storage.
 boolean containsUnitClass(java.lang.Class unitClass)
          Checks if any of a given class of unit is in storage.
 java.util.Collection<Unit> findAllUnitsOfClass(java.lang.Class unitClass)
          Finds all of the units of a class in storage.
 int findNumEmptyUnitsOfClass(java.lang.Class unitClass)
          Finds the number of units of a class that are contained in storage and have an empty inventory.
 int findNumUnitsOfClass(java.lang.Class unitClass)
          Finds the number of units of a class that are contained in storage.
 Unit findUnitOfClass(java.lang.Class unitClass)
          Finds a unit of a given class in storage.
 java.util.Set<AmountResource> getAllAmountResourcesStored()
          Gets all of the amount resources stored.
 java.util.Set<ItemResource> getAllItemResourcesStored()
          Gets a set of all the item resources in storage.
 double getAmountResourceCapacity(AmountResource resource)
          Gets the storage capacity for a resource.
 double getAmountResourceRemainingCapacity(AmountResource resource, boolean useContainedUnits)
          Gets the remaining capacity available for a resource.
 double getAmountResourceStored(AmountResource resource)
          Gets the amount of a resource stored.
 java.util.Collection<Unit> getContainedUnits()
          Gets a collection of all the stored units.
 double getGeneralCapacity()
          Gets the general capacity.
 double getGeneralStoredMass()
          Gets the mass stored in general capacity.
 int getItemResourceNum(ItemResource resource)
          Gets the number of an item resource in storage.
 double getRemainingGeneralCapacity()
          Gets the remaining general capacity available.
 double getTotalInventoryMass()
          Gets the total mass stored in inventory.
 double getUnitTotalMass()
          Gets the total unit mass in storage.
 boolean hasAmountResourceCapacity(AmountResource resource)
          Checks if storage has capacity for a resource.
 boolean hasAmountResourceCapacity(AmountResource resource, double amount)
          Checks if storage has capacity for an amount of a resource.
 boolean hasItemResource(ItemResource resource)
          Checks if storage has an item resource.
 boolean isEmpty()
          Checks if inventory is empty.
 void retrieveAmountResource(AmountResource resource, double amount)
          Retrieves an amount of a resource from storage.
 void retrieveItemResources(ItemResource resource, int number)
          Retrieves item resources.
 void retrieveUnit(Unit unit)
          Retrieves a unit from storage.
 void setCoordinates(Coordinates newLocation)
          Sets the coordinates of all units in the inventory.
 void storeAmountResource(AmountResource resource, double amount, boolean useContainedUnits)
          Store an amount of a resource.
 void storeItemResources(ItemResource resource, int number)
          Stores item resources.
 void storeUnit(Unit unit)
          Stores a unit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVENTORY_STORING_UNIT_EVENT

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

INVENTORY_RETRIEVING_UNIT_EVENT

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

INVENTORY_RESOURCE_EVENT

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

Inventory

public Inventory(Unit owner)
Constructor

Parameters:
owner - the unit that owns this inventory
Method Detail

addAmountResourceTypeCapacity

public void addAmountResourceTypeCapacity(AmountResource resource,
                                          double capacity)
                                   throws InventoryException
Adds capacity for a resource type.

Parameters:
resource - the resource.
capacity - the capacity amount (kg).
Throws:
InventoryException - if error setting capacity.

addAmountResourcePhaseCapacity

public void addAmountResourcePhaseCapacity(Phase phase,
                                           double capacity)
                                    throws InventoryException
Adds capacity for a resource phase.

Parameters:
phase - the phase
capacity - the capacity amount (kg).
Throws:
InventoryException - if error adding capacity.

hasAmountResourceCapacity

public boolean hasAmountResourceCapacity(AmountResource resource)
                                  throws InventoryException
Checks if storage has capacity for a resource.

Parameters:
resource - the resource.
Returns:
true if storage capacity.
Throws:
InventoryException

hasAmountResourceCapacity

public boolean hasAmountResourceCapacity(AmountResource resource,
                                         double amount)
                                  throws InventoryException
Checks if storage has capacity for an amount of a resource.

Parameters:
resource - the resource.
amount - the amount (kg).
Returns:
true if storage capacity.
Throws:
InventoryException - if error checking capacity.

getAmountResourceCapacity

public double getAmountResourceCapacity(AmountResource resource)
                                 throws InventoryException
Gets the storage capacity for a resource.

Parameters:
resource - the resource.
Returns:
capacity amount (kg).
Throws:
InventoryException - if error determining capacity.

getAmountResourceStored

public double getAmountResourceStored(AmountResource resource)
                               throws InventoryException
Gets the amount of a resource stored.

Parameters:
resource - the resource.
Returns:
stored amount (kg).
Throws:
InventoryException - if error getting amount stored.

getAllAmountResourcesStored

public java.util.Set<AmountResource> getAllAmountResourcesStored()
                                                          throws InventoryException
Gets all of the amount resources stored.

Returns:
set of amount resources.
Throws:
InventoryException - if error getting all amount resources.

getAmountResourceRemainingCapacity

public double getAmountResourceRemainingCapacity(AmountResource resource,
                                                 boolean useContainedUnits)
                                          throws InventoryException
Gets the remaining capacity available for a resource.

Parameters:
resource - the resource.
useContainedUnits - should the capacity of contained units be added?
Returns:
remaining capacity amount (kg). throws InventoryException if error getting remaining capacity.
Throws:
InventoryException

storeAmountResource

public void storeAmountResource(AmountResource resource,
                                double amount,
                                boolean useContainedUnits)
                         throws InventoryException
Store an amount of a resource.

Parameters:
resource - the resource.
amount - the amount (kg).
Throws:
InventoryException - if error storing resource.

retrieveAmountResource

public void retrieveAmountResource(AmountResource resource,
                                   double amount)
                            throws InventoryException
Retrieves an amount of a resource from storage.

Parameters:
resource - the resource.
amount - the amount (kg).
Throws:
InventoryException - if error retrieving resource.

addGeneralCapacity

public void addGeneralCapacity(double capacity)
Adds a capacity to general capacity.

Parameters:
capacity - amount capacity (kg).

getGeneralCapacity

public double getGeneralCapacity()
Gets the general capacity.

Returns:
amount capacity (kg).

getGeneralStoredMass

public double getGeneralStoredMass()
                            throws InventoryException
Gets the mass stored in general capacity.

Returns:
stored mass (kg).
Throws:
InventoryException - if error getting stored mass.

getRemainingGeneralCapacity

public double getRemainingGeneralCapacity()
                                   throws InventoryException
Gets the remaining general capacity available.

Returns:
amount capacity (kg).
Throws:
InventoryException - if error getting remaining capacity.

hasItemResource

public boolean hasItemResource(ItemResource resource)
                        throws InventoryException
Checks if storage has an item resource.

Parameters:
resource - the resource.
Returns:
true if has resource.
Throws:
InventoryException - if error checking resource.

getItemResourceNum

public int getItemResourceNum(ItemResource resource)
                       throws InventoryException
Gets the number of an item resource in storage.

Parameters:
resource - the resource.
Returns:
number of resources.
Throws:
InventoryException - if error getting item resource.

getAllItemResourcesStored

public java.util.Set<ItemResource> getAllItemResourcesStored()
                                                      throws InventoryException
Gets a set of all the item resources in storage.

Returns:
set of item resources.
Throws:
InventoryException - if error getting all item resources.

storeItemResources

public void storeItemResources(ItemResource resource,
                               int number)
                        throws InventoryException
Stores item resources.

Parameters:
resource - the resource to store.
number - the number of resources to store.
Throws:
InventoryException - if error storing the resources.

retrieveItemResources

public void retrieveItemResources(ItemResource resource,
                                  int number)
                           throws InventoryException
Retrieves item resources.

Parameters:
resource - the resource to retrieve.
number - the number of resources to retrieve.
Throws:
InventoryException - if error retrieving the resources.

getUnitTotalMass

public double getUnitTotalMass()
                        throws InventoryException
Gets the total unit mass in storage.

Returns:
total mass (kg).
Throws:
InventoryException - if error getting mass.

getContainedUnits

public java.util.Collection<Unit> getContainedUnits()
Gets a collection of all the stored units.

Returns:
Collection of all units

containsUnit

public boolean containsUnit(Unit unit)
Checks if a unit is in storage.

Parameters:
unit - the unit.
Returns:
true if unit is in storage.

containsUnitClass

public boolean containsUnitClass(java.lang.Class unitClass)
Checks if any of a given class of unit is in storage.

Parameters:
unitClass - the unit class.
Returns:
if class of unit is in storage.

findUnitOfClass

public Unit findUnitOfClass(java.lang.Class unitClass)
Finds a unit of a given class in storage.

Parameters:
unitClass - the unit class.
Returns:
the instance of the unit class or null if none.

findAllUnitsOfClass

public java.util.Collection<Unit> findAllUnitsOfClass(java.lang.Class unitClass)
Finds all of the units of a class in storage.

Parameters:
unitClass - the unit class.
Returns:
collection of units or empty collection if none.

findNumUnitsOfClass

public int findNumUnitsOfClass(java.lang.Class unitClass)
Finds the number of units of a class that are contained in storage.

Parameters:
unitClass - the unit class.
Returns:
number of units

findNumEmptyUnitsOfClass

public int findNumEmptyUnitsOfClass(java.lang.Class unitClass)
                             throws InventoryException
Finds the number of units of a class that are contained in storage and have an empty inventory.

Parameters:
unitClass - the unit class.
Returns:
number of empty units.
Throws:
InventoryException - if error determining number of units.

canStoreUnit

public boolean canStoreUnit(Unit unit)
                     throws InventoryException
Checks if a unit can be stored.

Parameters:
unit - the unit.
Returns:
true if unit can be added to inventory
Throws:
InventoryException - if error checking unit.

storeUnit

public void storeUnit(Unit unit)
               throws InventoryException
Stores a unit.

Parameters:
unit - the unit
Throws:
InventoryException - if unit could not be stored.

retrieveUnit

public void retrieveUnit(Unit unit)
                  throws InventoryException
Retrieves a unit from storage.

Parameters:
unit - the unit.
Throws:
InventoryException - if unit could not be retrieved.

setCoordinates

public void setCoordinates(Coordinates newLocation)
Sets the coordinates of all units in the inventory.

Parameters:
newLocation - the new coordinate location

getTotalInventoryMass

public double getTotalInventoryMass()
                             throws InventoryException
Gets the total mass stored in inventory.

Returns:
stored mass (kg).
Throws:
InventoryException - if error getting mass.

isEmpty

public boolean isEmpty()
                throws InventoryException
Checks if inventory is empty.

Returns:
true if empty.
Throws:
InventoryException - if error checking inventory.

clone

public Inventory clone(Unit owner)
                throws InventoryException
Creates a clone of this inventory (not including the inventory contents).

Parameters:
owner - the unit owner of the inventory (or null).
Returns:
inventory clone.
Throws:
InventoryException - if error creating inventory clone.