Package net.sf.freecol.common.model
Class ProductionCache
- java.lang.Object
-
- net.sf.freecol.common.model.ProductionCache
-
public class ProductionCache extends java.lang.ObjectTheProductionCacheis 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
Fields Modifier and Type Field Description private ColonycolonyThe colony whose production is being cached.private java.util.Set<GoodsType>goodsUsedA set of the goods used by the colony.private TypeCountMap<GoodsType>netProductionA map of net production by goods type.private java.util.Map<java.lang.Object,ProductionInfo>productionAndConsumptionA map of production info for various producers and consumers.private booleanupToDateFlag to indicate whether the cache is up to date, or not and needsupdate()to be called.
-
Constructor Summary
Constructors Constructor Description ProductionCache(Colony colony)Creates a newProductionCacheinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intgetGoodsCount(GoodsType type)Returns the number of goods of the given type stored in the colony.intgetNetProductionOf(GoodsType type)Returns the net production, that is the total production minus the total consumption, of the given GoodsType.ProductionInfogetProductionInfo(java.lang.Object object)TypeCountMap<GoodsType>getProductionMap()Gets a copy of the current production state.voidinvalidate()Invalidates the production cache.voidinvalidate(GoodsType goodsType)Invalidates the production cache if it produces or consumes the given GoodsType.booleanisConsuming(GoodsType goodsType)Does this production cache contain consumption of a goods type?booleanisProducing(GoodsType goodsType)Does this production cache contain production of a goods type?private voidreallyUpdate()Really update everything.private voidupdate()Updates all data structures.
-
-
-
Field Detail
-
colony
private final 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 final TypeCountMap<GoodsType> netProduction
A map of net production by goods type.
-
productionAndConsumption
private final java.util.Map<java.lang.Object,ProductionInfo> productionAndConsumption
A map of production info for various producers and consumers.
-
goodsUsed
private final java.util.Set<GoodsType> goodsUsed
A set of the goods used by the colony.
-
upToDate
private boolean upToDate
Flag to indicate whether the cache is up to date, or not and needsupdate()to be called. Synchronize access to this variable.
-
-
Constructor Detail
-
ProductionCache
public ProductionCache(Colony colony)
Creates a newProductionCacheinstance.- Parameters:
colony- aColonyvalue
-
-
Method Detail
-
update
private void update()
Updates all data structures. Front end for reallyUpdate, split out to keep the wrapping of upToDate distinct, and to make reallyUpdate visible when profiling.
-
reallyUpdate
private void reallyUpdate()
Really update everything. For now, there is a hard assumption that ColonyTiles do not consume but Buildings do. One day we may want to generalize this, which will require processing the goods types in an order sorted by the requirement dependencies. But not yet. This assumption is made explicit by getting the ProductionInfo from ColonyTiles with the simple getBasicProductionInfo() routine, but from Buildings with getAdjustedProductionInfo() which takes account of the input and output goods levels. FIXME: Ideally these should be unified into a WorkLocation.getProductionInfo with the Building-form arguments.
-
getGoodsCount
private int getGoodsCount(GoodsType type)
Returns the number of goods of the given type stored in the colony.- Parameters:
type- aGoodsTypevalue- Returns:
- an
intvalue
-
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 newFoundingFatheris 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- aGoodsTypevalue
-
isProducing
public boolean isProducing(GoodsType goodsType)
Does this production cache contain production of a goods type?- Parameters:
goodsType- TheGoodsTypeto check.- Returns:
- True if there is a production entry for the given type.
-
isConsuming
public boolean isConsuming(GoodsType goodsType)
Does this production cache contain consumption of a goods type?- Parameters:
goodsType- TheGoodsTypeto check.- Returns:
- True if there is a consumption entry for the given type.
-
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- aGoodsTypevalue- Returns:
- an
intvalue
-
getProductionInfo
public ProductionInfo getProductionInfo(java.lang.Object object)
- Parameters:
object- anObjectvalue- Returns:
- a
ProductionInfovalue
-
getProductionMap
public TypeCountMap<GoodsType> getProductionMap()
Gets a copy of the current production state.- Returns:
- A copy of the current production state.
-
-