org.locomotive.util
Class Commerce
java.lang.Object
|
+--org.locomotive.util.Commerce
- public class Commerce
- extends java.lang.Object
This class contains some useful utilities, mostly for dealing with
credits cards, and some for dealing with dollar currency formats.
Method Summary |
static java.lang.String |
cleanUpPrice(java.lang.String price)
Given a price string, make it presentable by adding .00 if it's a
straight integer or adding 0 if it's a 1.6 form. |
static int |
getValueInCentsFromPriceStr(java.lang.String price)
|
static boolean |
isValidCreditCard(long number)
Decide if a given credit card number is in good form or not using Luhn
Checksum algorithm. |
static java.lang.String |
parseCCExpMonth(java.lang.String cc_exp_str)
Given the expiration string of a credit card number, try to
figure out the month. |
static java.lang.String |
parseCCExpYear(java.lang.String cc_exp_str)
Given the expiration string of a credit card number, try to
figure out the year. |
static long |
parseCCNum(java.lang.String cc_str)
Checks basic syntax stuff for a creit card string. |
static java.lang.String |
printPriceFromCentValue(int num_cents)
Pass in an int representing the number of cents (== the number
of dollars * 100), and you'll get back a String representing it in
money format. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Commerce
public Commerce()
isValidCreditCard
public static boolean isValidCreditCard(long number)
- Decide if a given credit card number is in good form or not using Luhn
Checksum algorithm.
Number the digits from right to left, starting at 0. At odd locations
perform i = (2*i)%9. Sum all the digits. sum%10 must be 0.
parseCCNum
public static long parseCCNum(java.lang.String cc_str)
- Checks basic syntax stuff for a creit card string. Takes out -'s,
spaces, and any other non-digit stuff. Does not check max or min
size of the number value (though negative values are not possible since
-'s are removed...). Returns -1 if the number specified is
invalid.
parseCCExpMonth
public static java.lang.String parseCCExpMonth(java.lang.String cc_exp_str)
- Given the expiration string of a credit card number, try to
figure out the month. I made a small improvement to this and
have tested it some. It should work. (Casey)
parseCCExpYear
public static java.lang.String parseCCExpYear(java.lang.String cc_exp_str)
- Given the expiration string of a credit card number, try to
figure out the year. I made a small improvement to this and
have tested it some. It should work. (Casey)
cleanUpPrice
public static java.lang.String cleanUpPrice(java.lang.String price)
- Given a price string, make it presentable by adding .00 if it's a
straight integer or adding 0 if it's a 1.6 form. Does NOT add a $.
Probably should in the future. It's not there because purple moon
is using insertion points and adding their own $ to strings that
this is returning. Ah well. I could make some adapter code but what
the hell. You'll live.
printPriceFromCentValue
public static java.lang.String printPriceFromCentValue(int num_cents)
- Pass in an int representing the number of cents (== the number
of dollars * 100), and you'll get back a String representing it in
money format. ex: if num_cents is 534, then returns "5.34".
if num_cents is negative, will take its absolute value.
getValueInCentsFromPriceStr
public static int getValueInCentsFromPriceStr(java.lang.String price)
throws java.lang.NumberFormatException