org.mars_sim.msp.core
Class Inventory

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

public class Inventory
extends Object
implements 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 String INVENTORY_RESOURCE_EVENT
           
static String INVENTORY_RETRIEVING_UNIT_EVENT
           
static 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, boolean allowDirty)
          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(Class<? extends Unit> unitClass)
          Checks if any of a given class of unit is in storage.
 void destroy()
          Prepare object for garbage collection.
 Collection<Unit> findAllUnitsOfClass(Class<? extends Unit> unitClass)
          Finds all of the units of a class in storage.
 int findNumEmptyUnitsOfClass(Class<? extends Unit> unitClass, boolean allowDirty)
          Finds the number of units of a class that are contained in storage and have an empty inventory.
 int findNumUnitsOfClass(Class<? extends Unit> unitClass)
          Finds the number of units of a class that are contained in storage.
 Unit findUnitOfClass(Class<? extends Unit> unitClass)
          Finds a unit of a given class in storage.
 Set<AmountResource> getAllAmountResourcesStored(boolean allowDirty)
          Gets all of the amount resources stored.
 Set<ItemResource> getAllItemResourcesStored()
          Gets a set of all the item resources in storage.
 double getAmountResourceCapacity(AmountResource resource, boolean allowDirty)
          Gets the storage capacity for a resource.
 double getAmountResourceRemainingCapacity(AmountResource resource, boolean useContainedUnits, boolean allowDirty)
          Gets the remaining capacity available for a resource.
 double getAmountResourceStored(AmountResource resource, boolean allowDirty)
          Gets the amount of a resource stored.
 Collection<Unit> getContainedUnits()
          Gets a collection of all the stored units.
 double getGeneralCapacity()
          Gets the general capacity.
 double getGeneralStoredMass(boolean allowDirty)
          Gets the mass stored in general capacity.
 int getItemResourceNum(ItemResource resource)
          Gets the number of an item resource in storage.
 double getRemainingGeneralCapacity(boolean allowDirty)
          Gets the remaining general capacity available.
 double getTotalInventoryMass(boolean allowDirty)
          Gets the total mass stored in inventory.
 double getUnitTotalMass(boolean allowDirty)
          Gets the total unit mass in storage.
 boolean hasAmountResourceCapacity(AmountResource resource, boolean allowDirty)
          Checks if storage has capacity for a resource.
 boolean hasAmountResourceCapacity(AmountResource resource, double amount, boolean allowDirty)
          Checks if storage has capacity for an amount of a resource.
 boolean hasItemResource(ItemResource resource)
          Checks if storage has an item resource.
 boolean isEmpty(boolean allowDirty)
          Checks if inventory is empty.
 void removeAmountResourceTypeCapacity(AmountResource resource, double capacity)
          Removes capacity for a resource type.
 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 String INVENTORY_STORING_UNIT_EVENT
See Also:
Constant Field Values

INVENTORY_RETRIEVING_UNIT_EVENT

public static final String INVENTORY_RETRIEVING_UNIT_EVENT
See Also:
Constant Field Values

INVENTORY_RESOURCE_EVENT

public static final 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)
Adds capacity for a resource type.

Parameters:
resource - the resource.
capacity - the capacity amount (kg).

removeAmountResourceTypeCapacity

public void removeAmountResourceTypeCapacity(AmountResource resource,
                                             double capacity)
Removes capacity for a resource type.

Parameters:
resource - the resource
capacity - the capacity amount (kg).

addAmountResourcePhaseCapacity

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

Parameters:
phase - the phase
capacity - the capacity amount (kg).

hasAmountResourceCapacity

public boolean hasAmountResourceCapacity(AmountResource resource,
                                         boolean allowDirty)
Checks if storage has capacity for a resource.

Parameters:
resource - the resource.
allowDirty - will allow dirty (possibly out of date) results.
Returns:
true if storage capacity.

hasAmountResourceCapacity

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

