Package org.notima.util
Class NotimaUtil
java.lang.Object
org.notima.util.NotimaUtil
- Author:
- Daniel Tamm
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DateAdds number of days on specified datestatic intdaysFromNow(Date date) Returns number of days from todaystatic StringfillToLength(String str, boolean rightAlign, char fillChar, int len) Fills to a specified lengthstatic StringgetAmountStr(double amount) Converts a double to 12 digits where the two last digits are "öre" or "cents".static StringgetAmountStr(double amount, int len, boolean absolute) static intgetLuhnDigit(double amount) Return Luhn Digit using an amount as in datastatic intgetLuhnDigit(String indata) Luhn algoritm.static booleanhasDigitsOnly(String ref) static booleanisValidOCRNumber(String OCR) Validate OCR numberstatic StringonlyUSASCII(String clearupstring) Removes all non USASCII chars and converts to uppercase.static doubleparseAmountStr(String amountStr) static StringremoveBlanks(String cleanUp) Remove blanks from a string.static StringtoDigitsOnly(String cleanUp) Remove all non digit charactersstatic StringtoOCRNumber(String indata) Converts a string of digits to the equivalent OCR-numberstatic StringtoOCRNumberWithLengthCheck(String indata) Converts a string of digits to an OCR-number with length checkstatic StringtrimLeadingZeros(String cleanUp) static booleanvalidateBankgiro(String Bankgiro) Validate Bankgirostatic booleanvalidateIban(String swift, String iban) Perform very basic validation (length checks)
-
Constructor Details
-
NotimaUtil
public NotimaUtil()
-
-
Method Details
-
toDigitsOnly
Remove all non digit characters- Parameters:
cleanUp- String to be cleaned.- Returns:
- A cleaned string.
-
hasDigitsOnly
-
removeBlanks
Remove blanks from a string. Good for purging for instance IBAN numbers- Parameters:
cleanUp- String to clean up.- Returns:
- A string without blanks.
-
trimLeadingZeros
-
validateIban
Perform very basic validation (length checks)- Parameters:
swift- Swift to be validated.iban- Iban to be validated.- Returns:
- True if the IBAN passes a basic validation
-
validateBankgiro
Validate Bankgiro- Parameters:
Bankgiro- A string containing the bankgiro to be validated.- Returns:
- true if the bankgiro has passed length test.
-
getAmountStr
Converts a double to 12 digits where the two last digits are "öre" or "cents". Negative amounts are returned as absolute (no negative indicator)- Parameters:
amount- The amount to be formatted.- Returns:
- A string representation of an amount in BG-format.
-
getAmountStr
- Parameters:
amount- The amount to be converted.len- Let you specify the length of the stringabsolute- If true no negative indicator. If false the last digit is replaced with a letter according to a specific pattern to indicate a negative value.- Returns:
- The amount in string representation
-
parseAmountStr
-
getLuhnDigit
public static int getLuhnDigit(double amount) Return Luhn Digit using an amount as in data- Parameters:
amount- The amount- Returns:
- The luhn digit associated with the amount.
-
getLuhnDigit
Luhn algoritm.- Parameters:
indata- The numbers to calculated a Luhn digit from.- Returns:
- The luhn digit.
-
toOCRNumber
Converts a string of digits to the equivalent OCR-number- Parameters:
indata- The data to be converted- Returns:
- An OCR number with a checkdigit.
-
toOCRNumberWithLengthCheck
Converts a string of digits to an OCR-number with length check- Parameters:
indata- Numbers to be converted.- Returns:
- OCR-number with luhn digit and length check.
-
isValidOCRNumber
Validate OCR number. - Based on LUHN formula (Modulus10)- Parameters:
OCR- The OCR-number to validate- Returns:
- True if OCR is correct
-
fillToLength
Fills to a specified length- Parameters:
str- The string to be filled. If null it will be filled only with fillChar.rightAlign- If the string should be right aligned.fillChar- The char to fill.len- Lenght to fill. If str is more than len, str is truncated.- Returns:
- A string filled ackording to the given parameters.
-
onlyUSASCII
Removes all non USASCII chars and converts to uppercase. Swedish characters ÅÄÖ are replaced with A and O.- Parameters:
clearupstring- The string to be cleared.- Returns:
- A string containing only ASCII
-
daysFromNow
Returns number of days from today- Parameters:
date- Date to check- Returns:
- The number of days to the given date
-
addDays
Adds number of days on specified date- Parameters:
date- The date to add todaysToAdd- The number of days to add.- Returns:
- The date after the days have been added.
-