ch.sahits.game.openpatrician.model.impl
Class WareHolding

java.lang.Object
  extended by ch.sahits.game.openpatrician.model.impl.WareHolding
Direct Known Subclasses:
City, TradingOffice

public class WareHolding
extends Object

This class represents an entity that can hold wares which can be moved

Author:
Andi Hotz, (c) Sahits GmbH, 2011 Created on Dec 17, 2011

Field Summary
(package private)  HashMap<IWare,AmountablePrice> wares
          Store the amount of wares in the city in the ware specific sizes
 
Constructor Summary
WareHolding()
           
 
Method Summary
protected  void addNewWare(IWare ware, int amount)
          Add a new ware to the wares list
protected  int computeAVGPrice(IWare ware, int amount)
          Compute the average price for ware that is to be purchased in the specified amount.
protected  boolean containsWare(IWare ware)
          Check if there is an amountable object for this ware
 AmountablePrice getWare(IWare ware)
          Retrieve the AmountablePrice of the ware as it is stored in the holding
 int move(IWare ware, int amount, IPlayer player)
          Move ware into this holding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wares

final HashMap<IWare,AmountablePrice> wares
Store the amount of wares in the city in the ware specific sizes

Constructor Detail

WareHolding

public WareHolding()
Method Detail

addNewWare

protected void addNewWare(IWare ware,
                          int amount)
Add a new ware to the wares list

Parameters:
ware -

getWare

public AmountablePrice getWare(IWare ware)
Retrieve the AmountablePrice of the ware as it is stored in the holding

Parameters:
ware - to be retrieved
Returns:
AmountablePrice object

move

public int move(IWare ware,
                int amount,
                IPlayer player)
Move ware into this holding. The player may be null and is not used in this base implementation, but subclasses may be interested for statistical reasons. This method is thread save.

Parameters:
ware - to be moved
amount - of the ware that is moved
player - that initiates the moving, may be null, e.g. if the moving is initiated by a city
Returns:
the effective amount that was moved. The amount may be positive if something was added, negative if the ware was removed from the holding or zero if nothing was moved.

containsWare

protected final boolean containsWare(IWare ware)
Check if there is an amountable object for this ware

Parameters:
ware -
Returns:

computeAVGPrice

protected int computeAVGPrice(IWare ware,
                              int amount)
Compute the average price for ware that is to be purchased in the specified amount. The additional variable of the available amount is supplied by getWare(IWare). Subclasses may override this method.

Parameters:
ware - for which the average price is to be computed
amount - amount that is bought
Returns:


Copyright © 2011-2012 Sahits GmbH. All Rights Reserved.