StocksMonitor 1.5.0

hirondelle.stocks.portfolio
Class Portfolio

Object
  extended by Portfolio

public final class Portfolio
extends Object

Represents a uniquely-named set of Stock objects, in which the user has an interest in monitoring.

Methods in this class which take a Collection of Quote objects as a parameter

Here is an example illustrating how to change the stocks contained in the portfolio :

fWorkingCopy = new TreeSet( fCurrentPortfolio.getStocks() );
//..edit the contents of fWorkingCopy
fCurrentPortfolio.setStocks(fWorkingCopy);
Note that edits to fWorkingCopy can be easily abandoned, without affecting fCurrentPortfolio.


Constructor Summary
Portfolio(String aName, Set<Stock> aStocks)
          Constructor.
 
Method Summary
 boolean equals(Object aThat)
           
 BigDecimal getBookValue(Collection<Quote> aQuotes)
          Return the cost of acquisition of all items in thisPortfolio which also appear in aQuotes.
 BigDecimal getCurrentValue(Collection<Quote> aQuotes)
          Return the current worth of all items in the Portfolio which also appear in aQuotes.
 String getName()
          Return the unique name of this Portfolio.
 BigDecimal getPercentageProfit(Collection<Quote> aQuotes)
          Return getProfit(java.util.Collection) divided by getBookValue(java.util.Collection); if the book value is zero, then return zero.
 BigDecimal getProfit(Collection<Quote> aQuotes)
          Return getCurrentValue(java.util.Collection) less getBookValue(java.util.Collection).
 List<Quote> getQuotes()
          Return Quote objects, one for each Stock in this Portfolio.
 Set<Stock> getStocks()
          Return the Stock objects contained in this Portfolio.
static Portfolio getUntitledPortfolio()
          Return a Portfolio which contains no stocks, and whose title is an empty String.
 int hashCode()
           
 boolean isUntitled()
          Return true only if the name of this Portfolio is an empty String.
 void setName(String aName)
          Set the unique name of this Portfolio.
 void setStocks(Set<Stock> aStocks)
          Replace the Stock objects contained in this Portfolio.
 String toString()
          Represent this object as a String - intended for debugging purposes only.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Portfolio

public Portfolio(String aName,
                 Set<Stock> aStocks)
Constructor.

Parameters:
aName - is the unique identifier for this Portfolio, has visible content
aStocks - is possibly-empty, and represents a reference to an object which is shared with the caller; no defensive copy is made.
Method Detail

getUntitledPortfolio

public static Portfolio getUntitledPortfolio()
Return a Portfolio which contains no stocks, and whose title is an empty String.

An untitled Portfolio is a special object, which cannot be created either directly (by using the constructor), nor indirectly (by using the constructor and changing object state). These special objects are only obtained through this method.


isUntitled

public boolean isUntitled()
Return true only if the name of this Portfolio is an empty String.


getName

public String getName()
Return the unique name of this Portfolio.

Returns:
possibly-empty String.

setName

public void setName(String aName)
Set the unique name of this Portfolio.

Parameters:
aName - see Portfolio(String, Set) for conditions on aName.

getStocks

public Set<Stock> getStocks()
Return the Stock objects contained in this Portfolio.

The returned value is unmodifiable. See class description for example of of changing the Stocks in a Portfolio.


setStocks

public void setStocks(Set<Stock> aStocks)
Replace the Stock objects contained in this Portfolio.

Parameters:
aStocks - see Portfolio(String, Set) for conditions on aStocks.

getQuotes

public List<Quote> getQuotes()
                      throws DataAccessException
Return Quote objects, one for each Stock in this Portfolio.

Throws:
DataAccessException

getBookValue

public BigDecimal getBookValue(Collection<Quote> aQuotes)
Return the cost of acquisition of all items in thisPortfolio which also appear in aQuotes. Each Stock in aQuotes contributes the value Stock.getBookValue().

Parameters:
aQuotes - is a possibly-filtered collection of Quote objects; see QuoteFilter; each Quote object corresponds to a Stock known to this Portfolio.
Returns:
a value greater than or equal to 0.00.

getCurrentValue

public BigDecimal getCurrentValue(Collection<Quote> aQuotes)
Return the current worth of all items in the Portfolio which also appear in aQuotes. Each Quote contributes the value Quote.getCurrentValue().

Parameters:
aQuotes - is a possibly-filtered collection of Quote objects; see QuoteFilter.
Returns:
a value greater than or equal to 0.00.

getProfit

public BigDecimal getProfit(Collection<Quote> aQuotes)
Return getCurrentValue(java.util.Collection) less getBookValue(java.util.Collection).

Parameters:
aQuotes - is a possibly-filtered collection of Quote objects; see QuoteFilter.
Returns:
value is positive for a profit, and negative for a loss.

getPercentageProfit

public BigDecimal getPercentageProfit(Collection<Quote> aQuotes)
Return getProfit(java.util.Collection) divided by getBookValue(java.util.Collection); if the book value is zero, then return zero.

Parameters:
aQuotes - is a possibly-filtered collection of Quote objects; see QuoteFilter.

toString

public String toString()
Represent this object as a String - intended for debugging purposes only.

Overrides:
toString in class Object

equals

public boolean equals(Object aThat)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

StocksMonitor 1.5.0

Copyright Hirondelle Systems - License - Generated 2008Jul12.10.53