net.sf.freecol.server.ai
Class ProductionCache

java.lang.Object
  extended by net.sf.freecol.server.ai.ProductionCache

public class ProductionCache
extends java.lang.Object

The production cache is intended to record all possible combinations of units producing goods in a colony's work locations. These entries are sorted, allowing fast retrieval of the most efficient way to produce a given type of goods.


Nested Class Summary
 class ProductionCache.Entry
          An Entry in the production cache represents a single unit producing goods in a certain work location.
 
Field Summary
private  java.util.List<ProductionCache.Entry> assigned
          The assigned entries.
private  Colony colony
           
private  java.util.Set<ColonyTile> colonyTiles
          The available colony tiles.
private static java.util.Comparator<ProductionCache.Entry> defaultComparator
          Compares entries by production.
private  java.util.Map<GoodsType,java.util.List<ProductionCache.Entry>> entries
          Sorted entries per goods type.
private static java.util.Comparator<ProductionCache.Entry> marketValueComparator
          Compares entries by market value of production.
private  java.util.List<ProductionCache.Entry> reserved
          The reserved entries.
private  int unitCount
          The number of units available.
private  TypeCountMap<BuildingType> unitCounts
          The number of Units in various buildings.
private  java.util.Set<Unit> units
          The units available in the colony.
 
Constructor Summary
ProductionCache(Colony colony)
           
 
Method Summary
 void assign(ProductionCache.Entry entry)
          Assigns an entry.
private  java.util.List<ProductionCache.Entry> createEntries(GoodsType goodsType)
           
 int decrementUnitCount(BuildingType buildingType)
           
 java.util.List<ProductionCache.Entry> getAssigned()
           
 java.util.List<ProductionCache.Entry> getEntries(GoodsType goodsType)
           
 java.util.List<ProductionCache.Entry> getEntries(java.util.List<GoodsType> goodsTypes)
           
 java.util.List<ProductionCache.Entry> getEntries(java.util.List<GoodsType> goodsTypes, boolean useMarketValues)
           
 java.util.List<ProductionCache.Entry> getReserved()
           
 int getUnitCount()
           
 int getUnitCount(BuildingType buildingType)
           
 java.util.Set<Unit> getUnits()
           
static java.util.List<ProductionCache.Entry> removeEntries(Unit unit, WorkLocation workLocation, java.util.List<ProductionCache.Entry> entryList)
          Removes all entries that refer to the unit or work location given from the given list of entries and returns them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colony

private final Colony colony

units

private final java.util.Set<Unit> units
The units available in the colony.


colonyTiles

private final java.util.Set<ColonyTile> colonyTiles
The available colony tiles.


entries

private final java.util.Map<GoodsType,java.util.List<ProductionCache.Entry>> entries
Sorted entries per goods type.


assigned

private final java.util.List<ProductionCache.Entry> assigned
The assigned entries.


reserved

private final java.util.List<ProductionCache.Entry> reserved
The reserved entries.


defaultComparator

private static final java.util.Comparator<ProductionCache.Entry> defaultComparator
Compares entries by production.


marketValueComparator

private static final java.util.Comparator<ProductionCache.Entry> marketValueComparator
Compares entries by market value of production.


unitCount

private int unitCount
The number of units available.


unitCounts

private TypeCountMap<BuildingType> unitCounts
The number of Units in various buildings.

Constructor Detail

ProductionCache

public ProductionCache(Colony colony)
Method Detail

createEntries

private java.util.List<ProductionCache.Entry> createEntries(GoodsType goodsType)

getUnits

public java.util.Set<Unit> getUnits()

getUnitCount

public int getUnitCount()

getUnitCount

public int getUnitCount(BuildingType buildingType)

decrementUnitCount

public int decrementUnitCount(BuildingType buildingType)

getAssigned

public java.util.List<ProductionCache.Entry> getAssigned()

getReserved

public java.util.List<ProductionCache.Entry> getReserved()

getEntries

public java.util.List<ProductionCache.Entry> getEntries(GoodsType goodsType)

getEntries

public java.util.List<ProductionCache.Entry> getEntries(java.util.List<GoodsType> goodsTypes)

getEntries

public java.util.List<ProductionCache.Entry> getEntries(java.util.List<GoodsType> goodsTypes,
                                                        boolean useMarketValues)

assign

public void assign(ProductionCache.Entry entry)
Assigns an entry. All conflicting entries, i.e. entries that refer to the same unit or colony tile, are removed from the cache.

Parameters:
entry - an Entry value

removeEntries

public static java.util.List<ProductionCache.Entry> removeEntries(Unit unit,
                                                                  WorkLocation workLocation,
                                                                  java.util.List<ProductionCache.Entry> entryList)
Removes all entries that refer to the unit or work location given from the given list of entries and returns them.

Parameters:
unit - a Unit
workLocation - a WorkLocation
entryList - a List of Entrys
Returns:
the Entrys removed