|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectexample.stock.Stock
public final class Stock
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 Integer s. |
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 |
---|
public Stock()
Method Detail |
---|
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.
quoteString
- the String
to parse into the fields
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
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 Integer
s.
We do this by:
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
str
- the String
value to convert
to an int
java.lang.NumberFormatException
java.lang.StringIndexOutOfBoundsException
public static java.lang.String getName(java.lang.String quoteString)
Return the name of the stock
quoteString
- String
to parse for the field data
public static java.lang.String getTime(java.lang.String quoteString)
Return the time of the last trade
quoteString
- String
to parse for the field data
public static int getPrice(java.lang.String quoteString)
Return the price of the last trade of the stock
quoteString
- String
to parse for the field data
public static int getChange(java.lang.String quoteString)
Return the $ change in the stock
quoteString
- String
to parse for the field data
public static int getHigh(java.lang.String quoteString)
Return the 52-week high for the stock
quoteString
- String
to parse for the field data
public static int getLow(java.lang.String quoteString)
Return the 52-week low of the stock
quoteString
- String
to parse for the field data
public static int getOpen(java.lang.String quoteString)
Return the opening price of the stock
quoteString
- String
to parse for the field data
public static int getPrevious(java.lang.String quoteString)
Return the previous high for the stock
quoteString
- String
to parse for the field data
public static java.lang.String convert(int intNum)
Convert an int
into a String
with the decimal placed back in
intNum
- the int
value to convert
to a String
String
value of the intpublic static java.lang.String getStringPrice(java.lang.String quoteString)
String representation of price with decimal placed back in the correct spot
quoteString
- String
to parse for the field data
public static java.lang.String getStringChange(java.lang.String quoteString)
String representation of change with decimal placed back in the correct spot
quoteString
- String
to parse for the field data
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
quoteString
- String
to parse for the field data
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
quoteString
- String
to parse for the field data
public static java.lang.String getStringOpen(java.lang.String quoteString)
String representation of the opening price with decimal placed back in the correct spot
quoteString
- String
to parse for the field data
public static java.lang.String getStringPrevious(java.lang.String quoteString)
String representation of previous with decimal placed back in the correct spot
quoteString
- String
to parse for the field data
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |