rails.game
Class Portfolio

java.lang.Object
  extended by rails.game.Portfolio
All Implemented Interfaces:
MoveableHolder, TokenHolder

public class Portfolio
extends java.lang.Object
implements TokenHolder, MoveableHolder

Author:
Erik

Field Summary
protected  java.util.List<PublicCertificateI> certificates
          Owned public company certificates
protected  java.util.Map<java.lang.String,java.util.List<PublicCertificateI>> certPerCompany
          Owned public company certificates, organised in a HashMap per company
protected  java.util.Map<java.lang.String,java.util.List<PublicCertificateI>> certsPerType
          Owned public company certificates, organised in a HashMap per unique certificate type (company, share percentage, presidency).
static java.lang.String IPO_NAME
          Specific portfolio names
protected static org.apache.log4j.Logger log
           
protected  java.lang.String name
          Name of portfolio
protected  CashHolder owner
          Who owns the portfolio
static java.lang.String POOL_NAME
           
protected  java.util.List<PrivateCompanyI> privateCompanies
          Owned private companies
protected  PrivatesModel privatesOwnedModel
           
static java.lang.String SCRAPHEAP_NAME
           
protected  java.util.Map<PublicCompanyI,ShareModel> shareModelPerCompany
          Share model per company
protected  java.util.List<SpecialPropertyI> specialProperties
          Private-independent special properties.
protected  java.util.List<TokenI> tokens
          Owned tokens
protected  java.util.List<TrainI> trains
          Owned trains
protected  TrainsModel trainsModel
           
protected  java.util.Map<TrainTypeI,java.util.List<TrainI>> trainsPerType
           
static java.lang.String UNAVAILABLE_NAME
           
protected  java.lang.String uniqueName
          Unique name (including owner class name)
 
Constructor Summary
Portfolio(java.lang.String name, CashHolder holder)
           
 
Method Summary
 void addCertificate(PublicCertificateI certificate)
           
 void addCertificate(PublicCertificateI certificate, int[] position)
           
 boolean addObject(Moveable object, int[] position)
          Add an object.
 void addPrivate(PrivateCompanyI privateCompany, int position)
           
 boolean addSpecialProperty(SpecialPropertyI property, int position)
          Add a special property.
 boolean addToken(TokenI token, int position)
           
 void addTrain(TrainI train)
           
 void addTrain(TrainI train, int[] position)
           
 void buyTrain(TrainI train, int price)
           
 void discardTrain(TrainI train)
           
 PublicCertificateI findCertificate(PublicCompanyI company, boolean president)
          Find a certificate for a given company.
 PublicCertificateI findCertificate(PublicCompanyI company, int shares, boolean president)
          Find a certificate for a given company.
 java.util.List<SpecialPropertyI> getAllSpecialProperties()
           
 float getCertificateCount()
          Get the number of certificates that count against the certificate limit
 java.util.List<PublicCertificateI> getCertificates()
           
 java.util.List<PublicCertificateI> getCertificatesPerCompany(java.lang.String compName)
           
 PublicCertificateI getCertOfType(java.lang.String certTypeId)
           
 java.util.List<PublicCertificateI> getCertsOfType(java.lang.String certTypeId)
           
 java.util.Map<java.lang.String,java.util.List<PublicCertificateI>> getCertsPerCompanyMap()
           
 java.util.Map<java.lang.String,java.util.List<PublicCertificateI>> getCertsPerType()
           
 int[] getListIndex(Moveable object)
           
 java.lang.String getName()
          Each station must have a name, which includes the tile Id (if on a tile) or the hex name (if on a MapHex).
 int getNumberOfTrains()
           
 CashHolder getOwner()
           
 java.util.List<SpecialPropertyI> getPersistentSpecialProperties()
           
 java.util.List<PrivateCompanyI> getPrivateCompanies()
           
 ModelObject getPrivatesOwnedModel()
           
 int getShare(PublicCompanyI company)
          Returns percentage that a portfolio contains of one company.
 ShareModel getShareModel(PublicCompanyI company)
           
