Coin Purse

The coin purse class is used for representing a coin purse. The purse can hold any number of coin up to a max value if one is defined. It also provides functions for checking if the coin purse has enough coin for a given transaction (adding or removal) and reports how many coins will not fit or how many coins short the purse is.
Return to Index
new ( )
__gc ( )
__eq ( am.coin_purse rhs ) -> ( boolean )
coin ( ) -> ( integer )
coin ( integer coin ) -> ( am.coin_purse )
can_add_coin ( integer coin ) -> ( integer )
can_remove_coin ( integer coin ) -> ( integer )
add_coin ( integer coin ) -> ( am.coin_purse )
remove_coin ( integer coin ) -> ( am.coin_purse )
max_coin ( ) -> ( integer )
max_coin ( integer max_coin ) -> ( am.coin_purse )
new ( )
Creates a new empty coin purse.
__gc ( )
Release the reference count on this coin purse.
__eq ( am.coin_purse rhs ) -> ( boolean )
Compares this coin purse with another coin purse object.
Parameters:
am.coin_purse rhs : The other coin purse to compare with.
Returns:
boolean : True if they are the same coin purse object.
coin ( ) -> ( integer )
Returns the amount of coin in this coin purse.
Returns:
integer : The amount of coin.
coin ( integer coin ) -> ( am.coin_purse )
Sets the amount of coin in this coin purse.
Parameters:
integer coin : The amount of coin to set in this coin purse.
Returns:
am.coin_purse : This
can_add_coin ( integer coin ) -> ( integer )
Returns how many coins will not fit if the given amount were to be added. A result of 0 means that all coins will fit.
Parameters:
integer coin : The amount of coin to test.
Returns:
integer : The amount of coins that won't fit, 0 if all coins will fit.
can_remove_coin ( integer coin ) -> ( integer )
Returns how many coins cannot be taken out of the purse. A value of of zero means that all requested coins can be removed.
Parameters:
integer coin : The number of coins to attempt to take out.
Returns:
integer : The number of coins short.
add_coin ( integer coin ) -> ( am.coin_purse )
Adds the given number of coins to the purse. If the amount of coin won't fit they will be lost. Use can_add_coin to make sure this doesn't happen.
Parameters:
integer coin : The amount of coin to add to the purse.
Returns:
am.coin_purse : This
remove_coin ( integer coin ) -> ( am.coin_purse )
Removes the given number of coins from the purse. If the purse does not have the number of coins then the purse will not go into negative.
Parameters:
integer coin : The amount of coin to remove from the purse.
Returns:
am.coin_purse : This
max_coin ( ) -> ( integer )
Returns the maximum number of coins that this purse can hold. A value of 0 means this purse is unlimited.
Returns:
integer : The number of coin this purse can fit.
max_coin ( integer max_coin ) -> ( am.coin_purse )
Sets the max number of coin this purse can hold. If the maximum is set to 0, then this purse will have unlimited space. If the new maximum is lower than the current number of coin then the additional coins will be lost.
Parameters:
integer max_coin : The new max coin amount.
Returns:
am.coin_purse : This