Package net.sf.freecol.common.model
Class ProductionCache
- java.lang.Object
-
- net.sf.freecol.common.model.ProductionCache
-
public class ProductionCache extends java.lang.Object
TheProductionCache
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
Fields Modifier and Type Field Description private Colony
colony
The colony whose production is being cached.private java.util.Set<GoodsType>
goodsUsed
A set of the goods used by the colony.private TypeCountMap<GoodsType>
netProduction
A map of net production by goods type.private java.util.Map<java.lang.Object,ProductionInfo>
productionAndConsumption
A map of production info for various producers and consumers.private boolean
upToDate
Flag 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 newProductionCache
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
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.boolean
isConsuming(GoodsType goodsType)
Does this production cache contain consumption of a goods type?boolean
isProducing(GoodsType goodsType)
Does this production cache contain production of a goods type?private void
reallyUpdate()
Really update everything.private void
update()
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 newProductionCache
instance.- Parameters:
colony
- aColony
value
-
-
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
- aGoodsType
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 newFoundingFather
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
- aGoodsType
value
-
isProducing
public boolean isProducing(GoodsType goodsType)
Does this production cache contain production of a goods type?- Parameters:
goodsType
- TheGoodsType
to 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
- TheGoodsType
to 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
- aGoodsType
value- Returns:
- an
int
value
-
getProductionInfo
public ProductionInfo getProductionInfo(java.lang.Object object)
- Parameters:
object
- anObject
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.
-
-