example.stock
Class Stock

java.lang.Object
  extended by example.stock.Stock

public final class Stock
extends java.lang.Object

This is a utility class that is used to parse data obtained from either the quote server or the database and break it into fields for easy use rather than spreading the parsing code around to a thousand different places through out the program.


Constructor Summary
Stock()
           
 
Method Summary
static java.lang.String convert(int intNum)
          Convert an int into a String with the decimal placed back in
static int getChange(java.lang.String quoteString)
          Return the $ change in the stock
static int getHigh(java.lang.String quoteString)
          Return the 52-week high for the stock
static int getLow(java.lang.String quoteString)
          Return the 52-week low of the stock
static java.lang.String getName(java.lang.String quoteString)
          Return the name of the stock
static int getOpen(java.lang.String quoteString)
          Return the opening price of the stock
static int getPrevious(java.lang.String quoteString)
          Return the previous high for the stock
static int getPrice(java.lang.String quoteString)
          Return the price of the last trade of the stock
static java.lang.String getStringChange(java.lang.String quoteString)
          String representation of change with decimal placed back in the correct spot
static java.lang.String getStringHigh(java.lang.String quoteString)
          String representation of the 52-week high with decimal placed back in the correct spot
static java.lang.String getStringLow(java.lang.String quoteString)
          String representation of the 52-week low with decimal placed back in the correct spot
static java.lang.String getStringOpen(java.lang.String quoteString)
          String representation of the opening price with decimal placed back in the correct spot
static java.lang.String getStringPrevious(java.lang.String quoteString)
          String representation of previous with decimal placed back in the correct spot
static java.lang.String getStringPrice(java.lang.String quoteString)
          String representation of price with decimal placed back in the correct spot
static java.lang.String getTime(java.lang.String quoteString)
          Return the time of the last trade
static int makeInt(java.lang.String str)
          Take a String representation of an int and the number of decimal places that the String carries and make an int out of it Since there is no floating point support in MIDP/CLDC, we have to convert the decimal numbers into Integers.
static void parse(java.lang.String quoteString)
          Takes a String from the quote server or database and parses the string into each field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stock

public Stock()
Method Detail

parse

public static void parse(java.lang.String quoteString)
                  throws java.lang.NumberFormatException,
                         java.lang.StringIndexOutOfBoundsException

Takes a String from the quote server or database and parses the string into each field. We first have to split it into small strings and then parse each string that should be a number.

Parameters:
quoteString - the String to parse into the fields
Throws:
NumberFormatException - is thrown if data that is not of the correct format is passed in -- where the number parts of the string cannot be converted to Integers because there are non-numeric characters in positions where numbers are expected
StringIndexOutOfBoundsException - is thrown if data that is not of the correct format is passed in -- where the delimiters between the fields are not in the right spots, or the data is not of the correct length
java.lang.NumberFormatException
java.lang.StringIndexOutOfBoundsException

makeInt

public static int makeInt(java.lang.String str)
                   throws java.lang.NumberFormatException,
                          java.lang.StringIndexOutOfBoundsException

Take a String representation of an int and the number of decimal places that the String carries and make an int out of it

Since there is no floating point support in MIDP/CLDC, we have to convert the decimal numbers into Integers. We do this by:

  • Looking at only the first 7 significant characters which, because of the decimal, means the first 6 numbers from left to right.
  • Looking at a maximum of 4 decimal places
  • We remove the decimal character (if there is one) and concatenate the numbers before and after the decimal so that we can convert to an integer and manipulate the value as a number
  • After doing this for each number, we have int values but no notion of where the decimal place was. To alleviate this, we make sure that each number has EXACTLY 4 decimal place holders. Therefore, we can divide by 10000 to put the decimal place back in the same spot.
          Example: 100    -> 1000000 ->            /10000 = 100
          Example: 345.67 -> 34567   -> 3456700 -> /10000 = 345.67
          Example: 3.4526 -> 34526   ->            /10000 = 3.4526
    
  • Parameters:
    str - the String value to convert to an int
    Returns:
    the int value of the string
    Throws:
    java.lang.NumberFormatException
    java.lang.StringIndexOutOfBoundsException

    getName

    public static java.lang.String getName(java.lang.String quoteString)

    Return the name of the stock

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    name (ticker symbol) of the stock

    getTime

    public static java.lang.String getTime(java.lang.String quoteString)

    Return the time of the last trade

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    time of the last trade of the stock

    getPrice

    public static int getPrice(java.lang.String quoteString)

    Return the price of the last trade of the stock

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    price of the last trade of the stock

    getChange

    public static int getChange(java.lang.String quoteString)

    Return the $ change in the stock

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    $ change in the stock today

    getHigh

    public static int getHigh(java.lang.String quoteString)

    Return the 52-week high for the stock

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    52-week high of the stock

    getLow

    public static int getLow(java.lang.String quoteString)

    Return the 52-week low of the stock

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    52-week low of the stock

    getOpen

    public static int getOpen(java.lang.String quoteString)

    Return the opening price of the stock

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    opening price of the stock today

    getPrevious

    public static int getPrevious(java.lang.String quoteString)

    Return the previous high for the stock

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    previous high for the stock

    convert

    public static java.lang.String convert(int intNum)

    Convert an int into a String with the decimal placed back in

    Parameters:
    intNum - the int value to convert to a String
    Returns:
    The String value of the int

    getStringPrice

    public static java.lang.String getStringPrice(java.lang.String quoteString)

    String representation of price with decimal placed back in the correct spot

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    current stock price

    getStringChange

    public static java.lang.String getStringChange(java.lang.String quoteString)

    String representation of change with decimal placed back in the correct spot

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    change in stock price today

    getStringHigh

    public static java.lang.String getStringHigh(java.lang.String quoteString)

    String representation of the 52-week high with decimal placed back in the correct spot

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    52-week high

    getStringLow

    public static java.lang.String getStringLow(java.lang.String quoteString)

    String representation of the 52-week low with decimal placed back in the correct spot

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    52-week low

    getStringOpen

    public static java.lang.String getStringOpen(java.lang.String quoteString)

    String representation of the opening price with decimal placed back in the correct spot

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    opening stock price

    getStringPrevious

    public static java.lang.String getStringPrevious(java.lang.String quoteString)

    String representation of previous with decimal placed back in the correct spot

    Parameters:
    quoteString - String to parse for the field data
    Returns:
    previous high for the stock