org.starhope.appius.user
Class Wallet

java.lang.Object
  extended by org.starhope.appius.util.SimpleDataRecord<Wallet>
      extended by org.starhope.appius.user.Wallet
All Implemented Interfaces:
com.whirlycott.cache.Cacheable, Serializable, Comparable<Wallet>, CTime, DataRecord, Copyable<Wallet>, HasSubversionRevision

public class Wallet
extends SimpleDataRecord<Wallet>
implements Copyable<Wallet>

Author:
brpocock@star-hope.org
See Also:
Serialized Form

Field Summary
private  Map<String,BigDecimal> currency
          amount of money in various forms
private  UserRecord myOwner
          The owner of the wallet
private static long serialVersionUID
          WRITEME: Document this brpocock@star-hope.org
 
Fields inherited from class org.starhope.appius.util.SimpleDataRecord
myLoader, timeLastChanged, timeLastSaved
 
Constructor Summary
Wallet()
          WRITEME: Document this constructor brpocock@star-hope.org
Wallet(RecordLoader<Wallet> loader, UserRecord owner)
          constructor for being loaded for a certain user;
Wallet(UserRecord owner)
          default constructor for a new wallet for the given user
 
Method Summary
 void add(String cu, BigDecimal amount)
          WRITEME: Document this method brpocock@star-hope.org
 Wallet copyProtoype(Wallet prototype)
          WRITEME: Document this method brpocock@star-hope.org
static Wallet forUser(UserRecord userRecord)
          Get the wallet for a given user, creating a new one if necessary.
 BigDecimal get(Currency cu)
           
 BigDecimal get(int n)
          Check a random currency.
 Map<String,BigDecimal> getAllCurrency()
          WRITEME: Document this method brpocock@star-hope.org
 int getCacheableID()
          Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.
 String getCacheableIdent()
          Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.
private  UserRecord getOwner()
          WRITEME: Document this method brpocock@star-hope.org
 String getSubversionRevision()
           Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.
 void put(Currency cu, BigDecimal amount)
          WRITEME: Document this method brpocock@star-hope.org
 void put(String cu, BigDecimal amount)
           
private  void setOwner(UserRecord owner)
          WRITEME: Document this method brpocock@star-hope.org
 org.json.JSONObject toJSON()
           
 
Methods inherited from class org.starhope.appius.util.SimpleDataRecord
changed, checkStale, compareTo, equals, finalize, getRecordLoader, getTimeLastChanged, getTimeLastSaved, hashCode, isBeingLoaded, markAsLoaded, markAsSaved, markForReload, onRemove, onRetrieve, onStore, save, setRecordLoader, toString
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
WRITEME: Document this brpocock@star-hope.org

See Also:
Constant Field Values

currency

private final Map<String,BigDecimal> currency
amount of money in various forms


myOwner

private UserRecord myOwner
The owner of the wallet

Constructor Detail

Wallet

public Wallet()
WRITEME: Document this constructor brpocock@star-hope.org


Wallet

public Wallet(RecordLoader<Wallet> loader,
              UserRecord owner)
constructor for being loaded for a certain user;

Parameters:
loader - the record loader
owner - the owner

Wallet

public Wallet(UserRecord owner)
default constructor for a new wallet for the given user

Parameters:
owner - the owner of the wallet
Method Detail

forUser

public static Wallet forUser(UserRecord userRecord)
Get the wallet for a given user, creating a new one if necessary.

Parameters:
userRecord - the user whose wallet we want to see
Returns:
their new or existing wallet, as appropriate

add

public void add(String cu,
                BigDecimal amount)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
cu - WRITEME
amount - WRITEME

copyProtoype

public Wallet copyProtoype(Wallet prototype)
Description copied from interface: Copyable
WRITEME: Document this method brpocock@star-hope.org

Specified by:
copyProtoype in interface Copyable<Wallet>
Parameters:
prototype - WRITEME
Returns:
self, for chaining
See Also:
Copyable.copyProtoype(org.starhope.appius.util.DataRecord)

get

public BigDecimal get(Currency cu)
Parameters:
cu - currency units
Returns:
amount of the given currency currently held

get

public BigDecimal get(int n)
Check a random currency. really only useful if the wallet contains a single currency. not very advisable.

Parameters:
n - WRITEME
Returns:
WRITEME

getAllCurrency

public Map<String,BigDecimal> getAllCurrency()
WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME

getCacheableID

public int getCacheableID()
                   throws NotFoundException
Description copied from interface: DataRecord
Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.

Specified by:
getCacheableID in interface DataRecord
Returns:
an unique ID number
Throws:
NotFoundException - if the item doesn't have a distinct numeric ID
See Also:
DataRecord.getCacheableID()

getCacheableIdent

public String getCacheableIdent()
                         throws NotFoundException
Description copied from interface: DataRecord
Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.

Specified by:
getCacheableIdent in interface DataRecord
Returns:
an unique identifier string
Throws:
NotFoundException - if the item doesn't have a distinct string identifier
See Also:
DataRecord.getCacheableIdent()

getOwner

private UserRecord getOwner()
WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME

getSubversionRevision

public String getSubversionRevision()
Description copied from interface: HasSubversionRevision

Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.

As an example,the Subversion revision string for this file is "$Rev: 1968 $"

 
 @Override
 public String getSubversionRevision () {
        return "$Rev: ";
 }
 

Specified by:
getSubversionRevision in interface HasSubversionRevision
Returns:
The Subversion revision level for this class's source code file.
See Also:
HasSubversionRevision.getSubversionRevision()

put

public void put(Currency cu,
                BigDecimal amount)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
cu - WRITEME
amount - WRITEME

put

public void put(String cu,
                BigDecimal amount)
Parameters:
cu - currency units
amount - amount of the given currency currently held

setOwner

private void setOwner(UserRecord owner)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
owner - WRITEME

toJSON

public org.json.JSONObject toJSON()
Returns:
the wallet description in JSON