Venice 0.7beta

org.mov.quote
Class Symbol

java.lang.Object
  extended by org.mov.quote.Symbol
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class Symbol
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable

An immutable representation of a stock symbol, e.g. CBA or WBC. Previously the stock symbol was stored as a String but this created the question of whether it should be stored in lower or upper case. Unfortunately, due to development drift, even though the stock symbols were always displayed in upper case, they were stored in lower case. Often a "missing" conversion meant the symbol was displayed in lower case or worse it was stored in upper case which could cause the stock symbol to become "invisible".

By creating a single class we reduce the amount of toUpperCase() and toLowerCase() calls required, and have a single place to store symbol parsing code.

To reduce memory, symbols are stored canonically. That is there is a single object for each symbol. For example the string symbol "CBA" would be represented by a single class, no matter where it was used. So instead of instantiating a new symbol class, you find the canonical object using the find(java.lang.String) method.

Author:
Andrew Leppard

Field Summary
static int MAXIMUM_SYMBOL_LENGTH
          The maximum valid length for a symbol.
static int MINIMUM_SYMBOL_LENGTH
          The minimum valid length for a symbol
 
Method Summary
 char charAt(int offset)
          Return the character at the given offset.
 java.lang.Object clone()
          Create a clone of this symbol.
 int compareTo(java.lang.Object object)
          Compare this symbol to the given symbol.
 boolean equals(java.lang.Object object)
          Compare this symbol to the given symbol.
static Symbol find(java.lang.String string)
          Return the canonical symbol instance of the given symbol string.
 java.lang.String get()
          Return the symbol string.
 int hashCode()
          Calculate the hash code for this symbol.
 int length()
          Return the length of the symbol.
static java.util.SortedSet toSortedSet(java.lang.String string, boolean checkExists)
          Convert a string containing a list of symbols separated by spaces or commas into a sorted set of symbols with duplicates removed.
 java.lang.String toString()
          Convert the symbol to a string.
static Symbol toSymbol(java.lang.String string)
          Convert a string containing a single symbol into a quote symbol.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MINIMUM_SYMBOL_LENGTH

public static final int MINIMUM_SYMBOL_LENGTH
The minimum valid length for a symbol

See Also:
Constant Field Values

MAXIMUM_SYMBOL_LENGTH

public static final int MAXIMUM_SYMBOL_LENGTH
The maximum valid length for a symbol.

See Also:
Constant Field Values
Method Detail

find

public static Symbol find(java.lang.String string)
                   throws SymbolFormatException
Return the canonical symbol instance of the given symbol string.

Parameters:
string - a string containing a single symbol
Throws:
SymbolFormatException - if the string doesn't contain a valid quote

get

public java.lang.String get()
Return the symbol string.

Returns:
an upper case symbol string

length

public int length()
Return the length of the symbol. This is guaranteed to be within bounds.

Returns:
the symbol length.

charAt

public char charAt(int offset)
Return the character at the given offset. See the java.lang.String class for more details.

Parameters:
offset - the character offset
Returns:
the character at the given offset

toSortedSet

public static java.util.SortedSet toSortedSet(java.lang.String string,
                                              boolean checkExists)
                                       throws SymbolFormatException
Convert a string containing a list of symbols separated by spaces or commas into a sorted set of symbols with duplicates removed. This function Checks that all symbols appear in the quote source. e.g "CBA WBC TLS" -> [CBA, TLS, WBC].

Parameters:
string - a comma or space separated list of symbols
checkExists - set this flag to TRUE to make sure that the symbols are in the current quote source
Returns:
a sorted set of symbols
Throws:
SymbolFormatException - if the string doesn't contain a list of valid quotes

toSymbol

public static Symbol toSymbol(java.lang.String string)
                       throws SymbolFormatException
Convert a string containing a single symbol into a quote symbol. This differs from find(java.lang.String) as it performs better error checking and checks that the symbol exists.

Parameters:
string - a string containing a single symbol
Throws:
SymbolFormatException - if the string doesn't contain a valid quote

clone

public java.lang.Object clone()
Create a clone of this symbol.

Overrides:
clone in class java.lang.Object
Returns:
clone of this symbol

compareTo

public int compareTo(java.lang.Object object)
Compare this symbol to the given symbol.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - symbol to compare
Returns:
the value 0 if the symbols are equal; 1 if this symbol is after the specified symbol or -1 if this symbol is before the specified symbol.

equals

public boolean equals(java.lang.Object object)
Compare this symbol to the given symbol.

Overrides:
equals in class java.lang.Object
Parameters:
object - the symbol to compare
Returns:
true if they are equal

hashCode

public int hashCode()
Calculate the hash code for this symbol.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

toString

public java.lang.String toString()
Convert the symbol to a string. This is identical to the get() method.

Overrides:
toString in class java.lang.Object
Returns:
the symbol string

Venice 0.7beta