<T extends SpecialPropertyI>
java.util.List<T>
getSpecialProperties(java.lang.Class<T> clazz, boolean includeExercised)
           
 java.util.List<TokenI> getTokens()
           
 java.util.List<TrainI> getTrainList()
           
 TrainI getTrainOfType(TrainTypeI type)
           
 ModelObject getTrainsModel()
           
 TrainI[] getTrainsPerType(TrainTypeI type)
           
 java.lang.String getUniqueName()
          Get unique name (prefixed by the owners class type, to avoid Bank, Player and Company namespace clashes).
 java.util.List<TrainI> getUniqueTrains()
          Returns one train of any type held
 boolean hasSpecialProperties()
          Do we have any special properties?
 boolean hasTokens()
          Do we have any tokens?
 java.lang.String makeAbbreviatedListOfTrains()
          Make an abbreviated list of trains, like "2(6) 3(5)" etc, to show in the IPO.
 java.lang.String makeFullListOfTrains()
          Make a full list of trains, like "2 2 3 3", to show in any field describing train possessions, except the IPO.
 int ownsCertificates(PublicCompanyI company, int unit, boolean president)
           
 void removeCertificate(PublicCertificateI certificate)
           
 boolean removeObject(Moveable object)
          Remove an object.
 boolean removePrivate(PrivateCompanyI privateCompany)
           
 boolean removeSpecialProperty(SpecialPropertyI property)
          Remove a special property.
 boolean removeToken(TokenI token)
          Remove a token.
 void removeTrain(TrainI train)
           
 void rustObsoleteTrains()
           
 void setOwner(CashHolder owner)
           
 java.util.List<PublicCertificateI> swapPresidentCertificate(PublicCompanyI company, Portfolio other)
          Swap this Portfolio's President certificate for common shares in another Portfolio.
 void transferAssetsFrom(Portfolio otherPortfolio)
           
 void updateTrainsModel()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

privateCompanies

protected java.util.List<PrivateCompanyI> privateCompanies
Owned private companies


privatesOwnedModel

protected PrivatesModel privatesOwnedModel

certificates

protected java.util.List<PublicCertificateI> certificates
Owned public company certificates


certPerCompany

protected java.util.Map<java.lang.String,java.util.List<PublicCertificateI>> certPerCompany
Owned public company certificates, organised in a HashMap per company


certsPerType

protected java.util.Map<java.lang.String,java.util.List<PublicCertificateI>> certsPerType
Owned public company certificates, organised in a HashMap per unique certificate type (company, share percentage, presidency). The key is the certificate type id (see PublicCertificate), the value is the number of certificates of that type.


shareModelPerCompany

protected java.util.Map<PublicCompanyI,ShareModel> shareModelPerCompany
Share model per company


trains

protected java.util.List<TrainI> trains
Owned trains


trainsPerType

protected java.util.Map<TrainTypeI,java.util.List<TrainI>> trainsPerType

trainsModel

protected TrainsModel trainsModel

tokens

protected java.util.List<TokenI> tokens
Owned tokens


specialProperties

protected java.util.List<SpecialPropertyI> specialProperties
Private-independent special properties. When moved here, a special property no longer depends on the private company being alive. Example: 18AL named train tokens.


owner

protected CashHolder owner
Who owns the portfolio


name

protected java.lang.String name
Name of portfolio


uniqueName

protected java.lang.String uniqueName
Unique name (including owner class name)


IPO_NAME

public static final java.lang.String IPO_NAME
Specific portfolio names

See Also:
Constant Field Values

POOL_NAME

public static final java.lang.String POOL_NAME
See Also:
Constant Field Values

SCRAPHEAP_NAME

public static final java.lang.String SCRAPHEAP_NAME
See Also:
Constant Field Values

UNAVAILABLE_NAME

public static final java.lang.String UNAVAILABLE_NAME
See Also:
Constant Field Values

log

protected static org.apache.log4j.Logger log
Constructor Detail

Portfolio

public Portfolio(java.lang.String name,
                 CashHolder holder)
Method Detail

transferAssetsFrom

public void transferAssetsFrom(Portfolio otherPortfolio)

addPrivate

public void addPrivate(PrivateCompanyI privateCompany,
                       int position)

addCertificate

public void addCertificate(PublicCertificateI certificate)

addCertificate

public void addCertificate(PublicCertificateI certificate,
                           int[] position)

removePrivate

public boolean removePrivate(PrivateCompanyI privateCompany)

removeCertificate

public void removeCertificate(PublicCertificateI certificate)

getShareModel

public ShareModel getShareModel(PublicCompanyI company)

getPrivateCompanies

public java.util.List<PrivateCompanyI> getPrivateCompanies()

getCertificates

public java.util.List<PublicCertificateI> getCertificates()

getCertificateCount

public float getCertificateCount()
Get the number of certificates that count against the certificate limit


getCertsPerCompanyMap

public java.util.Map<java.lang.String,java.util.List<PublicCertificateI>> getCertsPerCompanyMap()

getCertificatesPerCompany

public java.util.List<PublicCertificateI> getCertificatesPerCompany(java.lang.String compName)

findCertificate

public PublicCertificateI findCertificate(PublicCompanyI company,
                                          boolean president)
Find a certificate for a given company.

Parameters:
company - The public company for which a certificate is found.
president - Whether we look for a president or non-president certificate. If there is only one certificate, this parameter has no meaning.
Returns:
The certificate, or null if not found./

findCertificate

public PublicCertificateI findCertificate(PublicCompanyI company,
                                          int shares,
                                          boolean president)
Find a certificate for a given company.


getCertsPerType

public java.util.Map<java.lang.String,java.util.List<PublicCertificateI>> getCertsPerType()

getCertsOfType

