type.lib
Class StockNS

java.lang.Object
  extended by type.lib.StockNS
All Implemented Interfaces:
java.io.Serializable

public class StockNS
extends java.lang.Object
implements java.io.Serializable

This class is identical to the Stock class except for three non-standard (NS) features. For pedagogical reasons, neither toString nor equals nor hashCode is present.

Version:
7.0 - Summer 2010
Author:
H. Roumani, roumani@cse.yorku.ca
See Also:
Serialized Form

Field Summary
 char delimiter
          This field determines what character is inserted between the stock symbol and its name in the return of the toString() method (assuming the symbol exists).
 java.lang.String name
          The name of this stock as listed on the exchange.
static boolean titleCaseName
          This field controls the format of the stock name as returned by the getName() method.
 
Constructor Summary
StockNS()
          Construct a default Stock having a null symbol.
StockNS(StockNS stock)
          Construct a copy of the passed Stock.
StockNS(java.lang.String symbol)
          Construct a Stock having the (capitalized) passed symbol.
 
Method Summary
 StockNS cloneMe()
          Copy the state of this object.
 char getDelimiter()
          Determine the delimiter of this Stock.
 java.lang.String getName()
          Determine the name of this Stock as listed on the exchange.
 double getPrice()
          Determine the price of this Stock.
 java.lang.String getSymbol()
          Determine the symbol of this Stock.
 void refresh()
          Connect to the exchange and obtain the name and price of this stock and update its attributes accordingly.
 boolean setDelimiter(char myDelimiter)
          Mutator to change the delimiter of this stock to the passed one.
 void setSymbol(java.lang.String symbol)
          Mutator to change the symbol of this stock to the (capitalized) passed symbol.
 java.lang.String toString()
          Construct a string representation of this Stock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name
The name of this stock as listed on the exchange. If no such stock exists, the name is set to null.

(Bad design --this field should not be made public.)


delimiter

public char delimiter
This field determines what character is inserted between the stock symbol and its name in the return of the toString() method (assuming the symbol exists). The default is space.

(Bad design --should have been kept private. Access would have still been possible via the existing public accessor and mutator.)


titleCaseName

public static boolean titleCaseName
This field controls the format of the stock name as returned by the getName() method. If set to false (default), the name is returned exactly as listed on the exchange. Otherwise, it is returned in title case (1st letter of each word capitalized).

Constructor Detail

StockNS

public StockNS()
Construct a default Stock having a null symbol. This convenience constructor has the same effect as passing null to the 1-parameter, overloaded constructor.


StockNS

public StockNS(java.lang.String symbol)
Construct a Stock having the (capitalized) passed symbol. All of the stock attributes will be set as per the refresh() method.

Parameters:
symbol - the (ticker) symbol of the stock to construct.

StockNS

public StockNS(StockNS stock)
Construct a copy of the passed Stock.

Parameters:
stock - the Stock to copy.
Method Detail

getName

public java.lang.String getName()
Determine the name of this Stock as listed on the exchange. The letter case is as indicated in the titleCaseName field.

Returns:
the name of this Stock. If no such stock exists, null is returned.

getSymbol

public java.lang.String getSymbol()
Determine the symbol of this Stock.

Returns:
the symbol of this Stock.

getPrice

public double getPrice()
Determine the price of this Stock.

Returns:
the price of this Stock as last obtained from the exchange.

getDelimiter

public char getDelimiter()
Determine the delimiter of this Stock.

Returns:
the delimiter of this Stock.

setDelimiter

public boolean setDelimiter(char myDelimiter)
Mutator to change the delimiter of this stock to the passed one. No change is made, however, if the passed delimiter is a letter or a digit.

Parameters:
myDelimiter - the new delimiter character
Returns:
true if the change was made (i.e. if the passed parameter is neither a letter nor a digit), and return false otherwise.

setSymbol

public void setSymbol(java.lang.String symbol)
Mutator to change the symbol of this stock to the (capitalized) passed symbol. The stock attributes are re-set as per the refresh() method.

Parameters:
symbol - the symbol to change to.

toString

public java.lang.String toString()
Construct a string representation of this Stock.

Overrides:
toString in class java.lang.Object
Returns:
the stock's symbol (capitalized), followed by the delimiter character, followed by the stock's name. However if the symbol doesn't exist, the string "No such stock!" is returned.

refresh

public void refresh()
Connect to the exchange and obtain the name and price of this stock and update its attributes accordingly. If the symbol is null or is not listed on the exchange, the name is set to null and its price to 0.


cloneMe

public StockNS cloneMe()
Copy the state of this object.

Returns:
a reference to a new Stock object having exactly the state as this one.


Java by Abstraction: A Client-View Approach