org.starhope.appius.mb
Class Currency

java.lang.Object
  extended by org.starhope.appius.util.ManagedReferenceHolder
      extended by org.starhope.appius.sql.SQLPeerDatum
          extended by org.starhope.appius.sql.SQLPeerEnum
              extended by org.starhope.appius.mb.Currency

public class Currency
extends SQLPeerEnum

Author:
brpocock

Field Summary
private  String code
          The ISO-4217 currency code (three letters); "USD" is U.S.
private static long serialVersionUID
           
private  String symbol
          The display character sequence.
 
Fields inherited from class org.starhope.appius.sql.SQLPeerEnum
enumeration, instance
 
Constructor Summary
private Currency()
           
protected Currency(int id)
           
private Currency(ResultSet resultSet)
           
 
Method Summary
 void flush()
           
static Currency get_USD()
          This is a quick "semantic sugar" to pick up U.S.
static Currency get(org.json.JSONObject object)
           
static Currency get(String id)
           
static Currency getByCode(String string)
           
 String getCode()
          Get the three-character (ISO-4217) currency code.
protected  PreparedStatement getStatement(Connection connection)
          WRITEME: document this method (brpocock, Aug 14, 2009)
 String getSymbol()
           
 void set(org.json.JSONObject o)
           
protected  void set(ResultSet rs)
           
 void setCode(String newCode)
          Change the currency code for this instance.
 void setSymbol(String newSymbol)
          Set the user-visible displayed symbol of this currency.
 
Methods inherited from class org.starhope.appius.sql.SQLPeerEnum
cache, getCacheUniqueID, getID, getID, getString, getString, prepCache, toJSON
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
changed, findInCache, get, prepare, prepare, saveInCache
 
Methods inherited from class org.starhope.appius.util.ManagedReferenceHolder
deref, setRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

code

private String code
The ISO-4217 currency code (three letters); "USD" is U.S. Dollar, and "EUR" is the Euro.


symbol

private String symbol
The display character sequence. For US Dollars, it's " US $ "; for Euros, it's just the Euro sign

Constructor Detail

Currency

private Currency()

Currency

protected Currency(int id)
Parameters:
id - The integral ID number for the type of currency to be instantiated

Currency

private Currency(ResultSet resultSet)
Parameters:
resultSet - the SQL row from which to instantiate this currency object
Method Detail

get

public static Currency get(org.json.JSONObject object)
                    throws RuntimeException,
                           NotFoundException,
                           org.json.JSONException
Parameters:
object - the JSON data describing the currency wanted
Returns:
the Currency object
Throws:
org.json.JSONException - if the JSON data is badly-formed
NotFoundException - if the object isn't found in the database
RuntimeException - if something else bad happens

get

public static Currency get(String id)
                    throws RuntimeException,
                           NotFoundException
Parameters:
id - database ID
Returns:
currency with that database ID
Throws:
NotFoundException - if it's not found in the database
RuntimeException - if something else wonky were to happen

get_USD

public static Currency get_USD()
This is a quick "semantic sugar" to pick up U.S. Dollars as a currency format, since that's realistically the only one we're dealing with at the moment.

Returns:
a Currency object representing U.S. Dollars.

getByCode

public static Currency getByCode(String string)
                          throws NotFoundException
Parameters:
string - ISO-4217 currency code
Returns:
a Currency object
Throws:
NotFoundException - if it can't be found

flush

public void flush()
Specified by:
flush in class SQLPeerDatum
See Also:
SQLPeerDatum.flush()

getCode

public String getCode()
Get the three-character (ISO-4217) currency code.

Returns:
A string of three uppercase characters

getStatement

protected PreparedStatement getStatement(Connection connection)
Description copied from class: SQLPeerEnum
WRITEME: document this method (brpocock, Aug 14, 2009)

Specified by:
getStatement in class SQLPeerEnum
Returns:
See Also:
SQLPeerEnum.getStatement(java.sql.Connection)

getSymbol

public String getSymbol()
Returns:
A string of 1-5 characters suitable for unambiguous representation of this currency.
See Also:
Returns the currency symbol for user presentation of prices.

set

public void set(org.json.JSONObject o)
Overrides:
set in class SQLPeerDatum
See Also:
CastsToJSON.set(org.json.JSONObject)

set

protected void set(ResultSet rs)
Specified by:
set in class SQLPeerDatum
See Also:
SQLPeerDatum.set(java.sql.ResultSet)

setCode

public void setCode(String newCode)
             throws DataException
Change the currency code for this instance.

Parameters:
newCode - The new currency code to be set (ISO-4217, uppercase, e.g. "USD")
Throws:
DataException - if the specification does not consist of three BraqueCharacter.UPPERCASE_LETTER characters.

setSymbol

public void setSymbol(String newSymbol)
               throws DataException
Set the user-visible displayed symbol of this currency. E.G. for the US Dollar, this is "US $"; Mexican New Peso, "Mx $"; for the Canadian dollar, "CA $"; for the Chinese Yuan, it might be "Cn ¥", versus Japanese Yen "Jp ¥"; Euro, just "€" (since there's no confusion with any other country using a similar currency symbol)

Parameters:
newSymbol - The new symbol string to be used for this currency
Throws:
DataException - if the new symbol string is not supplied, or is more than 5 characters long