Methods Summary |
---|
public static java.lang.String | convert(int intNum)Convert an int into a String
with the decimal placed back in
String s = String.valueOf(intNum);
String pre = s.substring(0, ((s.length() < 4) ?
s.length() : s.length()-4));
String suf = s.substring(((s.length() == pre.length()) ?
0 : s.length()-4), s.length());
if (Integer.valueOf(suf).intValue() == 0) {
return pre;
}
while (Integer.valueOf(suf.substring(suf.length()-1,
suf.length())).intValue() == 0) {
suf = suf.substring(0, suf.length()-1);
}
return (pre + "." + suf);
|
public static int | getChange(java.lang.String quoteString)Return the $ change in the stock
parse(quoteString);
return change;
|
public static int | getHigh(java.lang.String quoteString)Return the 52-week high for the stock
parse(quoteString);
return high;
|
public static int | getLow(java.lang.String quoteString)Return the 52-week low of the stock
parse(quoteString);
return low;
|
public static java.lang.String | getName(java.lang.String quoteString)Return the name of the stock
parse(quoteString);
return name;
|
public static int | getOpen(java.lang.String quoteString)Return the opening price of the stock
parse(quoteString);
return open;
|
public static int | getPrevious(java.lang.String quoteString)Return the previous high for the stock
parse(quoteString);
return prev;
|
public static int | getPrice(java.lang.String quoteString)Return the price of the last trade of the stock
parse(quoteString);
return price;
|
public static java.lang.String | getStringChange(java.lang.String quoteString)String representation of change with decimal placed
back in the correct spot
parse(quoteString);
return convert(change);
|
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
parse(quoteString);
return convert(high);
|
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
parse(quoteString);
return convert(low);
|
public static java.lang.String | getStringOpen(java.lang.String quoteString)String representation of the opening price with
decimal placed back in the correct spot
parse(quoteString);
return convert(open);
|
public static java.lang.String | getStringPrevious(java.lang.String quoteString)String representation of previous with decimal
placed back in the correct spot
parse(quoteString);
return convert(prev);
|
public static java.lang.String | getStringPrice(java.lang.String quoteString)String representation of price with decimal placed
back in the correct spot
parse(quoteString);
return convert(price);
|
public static java.lang.String | getTime(java.lang.String quoteString)Return the time of the last trade
parse(quoteString);
return time;
|
public static int | makeInt(java.lang.String source)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:
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
// cut the entire string down to 6 characters
if (source.length() > 7) {
source = source.substring(0, 6);
}
// cut the string down to 4 decimal places
while (source.length() - (source.indexOf('.") + 1) > 4) {
source = source.substring(0, source.length()-1);
}
// convert to an int
int value = (source.indexOf('.") == -1) ?
Integer.valueOf(source).intValue()
: Integer.valueOf(new String(
source.substring(0, source.indexOf('.")) +
source.substring(source.indexOf('.")+1,
source.length()))).intValue();
// offset to 4 decimal placeholders
int length = (source.indexOf('.") == -1) ? 0
: source.substring(source.indexOf('.")+1,
source.length()).length();
if (length < 4) {
int diff = 4 - length;
while (diff-- > 0) { value *= 10; }
}
return value;
|
public static void | parse(java.lang.String quoteString)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.
// get our starting index
int index = quoteString.indexOf('"");
if (index == -1) {
name = quoteString;
return;
}
// split the string up into it's fields
name = quoteString.substring(++index,
(index = quoteString.indexOf('"", index)));
index += 3;
time = quoteString.substring(index,
(index = quoteString.indexOf('-", index))-1);
index += 5;
String Sprice = quoteString.substring(index,
(index = quoteString.indexOf('<", index)));
index += 6;
String Schange = quoteString.substring(index,
(index = quoteString.indexOf(',", index)));
index += 2;
String Slow = quoteString.substring(index,
(index = quoteString.indexOf(' ", index)));
index += 3;
String Shigh = quoteString.substring(index,
(index = quoteString.indexOf('"", index)));
index += 2;
String Sopen = quoteString.substring(index,
(index = quoteString.indexOf(',", index)));
++index;
String Sprev = quoteString.substring(index, quoteString.length()-2);
// convert the strings that should be numbers into ints
price = makeInt(Sprice);
// remove the '+' sign if it exists
Schange = (Schange.indexOf('+") == -1) ?
Schange : Schange.substring(1, Schange.length());
change = makeInt(Schange);
prev = makeInt(Sprev);
if ("N/A".equals(Slow)) {
low = prev;
} else {
low = makeInt(Slow);
}
if ("N/A".equals(Shigh)) {
high = prev;
} else {
high = makeInt(Shigh);
}
if ("N/A".equals(Sopen)) {
open = prev;
} else {
open = makeInt(Sopen);
}
|