Package com.prowidesoftware.swift.utils
Class SwiftFormatUtils
- java.lang.Object
-
- com.prowidesoftware.swift.utils.SwiftFormatUtils
-
public class SwiftFormatUtils extends java.lang.Object
This class provides methods to convert field components to objects. It handles for example; dates, currencies and general functions defined in the SWIFT standard.- DATE1 MMDD
- DATE2 YYMMDD
- DATE3 YYMM
- DATE4 YYYYMMDD
- YEAR YYYY
- AMOUNT ###,### (digits with comma as decimal separator)
- TIME2 HHmmss
- TIME3 HH[mm]
- BOOL Y/N
- DATETIME YYYYMMDDHHMM
- DATETIME with short year YYMMDDHHMM
- DAYTIME DDHHMM
- MONTHDAY MMDD
- MIR
- MOR
- Since:
- 6.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
decimalsInAmount(java.lang.String amountString)
Return the number of decimals for a string with a swift formatted amount.static int
decimalsInAmount(java.math.BigDecimal amount)
Return the number of decimals for the given number, which can be null, in which case this method returns zero.static java.lang.String
getBIC(BIC bic)
Gets the code from the parameter BIC.static BIC
getBIC(java.lang.String code)
static java.math.BigDecimal
getBigDecimal(java.lang.String amount)
Parses a value into a java Number (BigDecimal) using the comma for decimal separator.static java.lang.String
getBigDecimal(java.math.BigDecimal bigDecimal)
Parses a Number into a SWIFT string number ####,## with truncated zero decimals and mandatory decimal separator.static java.lang.String
getBoolean(java.lang.Boolean bool)
Parses a Boolean object into a string.static java.lang.Boolean
getBoolean(java.lang.String string)
Gets the given string as boolean.static java.util.Currency
getCurrency(java.lang.String code)
Returns theCurrency
instance for the given currency code.static java.lang.String
getCurrency(java.util.Currency currency)
Gets the currency code from the parameter Currency.static java.util.Calendar
getDate1(java.lang.String strDate)
Parses a DATE1 string (accept dates in format MMDD) into a Calendar object.static java.lang.String
getDate1(java.util.Calendar date)
Parses a Calendar object into a DATE1 string.static java.util.Calendar
getDate2(java.lang.String strDate)
Parses a DATE2 string (accept dates in format YYMMDD) into a Calendar object.static java.lang.String
getDate2(java.util.Calendar date)
Parses a Calendar object into a DATE2 string.static java.util.Calendar
getDate3(java.lang.String strDate)
Parses a DATE3 string (accept dates in format YYMM) into a Calendar object.static java.lang.String
getDate3(java.util.Calendar date)
Parses a Calendar object into a DATE1 string.static java.util.Calendar
getDate4(java.lang.String strDate)
Parses a DATE4 string (accept dates in format YYYYMMDD) into a Calendar object.static java.lang.String
getDate4(java.util.Calendar date)
Parses a Calendar object into a DATE1 string.static java.util.Calendar
getDateTime(java.lang.String strDate)
Parses a DATETIME string (accepts dates with time in YYYYMMDDHHMM format) into a Calendar object.static java.lang.String
getDateTime(java.util.Calendar date)
Parses a Calendar object into a string containing the DATETIME with YYYYMMDDHHMM format.static java.util.Calendar
getDateTimeShortYear(java.lang.String strDate)
Parses a DATETIME with short year string (accepts dates with time in YYMMDDHHMM format) into a Calendar object.static java.lang.String
getDateTimeShortYear(java.util.Calendar date)
Parses a Calendar object into a DATETIME with short year string in YYMMDDHHMM format.static java.util.Calendar
getDayTime(java.lang.String strDate)
Parses a DAYTIME string (accepts dates with time in DDHHMM format) into a Calendar object.static java.lang.String
getDayTime(java.util.Calendar date)
Parses a Calendar object into a string containing the DAYTIME in DDHHMM format.static java.util.Calendar
getHhmm(java.lang.String hhmm)
Converts the given time into a Calendar.static java.util.Calendar
getHour(java.lang.String strDate)
Parses an HOUR string (accepts time in HH format) into a Calendar object.static java.lang.String
getHour(java.util.Calendar date)
Parses a Calendar object into a string containing the HOUR in HH format.static java.lang.String
getLong(java.lang.Long number)
Converts a Long into a SWIFT string numberstatic java.lang.Long
getLong(java.lang.String value)
Parses a value into a java Number (BigDecimal) using the comma for decimal separator.static java.lang.String
getLTAddress(LogicalTerminalAddress address)
Gets the code from the parameter LogicalTerminalAddress.static LogicalTerminalAddress
getLTAddress(java.lang.String address)
static java.lang.String
getMIR(MIR mir)
Parses a MIR object into a string containing its serialized data.static MIR
getMIR(java.lang.String value)
Parses a string value into a MIR object.static java.util.Calendar
getMonthDay(java.lang.String strDate)
Parses a MONTHDAY string (accepts dates in MMDD format) into a Calendar object.static java.lang.String
getMonthDay(java.util.Calendar date)
Parses a Calendar object into a string containing MONTHDAY in MMDD format.static java.lang.String
getMOR(MOR mor)
Parses a MOR object into a string containing its serialized data.static MOR
getMOR(java.lang.String value)
Parses a string value into a MOR object.static java.lang.String
getNumber(java.lang.Number number)
Parses a Number into a SWIFT string number ####,## with truncated zero decimals and mandatory decimal separator.static java.lang.Number
getNumber(java.lang.String amount)
Parses a value into a java Number (BigDecimal) using the comma for decimal separator.static java.util.Calendar
getOffset(java.lang.String string)
static java.lang.String
getOffset(java.util.Calendar date)
Parses a Calendar object into a offset string.static java.lang.Character
getSign(java.lang.String string)
static java.util.Calendar
getTime2(java.lang.String hhmmss)
Converts the given time into a Calendar.static java.lang.String
getTime2(java.util.Calendar date)
Parses a Calendar object into a TIME2 string.static java.util.Calendar
getTime3(java.lang.String hhmmss)
Converts the given time into a Calendar.static java.lang.String
getTime3(java.util.Calendar date)
Parses a Calendar object into a TIME3 string.static java.util.Calendar
getYear(java.lang.String strDate)
Parses a YEAR string (accept dates in format YYYY) into a Calendar object.static java.lang.String
getYear(java.util.Calendar date)
Parses a Calendar object into a YYYY string.static boolean
isLeapYear(int year)
returns true if the parameter year is a leap year
-
-
-
Method Detail
-
getDate2
public static java.util.Calendar getDate2(java.lang.String strDate)
Parses a DATE2 string (accept dates in format YYMMDD) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
-
getDate2
public static java.lang.String getDate2(java.util.Calendar date)
Parses a Calendar object into a DATE2 string.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
-
getDate1
public static java.util.Calendar getDate1(java.lang.String strDate)
Parses a DATE1 string (accept dates in format MMDD) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
- See Also:
getMonthDay(String)
-
isLeapYear
public static boolean isLeapYear(int year)
returns true if the parameter year is a leap year- Since:
- 7.8.8
-
getDate1
public static java.lang.String getDate1(java.util.Calendar date)
Parses a Calendar object into a DATE1 string.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 6.4
- See Also:
getMonthDay(Calendar)
-
getDate3
public static java.util.Calendar getDate3(java.lang.String strDate)
Parses a DATE3 string (accept dates in format YYMM) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
-
getDate3
public static java.lang.String getDate3(java.util.Calendar date)
Parses a Calendar object into a DATE1 string.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 6.4
-
getDate4
public static java.util.Calendar getDate4(java.lang.String strDate)
Parses a DATE4 string (accept dates in format YYYYMMDD) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
-
getDate4
public static java.lang.String getDate4(java.util.Calendar date)
Parses a Calendar object into a DATE1 string.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 6.4
-
getYear
public static java.util.Calendar getYear(java.lang.String strDate)
Parses a YEAR string (accept dates in format YYYY) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
-
getYear
public static java.lang.String getYear(java.util.Calendar date)
Parses a Calendar object into a YYYY string.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 6.4
-
getLong
public static java.lang.Long getLong(java.lang.String value)
Parses a value into a java Number (BigDecimal) using the comma for decimal separator.- Parameters:
value
- to parse- Returns:
- Long of the parsed value or null if the number could not be parsed
-
getLong
public static java.lang.String getLong(java.lang.Long number)
Converts a Long into a SWIFT string number- Parameters:
number
- to convert- Returns:
- String representation of the converted number
-
getNumber
public static java.lang.Number getNumber(java.lang.String amount)
Parses a value into a java Number (BigDecimal) using the comma for decimal separator.- Parameters:
amount
- to parse- Returns:
- Number of the parsed amount or null if the number could not be parsed
-
getNumber
public static java.lang.String getNumber(java.lang.Number number)
Parses a Number into a SWIFT string number ####,## with truncated zero decimals and mandatory decimal separator.- Example: 1234.00 -> 1234,
- Example: 1234 -> 1234,
- Example: 1234.56 -> 1234,56
- Parameters:
number
- to parse- Returns:
- Number of the parsed amount or null if the number is null
-
getBigDecimal
public static java.math.BigDecimal getBigDecimal(java.lang.String amount)
Parses a value into a java Number (BigDecimal) using the comma for decimal separator.- Parameters:
amount
- to parse- Returns:
- Number of the parsed amount or null if the number could not be parsed
-
getBigDecimal
public static java.lang.String getBigDecimal(java.math.BigDecimal bigDecimal)
Parses a Number into a SWIFT string number ####,## with truncated zero decimals and mandatory decimal separator.- Example: 1234.00 -> 1234,
- Example: 1234 -> 1234,
- Example: 1234.56 -> 1234,56
- Parameters:
bigDecimal
- to parse- Returns:
- Number of the parsed amount or null if the number is null
-
getHhmm
public static java.util.Calendar getHhmm(java.lang.String hhmm)
Converts the given time into a Calendar. Only the time information is set, the date will be the default 1/1/70- Parameters:
hhmm
- hour and minutes- Returns:
- a Calendar set with the given hour and minutes
-
getTime2
public static java.util.Calendar getTime2(java.lang.String hhmmss)
Converts the given time into a Calendar. Only the time information is set, the date will be the default 1/1/70- Parameters:
hhmmss
- hour, minutes and seconds- Returns:
- a Calendar set with the given hour, minutes and seconds
-
getTime2
public static java.lang.String getTime2(java.util.Calendar date)
Parses a Calendar object into a TIME2 string.- Parameters:
date
- Calendar to parse- Returns:
- parsed time or null if the calendar is null
- Since:
- 6.4
-
getTime3
public static java.util.Calendar getTime3(java.lang.String hhmmss)
Converts the given time into a Calendar. Only the time information is set, the date will be the default 1/1/70- Parameters:
hhmmss
- hour, minutes and seconds- Returns:
- a Calendar set with the given hour, or and hour and minutes
-
getTime3
public static java.lang.String getTime3(java.util.Calendar date)
Parses a Calendar object into a TIME3 string.- Parameters:
date
- Calendar to parse- Returns:
- parsed time or null if the calendar is null
- Since:
- 6.4
-
getSign
public static java.lang.Character getSign(java.lang.String string)
- Parameters:
string
- with a single character- Returns:
- the Character for the given string
-
getOffset
public static java.util.Calendar getOffset(java.lang.String string)
- Parameters:
string
- with an offset- Returns:
- a Calendar set with hour and minutes from the offset
-
getOffset
public static java.lang.String getOffset(java.util.Calendar date)
Parses a Calendar object into a offset string.- Parameters:
date
- Calendar to parse- Returns:
- parsed time or null if the calendar is null
- Since:
- 6.4
-
getCurrency
public static java.util.Currency getCurrency(java.lang.String code)
Returns theCurrency
instance for the given currency code.- Parameters:
code
- string with a currency code- Returns:
- a Currency initialized from the parameter code or null if parameter code is null
- Throws:
java.lang.IllegalArgumentException
- if currencyCode is not a supported ISO 4217 code.
-
getCurrency
public static java.lang.String getCurrency(java.util.Currency currency)
Gets the currency code from the parameter Currency.- Parameters:
currency
- Currency to use- Returns:
- the string with the currency code
- Since:
- 6.4
-
getBIC
public static BIC getBIC(java.lang.String code)
- Parameters:
code
- string with a BIC code- Returns:
- a BIC initialized from the parameter code
-
getBIC
public static java.lang.String getBIC(BIC bic)
Gets the code from the parameter BIC. If branch is present, returns a BIC11, otherwise returns a BIC8.- Parameters:
bic
- BIC to use- Returns:
- the string with the BIC code
- Since:
- 6.4
-
getBoolean
public static java.lang.Boolean getBoolean(java.lang.String string)
Gets the given string as boolean.- Parameters:
string
- code to use where the expected values are "Y" or "N"- Returns:
- true for "Y", false for "N", and null otherwise
- Since:
- 7.4
-
getBoolean
public static java.lang.String getBoolean(java.lang.Boolean bool)
Parses a Boolean object into a string.- Parameters:
bool
- Boolean to parse- Returns:
- parsed boolean converted to "Y" or "N" or null if the boolean object is null
- Since:
- 7.4
-
getDateTime
public static java.util.Calendar getDateTime(java.lang.String strDate)
Parses a DATETIME string (accepts dates with time in YYYYMMDDHHMM format) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
- Since:
- 7.4
-
getDateTime
public static java.lang.String getDateTime(java.util.Calendar date)
Parses a Calendar object into a string containing the DATETIME with YYYYMMDDHHMM format.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 7.4
-
getDateTimeShortYear
public static java.util.Calendar getDateTimeShortYear(java.lang.String strDate)
Parses a DATETIME with short year string (accepts dates with time in YYMMDDHHMM format) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
- Since:
- 7.4
-
getDateTimeShortYear
public static java.lang.String getDateTimeShortYear(java.util.Calendar date)
Parses a Calendar object into a DATETIME with short year string in YYMMDDHHMM format.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 7.4
-
getDayTime
public static java.util.Calendar getDayTime(java.lang.String strDate)
Parses a DAYTIME string (accepts dates with time in DDHHMM format) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
- Since:
- 7.4
-
getDayTime
public static java.lang.String getDayTime(java.util.Calendar date)
Parses a Calendar object into a string containing the DAYTIME in DDHHMM format.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 7.4
-
getMonthDay
public static java.util.Calendar getMonthDay(java.lang.String strDate)
Parses a MONTHDAY string (accepts dates in MMDD format) into a Calendar object.The year is set to the current year. The implementation will log a warning and return null if 0229 is passed as argument and the current year is not a leap year.
- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
- Since:
- 7.4
-
getMonthDay
public static java.lang.String getMonthDay(java.util.Calendar date)
Parses a Calendar object into a string containing MONTHDAY in MMDD format. For February 29 it will return null if current year is not a leap year.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 7.4
-
getHour
public static java.util.Calendar getHour(java.lang.String strDate)
Parses an HOUR string (accepts time in HH format) into a Calendar object.- Parameters:
strDate
- string to parse- Returns:
- parsed date or null if the argument did not matched the expected date format
- Since:
- 7.4
-
getHour
public static java.lang.String getHour(java.util.Calendar date)
Parses a Calendar object into a string containing the HOUR in HH format.- Parameters:
date
- Calendar to parse- Returns:
- parsed date or null if the calendar is null
- Since:
- 7.4
-
getMIR
public static MIR getMIR(java.lang.String value)
Parses a string value into a MIR object.- Parameters:
value
- string containing the complete MIR value- Returns:
- a MIR object containing the parsed data or null if the argument is not a 28 length string with a proper MIR data
- See Also:
MIR
-
getMIR
public static java.lang.String getMIR(MIR mir)
Parses a MIR object into a string containing its serialized data.- Parameters:
mir
- MIR to process- Returns:
- serialized content of the MIR object or null if the parameter is empty or null
- Since:
- 7.4
- See Also:
MIR.getMIR()
-
getMOR
public static MOR getMOR(java.lang.String value)
Parses a string value into a MOR object.- Parameters:
value
- string containing the complete MOR value- Returns:
- a MOR object containing the parsed data or null if the argument is not a 28 length string with a proper MOR data
- See Also:
MOR
-
getMOR
public static java.lang.String getMOR(MOR mor)
Parses a MOR object into a string containing its serialized data.- Parameters:
mor
- MOR to process- Returns:
- serialized content of the MOR object or null if the parameter is empty or null
- Since:
- 7.4
- See Also:
MOR.getMOR()
-
decimalsInAmount
public static int decimalsInAmount(java.lang.String amountString)
Return the number of decimals for a string with a swift formatted amount.- Parameters:
amountString
- may be null or empty, in which case this method returns 0- Returns:
- the number of digits after the last , or 0 in any other case.
- Since:
- 7.8
-
decimalsInAmount
public static int decimalsInAmount(java.math.BigDecimal amount)
Return the number of decimals for the given number, which can be null, in which case this method returns zero.- Returns:
- the number of decimal in the number or zero if there are none or the amount is null
- Since:
- 7.8
-
getLTAddress
public static LogicalTerminalAddress getLTAddress(java.lang.String address)
- Parameters:
address
- string with a LT identifier code (12 chars) composed by the BIC, LT identifier and branch.- Returns:
- a LT address initialized from the parameter code
- Since:
- 7.8.8
-
getLTAddress
public static java.lang.String getLTAddress(LogicalTerminalAddress address)
Gets the code from the parameter LogicalTerminalAddress. If the address is not complete, it will be filled with default values usingLogicalTerminalAddress.getSenderLogicalTerminalAddress()
- Parameters:
address
- LT address to use- Returns:
- the string with the full 12 characters long LT identifier
- Since:
- 7.8.8
-
-