Parameters:
resource - the resource.
amount - the amount (kg).
allowDirty - will allow dirty (possibly out of date) results.
Returns:
true if storage capacity.

getAmountResourceCapacity

public double getAmountResourceCapacity(AmountResource resource,
                                        boolean allowDirty)
Gets the storage capacity for a resource.

Parameters:
resource - the resource.
allowDirty - will allow dirty (possibly out of date) results.
Returns:
capacity amount (kg).

getAmountResourceStored

public double getAmountResourceStored(AmountResource resource,
                                      boolean allowDirty)
Gets the amount of a resource stored.

Parameters:
resource - the resource.
allowDirty - will allow dirty (possibly out of date) results.
Returns:
stored amount (kg).

getAllAmountResourcesStored

public Set<AmountResource> getAllAmountResourcesStored(boolean allowDirty)
Gets all of the amount resources stored.

Parameters:
allowDirty - will allow dirty (possibly out of date) results.
Returns:
set of amount resources.

getAmountResourceRemainingCapacity

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

Parameters:
resource - the resource.
useContainedUnits - should the capacity of contained units be added?
allowDirty - will allow dirty (possibly out of date) results.
Returns:
remaining capacity amount (kg).

storeAmountResource

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

Parameters:
resource - the resource.
amount - the amount (kg).

retrieveAmountResource

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

Parameters:
resource - the resource.
amount - the amount (kg).

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(boolean allowDirty)
Gets the mass stored in general capacity.

Parameters:
allowDirty - will allow dirty (possibly out of date) results.
Returns:
stored mass (kg).

getRemainingGeneralCapacity

public double getRemainingGeneralCapacity(boolean allowDirty)
Gets the remaining general capacity available.

Parameters:
allowDirty - will allow dirty (possibly out of date) results.
Returns:
amount capacity (kg).

hasItemResource

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

Parameters:
resource - the resource.
Returns:
true if has resource.

getItemResourceNum

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

Parameters:
resource - the resource.
Returns:
number of resources.

getAllItemResourcesStored

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

Returns:
set of item resources.

storeItemResources

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

Parameters:
resource - the resource to store.
number - the number of resources to store.

retrieveItemResources

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

Parameters:
resource - the resource to retrieve.
number - the number of resources to retrieve.

getUnitTotalMass

public double getUnitTotalMass(boolean allowDirty)
Gets the total unit mass in storage.

Parameters:
allowDirty - will allow dirty (possibly out of date) results.
Returns:
total mass (kg).

getContainedUnits

public 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(Class<? extends Unit> 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(Class<? extends Unit> 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 Collection<Unit> findAllUnitsOfClass(Class<? extends Unit> 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(Class<? extends Unit> 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(Class<? extends Unit> unitClass,
                                    boolean allowDirty)
Finds the number of units of a class that are contained in storage and have an empty inventory.

Parameters:
unitClass - the unit class.
allowDirty - will allow dirty (possibly out of date) results.
Returns:
number of empty units.

canStoreUnit

public boolean canStoreUnit(Unit unit,
                            boolean allowDirty)
Checks if a unit can be stored.

Parameters:
unit - the unit.
allowDirty - will allow dirty (possibly out of date) results.
Returns:
true if unit can be added to inventory

storeUnit

public void storeUnit(Unit unit)
Stores a unit.

Parameters:
unit - the unit

retrieveUnit

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

Parameters:
unit - the unit.

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(boolean allowDirty)
Gets the total mass stored in inventory.

Parameters:
allowDirty - will allow dirty (possibly out of date) results.
Returns:
stored mass (kg).

isEmpty

public boolean isEmpty(boolean allowDirty)
Checks if inventory is empty.

Parameters:
allowDirty - will allow dirty (possibly out of date) results.
Returns:
true if empty.

clone

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

Parameters:
owner - the unit owner of the inventory (or null).
Returns:
inventory clone.

destroy

public void destroy()
Prepare object for garbage collection.



Copyright © 2009-2013. All Rights Reserved.