public final class Stock extends Object implements Comparable<Stock>
All permitted values are specified by the constructor.
Constructor and Description |
---|
Stock(String aName,
String aTicker,
Exchange aExchange,
Integer aNumShares,
BigDecimal aAveragePrice) |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Stock aThat) |
boolean |
equals(Object aThat) |
BigDecimal |
getAveragePrice() |
BigDecimal |
getBookValue()
Return the product of
getNumShares() and getAveragePrice() . |
Exchange |
getExchange() |
String |
getName() |
Integer |
getNumShares() |
String |
getTicker() |
int |
hashCode() |
boolean |
isIndex()
Return true only if the ticker represents an index such as
the Dow Jones or the Standard and Poor 500 , as opposed to a regular stock.
|
static boolean |
isValidInput(List<String> aErrorMessages,
String aName,
String aTicker,
Exchange aExchange,
Integer aNumShares,
BigDecimal aAvgPrice)
Validate user input to a fine-grained level.
|
String |
toString()
Format this object as text which can be used as input to
valueOf(java.lang.String) . |
Stock |
valueOf(String aStockText)
Parse a result of
toString() into a Stock object. |
public Stock(String aName, String aTicker, Exchange aExchange, Integer aNumShares, BigDecimal aAveragePrice)
aName
- has visible content, and is the
full name of the stock.aTicker
- non-null, contains only letters, periods, underscores, and
the ^ character, and must have a length in the range 1..20 inclusive ;
it is the ticker symbol used by aExchange, and does not include the
suffix used by Yahoo to identify the exchange.aExchange
- is not nullaNumShares
- is not null, and represents a
holding as input by the user (and usually reflects their actual holding).aAveragePrice
- is not null, satisfies
!aAveragePrice.doubleValue<0,
and equals the average price paid by the user for aNumShares.public Stock valueOf(String aStockText)
toString()
into a Stock object.aStockText
- is in the format defined by toString()
.public String toString()
valueOf(java.lang.String)
.
The return value is used for persistence of Stock objects.
The format is shown by this example:
SUNW:Sun Microsystems:Nasdaq Stock Exchange:100:46.25
That is:
Ticker:Name:Exchange:NumShares:AveragePrice
public static boolean isValidInput(List<String> aErrorMessages, String aName, String aTicker, Exchange aExchange, Integer aNumShares, BigDecimal aAvgPrice)
All parameters other than aErrorMessages may take any value whatsoever. All parameters other than aErrorMessages are examined, and every invalid parameter will cause a corresponding error message to be added to aErrorMessages. Valid parameters have no corresponding message.
All criteria for validity are identical with those of the constructor.
This method is intended to help validate textual user input into a dialog, before any attempt is made to call the constructor of this class. In the event of an error, the associated error messages can be displayed to the user.
aErrorMessages
- is an out parameter, in which an error message is
placed for each problem found; it must be non-null and empty.public Exchange getExchange()
public Integer getNumShares()
public BigDecimal getAveragePrice()
public BigDecimal getBookValue()
getNumShares()
and getAveragePrice()
.
The book value of a security is simply the cost of its acquisition.
public boolean isIndex()
In the Yahoo system, an index always begins with the ^ character.
public int compareTo(Stock aThat)
compareTo
in interface Comparable<Stock>
Copyright Hirondelle Systems - License - Generated 2013Sep20.10.58