Class NotimaUtil

java.lang.Object
org.notima.util.NotimaUtil

public class NotimaUtil extends Object
Author:
Daniel Tamm
  • Constructor Details

    • NotimaUtil

      public NotimaUtil()
  • Method Details

    • toDigitsOnly

      public static String toDigitsOnly(String cleanUp)
      Remove all non digit characters
      Parameters:
      cleanUp - String to be cleaned.
      Returns:
      A cleaned string.
    • hasDigitsOnly

      public static boolean hasDigitsOnly(String ref)
    • removeBlanks

      public static String removeBlanks(String cleanUp)
      Remove blanks from a string. Good for purging for instance IBAN numbers
      Parameters:
      cleanUp - String to clean up.
      Returns:
      A string without blanks.
    • trimLeadingZeros

      public static String trimLeadingZeros(String cleanUp)
    • validateIban

      public static boolean validateIban(String swift, String iban)
      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

      public static boolean validateBankgiro(String Bankgiro)
      Validate Bankgiro
      Parameters:
      Bankgiro - A string containing the bankgiro to be validated.
      Returns:
      true if the bankgiro has passed length test.
    • getAmountStr

      public static String getAmountStr(double amount)
      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

      public static String getAmountStr(double amount, int len, boolean absolute)
      Parameters:
      amount - The amount to be converted.
      len - Let you specify the length of the string
      absolute - 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

      public static double parseAmountStr(String amountStr)
    • 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

      public static int getLuhnDigit(String indata)
      Luhn algoritm.
      Parameters:
      indata - The numbers to calculated a Luhn digit from.
      Returns:
      The luhn digit.
    • toOCRNumber

      public static String toOCRNumber(String indata)
      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

      public static String toOCRNumberWithLengthCheck(String indata)
      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

      public static boolean isValidOCRNumber(String OCR)
      Validate OCR number. - Based on LUHN formula (Modulus10)
      Parameters:
      OCR - The OCR-number to validate
      Returns:
      True if OCR is correct
    • fillToLength

      public static String fillToLength(String str, boolean rightAlign, char fillChar, int len)
      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

      public static String onlyUSASCII(String clearupstring)
      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

      public static int daysFromNow(Date date)
      Returns number of days from today
      Parameters:
      date - Date to check
      Returns:
      The number of days to the given date
    • addDays

      public static Date addDays(Date date, int daysToAdd)
      Adds number of days on specified date
      Parameters:
      date - The date to add to
      daysToAdd - The number of days to add.
      Returns:
      The date after the days have been added.