public java.util.List<PublicCertificateI> getCertsOfType(java.lang.String certTypeId)

getCertOfType

public PublicCertificateI getCertOfType(java.lang.String certTypeId)

getOwner

public CashHolder getOwner()
Returns:

setOwner

public void setOwner(CashHolder owner)
Parameters:
object -

getName

public java.lang.String getName()
Description copied from interface: TokenHolder
Each station must have a name, which includes the tile Id (if on a tile) or the hex name (if on a MapHex).

Specified by:
getName in interface MoveableHolder
Specified by:
getName in interface TokenHolder
Returns:

getUniqueName

public java.lang.String getUniqueName()
Get unique name (prefixed by the owners class type, to avoid Bank, Player and Company namespace clashes).

Returns:

getShare

public int getShare(PublicCompanyI company)
Returns percentage that a portfolio contains of one company.

Parameters:
company -
Returns:

ownsCertificates

public int ownsCertificates(PublicCompanyI company,
                            int unit,
                            boolean president)

swapPresidentCertificate

public java.util.List<PublicCertificateI> swapPresidentCertificate(PublicCompanyI company,
                                                                   Portfolio other)
Swap this Portfolio's President certificate for common shares in another Portfolio.

Parameters:
company - The company whose Presidency is handed over.
other - The new President's portfolio.
Returns:
The common certificates returned.

addTrain

public void addTrain(TrainI train)

addTrain

public void addTrain(TrainI train,
                     int[] position)

removeTrain

public void removeTrain(TrainI train)

buyTrain

public void buyTrain(TrainI train,
                     int price)

discardTrain

public void discardTrain(TrainI train)

updateTrainsModel

public void updateTrainsModel()

getNumberOfTrains

public int getNumberOfTrains()

getTrainList

public java.util.List<TrainI> getTrainList()

getTrainsPerType

public TrainI[] getTrainsPerType(TrainTypeI type)

getTrainsModel

public ModelObject getTrainsModel()

getUniqueTrains

public java.util.List<TrainI> getUniqueTrains()
Returns one train of any type held


getTrainOfType

public TrainI getTrainOfType(TrainTypeI type)

makeAbbreviatedListOfTrains

public java.lang.String makeAbbreviatedListOfTrains()
Make an abbreviated list of trains, like "2(6) 3(5)" etc, to show in the IPO.


makeFullListOfTrains

public java.lang.String makeFullListOfTrains()
Make a full list of trains, like "2 2 3 3", to show in any field describing train possessions, except the IPO.


addSpecialProperty

public boolean addSpecialProperty(SpecialPropertyI property,
                                  int position)
Add a special property. Used to make special properties independent of the private company that originally held it.

Parameters:
property - The special property object to add.
Returns:
True if successful.

removeSpecialProperty

public boolean removeSpecialProperty(SpecialPropertyI property)
Remove a special property.

Parameters:
property - The special property object to remove.
Returns:
True if successful.

addObject

public boolean addObject(Moveable object,
                         int[] position)
Add an object.

Specified by:
addObject in interface MoveableHolder
Parameters:
object - The object to add.
position - Position to insert object at. O: at front, -1, at end, >0: at that position.
Returns:
True if successful.

removeObject

public boolean removeObject(Moveable object)
Remove an object.

Specified by:
removeObject in interface MoveableHolder
Parameters:
object - The object to remove.
Returns:
True if successful.

getListIndex

public int[] getListIndex(Moveable object)
Specified by:
getListIndex in interface MoveableHolder

getPersistentSpecialProperties

public java.util.List<SpecialPropertyI> getPersistentSpecialProperties()
Returns:
ArrayList of all special properties we have.

getAllSpecialProperties

public java.util.List<SpecialPropertyI> getAllSpecialProperties()

hasSpecialProperties

public boolean hasSpecialProperties()
Do we have any special properties?

Returns:
Boolean

getSpecialProperties

public <T extends SpecialPropertyI> java.util.List<T> getSpecialProperties(java.lang.Class<T> clazz,
                                                                           boolean includeExercised)

getPrivatesOwnedModel

public ModelObject getPrivatesOwnedModel()

addToken

public boolean addToken(TokenI token,
                        int position)
Specified by:
addToken in interface TokenHolder

removeToken

public boolean removeToken(TokenI token)
Description copied from interface: TokenHolder
Remove a token. Subclasses may override this method to implement side effects.

Specified by:
removeToken in interface TokenHolder
Parameters:
token - The token object to remove.
Returns:
True if successful.

getTokens

public java.util.List<TokenI> getTokens()
Specified by:
getTokens in interface TokenHolder
Returns:
ArrayList of all tokens we have.

hasTokens

public boolean hasTokens()
Description copied from interface: TokenHolder
Do we have any tokens?

Specified by:
hasTokens in interface TokenHolder
Returns:
Boolean

rustObsoleteTrains

public void rustObsoleteTrains()