|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.sun.tdk.sampleapi.Quote
Represents (immutable) stock quote.
Field Summary | |
static int |
CHANGE
Corresponds to the change in the stock in 1/10000 of a dollar. |
static int |
HIGH
Corresponds to the 52-week high for the stock. |
static int |
LOW
Corresponds to the 52-week low for the stock. |
static int |
OPEN
Corresponds to the opening price of the stock. |
static int |
PREVIOUS
Corresponds to the previous high for the stock. |
static int |
PRICE
Corresponds to the price of the last trade of the stock. |
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.Object |
getString(int index)
Returns stock change/high/low/openprevious/price. |
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
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int CHANGE
Constant value 1
is set to CHANGE
.
getString(int)
,
Constant Field Valuespublic static final int HIGH
Constant value 2
is set to HIGH
.
getString(int)
,
Constant Field Valuespublic static final int LOW
Constant value 3
is set to LOW
.
getString(int)
,
Constant Field Valuespublic static final int OPEN
Constant value 4
is set to OPEN
.
getString(int)
,
Constant Field Valuespublic static final int PREVIOUS
Constant value 5
is set to PREVIOUS
.
getString(int)
,
Constant Field Valuespublic static final int PRICE
Constant value 6
is set to PRICE
.
getString(int)
,
Constant Field ValuesConstructor Detail |
public Quote(java.lang.String name, java.util.Date time, int price, int change, int high, int low, int open, int prev)
time
can be null
.
name
- Name of the stocktime
- Time of the last trade, can be null
price
- Price of the stockchange
- Change in 1/10000 of a dollarhigh
- 52-week highlow
- 52-week lowopen
- Opening price on the dayprev
- Previous high
java.lang.NullPointerException
- if the specified name is null
Method Detail |
public java.lang.Object getString(int index)
getString(CHANGE)
== getStringChange()
getString(HIGH)
== getStringHigh()
getString(LOW)
== getStringLow()
getString(OPEN)
== getStringOpen()
getString(PREVIOUS)
== getStringPrevious()
getString(PRICE)
== getStringPrice()
IllegalArgumentException
- if
index is not one of CHANGE, HIGH, LOW, OPEN, PREVIOUS, or PRICE.getStringChange()
,
getStringHigh()
,
getStringLow()
,
getStringOpen()
,
getStringPrevious()
,
getStringPrice()
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
Integer
s.
We do this by:
convert(int)
method.
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)
source
- The String
value to convert
to an int
int
value of the string (trimmed to 4 fractional digits and
multiplied by 10000)
java.lang.NumberFormatException
- If the source is
null
or after applying specified operations the value does
not represent a valid int
convert(int)
public java.lang.String getName()
public java.util.Date getTime()
public int getPrice()
public int getChange()
public int getHigh()
public int getLow()
public int getOpen()
public int getPrevious()
public static java.lang.String convert(int intNum)
int
to a String
with the decimal placed back in (divide by 10000).
Example: -100 -> -0.01 Example: 34567 -> 3.4567
intNum
- The int
value to convert
to a String
String
value of the int
makeInt(String)
public java.lang.String getStringPrice()
public java.lang.String getStringChange()
change
with the decimal placed
back in the correct position.
public java.lang.String getStringHigh()
String
representation of the 52-week high with the decimal
placed back in the correct position.
public java.lang.String getStringLow()
String
representation of the 52-week low with the decimal
placed back in the correct position.
public java.lang.String getStringOpen()
String
representation of the opening price with
the decimal placed back in the correct position.
public java.lang.String getStringPrevious()
String
representation of previous with the decimal
placed back in the correct position.
public java.lang.String toString()
String
representation of this quote in the format
getName()+" "+getStringPrice()+" at "+getTime()+" "+ getStringChange()
.
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |