com.sun.tdk.sampleapi
Class Quote

java.lang.Object
  |
  +--com.sun.tdk.sampleapi.Quote

public class Quote
extends java.lang.Object

Represents (immutable) stock quote.

Since:
1.0

Constructor Summary
Quote(java.lang.String name, java.util.Date time, int price, int change, int high, int low, int open, int prev)
          Creates a new Quote object.
 
Method Summary
static java.lang.String convert(int intNum)
          Convert an int to a String with the decimal placed back in (divide by 10000).
 int getChange()
          Returns the change in the stock in 1/10000 of a dollar.
 int getHigh()
          Returns the 52-week high for the stock.
 int getLow()
          Returns the 52-week low for the stock.
 java.lang.String getName()
          Returns the name of the stock.
 int getOpen()
          Returns the opening price of the stock.
 int getPrevious()
          Returns the previous high for the stock.
 int getPrice()
          Returns the price of the last trade of the stock.
 java.lang.String getStringChange()
          Returns the string representation of change with the decimal placed back in the correct position.
 java.lang.String getStringHigh()
          Returns the String representation of the 52-week high with the decimal placed back in the correct position.
 java.lang.String getStringLow()
          Returns the String representation of the 52-week low with the decimal placed back in the correct position.
 java.lang.String getStringOpen()
          Returns the String representation of the opening price with the decimal placed back in the correct position.
 java.lang.String getStringPrevious()
          Returns the String representation of previous with the decimal placed back in the correct position.
 java.lang.String getStringPrice()
          Returns the string representation of the price with the decimal placed back in the correct position.
 java.util.Date getTime()
          Returns the time of the last trade.
static int makeInt(java.lang.String source)
          Takes a String representation of a floating point number and makes an int out of it.
 java.lang.String toString()
          Returns the String representation of this quote in the format getName()+" "+getStringPrice()+" at "+getTime()+" "+ getStringChange().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Quote

public Quote(java.lang.String name,
             java.util.Date time,
             int price,
             int change,
             int high,
             int low,
             int open,
             int prev)
Creates a new Quote object. Argument time can be null.

Parameters:
name - Name of the stock
time - Time of the last trade, can be null
price - Price of the stock
change - Change in 1/10000 of a dollar
high - 52-week high
low - 52-week low
open - Opening price on the day
prev - Previous high
Throws:
java.lang.NullPointerException - if the specified name is null
Method Detail

makeInt

public static int makeInt(java.lang.String source)
                   throws java.lang.NumberFormatException

Takes a String representation of a floating point number and makes an int out of it.

Since there is no floating point support on some limited devices (for example, pagers), we have to convert the decimal numbers into Integers. We do this by:

  • Looking at a maximum of 4 fractional places (trim exceeding)
  • Performing a "multiplication" by 10000 to a string representation of a floating point number by cutting out the decimal point and adding the appropriate number of zeroes if needed. The original number can then be restored using the convert(int) method.
  • After doing this the string representation is converted to an int
          Example: 100     -> 1000000  (/10000 = 100)
          Example: 345.67  -> 3456700  (/10000 = 345.67)
          Example: 3.45678 -> 34567    (/10000 = 3.4567)
          Example: 1234567 -> 12345670000 (doesn't fit into int,
                    results in NumberFormatException)
    
  • Parameters:
    source - The String value to convert to an int
    Returns:
    The int value of the string (trimmed to 4 fractional digits and multiplied by 10000)
    Throws:
    java.lang.NumberFormatException - If the source is null or after applying specified operations the value does not represent a valid int
    See Also:
    convert(int)

    getName

    public java.lang.String getName()
    Returns the name of the stock.

    Returns:
    Name (ticker symbol) of the stock

    getTime

    public java.util.Date getTime()
    Returns the time of the last trade.

    Returns:
    Time of the last trade of the stock

    getPrice

    public int getPrice()
    Returns the price of the last trade of the stock.

    Returns:
    Price of the last trade of the stock

    getChange

    public int getChange()
    Returns the change in the stock in 1/10000 of a dollar.

    Returns:
    Change in the stock today

    getHigh

    public int getHigh()
    Returns the 52-week high for the stock.

    Returns:
    The 52-week high for the stock

    getLow

    public int getLow()
    Returns the 52-week low for the stock.

    Returns:
    The 52-week low for the stock

    getOpen

    public int getOpen()
    Returns the opening price of the stock.

    Returns:
    Opening price of the stock today

    getPrevious

    public int getPrevious()
    Returns the previous high for the stock.

    Returns:
    Previous high for the stock

    convert

    public static java.lang.String convert(int intNum)
    Convert an int to a String with the decimal placed back in (divide by 10000).
          Example: -100    -> -0.01
          Example: 34567   -> 3.4567
    

    Parameters:
    intNum - The int value to convert to a String
    Returns:
    The String value of the int
    See Also:
    makeInt(String)

    getStringPrice

    public java.lang.String getStringPrice()
    Returns the string representation of the price with the decimal placed back in the correct position.

    Returns:
    Current stock price

    getStringChange

    public java.lang.String getStringChange()
    Returns the string representation of change with the decimal placed back in the correct position.

    Returns:
    Change in stock price today

    getStringHigh

    public java.lang.String getStringHigh()
    Returns the String representation of the 52-week high with the decimal placed back in the correct position.

    Returns:
    The 52-week high

    getStringLow

    public java.lang.String getStringLow()
    Returns the String representation of the 52-week low with the decimal placed back in the correct position.

    Returns:
    The 52-week low

    getStringOpen

    public java.lang.String getStringOpen()
    Returns the String representation of the opening price with the decimal placed back in the correct position.

    Returns:
    Opening stock price

    getStringPrevious

    public java.lang.String getStringPrevious()
    Returns the String representation of previous with the decimal placed back in the correct position.

    Returns:
    Previous high for the stock

    toString

    public java.lang.String toString()
    Returns the String representation of this quote in the format getName()+" "+getStringPrice()+" at "+getTime()+" "+ getStringChange(). Overrides Object.toString.

    Overrides:
    toString in class java.lang.Object