net.sf.freecol.common.model
Class ProductionCache

java.lang.Object
  extended by net.sf.freecol.common.model.ProductionCache

public class ProductionCache
extends java.lang.Object

The ProductionCache is contains all relevant information about the production and consumption of the colony. This includes the production of all colony tiles and buildings, as well as the consumption of all units, buildings and build queues.


Field Summary
private  Colony colony
          The colony whose production is being cached.
private  java.util.Set<GoodsType> goodsUsed
           
private  TypeCountMap<GoodsType> netProduction
           
private  java.util.Map<java.lang.Object,ProductionInfo> productionAndConsumption
           
private  boolean upToDate
           
 
Constructor Summary
ProductionCache(Colony colony)
          Creates a new ProductionCache instance.
 
Method Summary
private  int getGoodsCount(GoodsType type)
          Returns the number of goods of the given type stored in the colony.
 int getNetProductionOf(GoodsType type)
          Returns the net production, that is the total production minus the total consumption, of the given GoodsType.
 ProductionInfo getProductionInfo(java.lang.Object object)
          Returns the ProductionInfo for the given WorkLocation or Consumer.
 TypeCountMap<GoodsType> getProductionMap()
          Gets a copy of the current production state.
 void invalidate()
          Invalidates the production cache.
 void invalidate(GoodsType goodsType)
          Invalidates the production cache if it produces or consumes the given GoodsType.
private  void update()
          Updates all data structures.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colony

private Colony colony
The colony whose production is being cached. The goods stored in the colony may need to be considered in order to prevent excess production.


netProduction

private TypeCountMap<GoodsType> netProduction

productionAndConsumption

private java.util.Map<java.lang.Object,ProductionInfo> productionAndConsumption

goodsUsed

private java.util.Set<GoodsType> goodsUsed

upToDate

private boolean upToDate
Constructor Detail

ProductionCache

public ProductionCache(Colony colony)
Creates a new ProductionCache instance.

Parameters:
colony - a Colony value
Method Detail

update

private void update()
Updates all data structures. The method has no side effects.


getGoodsCount

private int getGoodsCount(GoodsType type)
Returns the number of goods of the given type stored in the colony.

Parameters:
type - a GoodsType value
Returns:
an int value

invalidate

public void invalidate()
Invalidates the production cache. This method needs to be called whenever global production modifiers change. This might be the case when a new FoundingFather is added, or when the colony's production bonus changes.


invalidate

public void invalidate(GoodsType goodsType)
Invalidates the production cache if it produces or consumes the given GoodsType. This method needs to be called whenever goods are added to or removed from the colony.

Parameters:
goodsType - a GoodsType value

getNetProductionOf

public int getNetProductionOf(GoodsType type)
Returns the net production, that is the total production minus the total consumption, of the given GoodsType.

Parameters:
type - a GoodsType value
Returns:
an int value

getProductionInfo

public ProductionInfo getProductionInfo(java.lang.Object object)
Returns the ProductionInfo for the given WorkLocation or Consumer.

Parameters:
object - an Object value
Returns:
a ProductionInfo value

getProductionMap

public TypeCountMap<GoodsType> getProductionMap()
Gets a copy of the current production state.

Returns:
A copy of the current production state.