Package nl.garvelink.iban
Class IBAN
java.lang.Object
nl.garvelink.iban.IBAN
- All Implemented Interfaces:
Serializable
An immutable value type representing an International Bank Account Number. Instances of this class have correct
check digits and a valid length for their country code. No country-specific validation is performed, other than
matching the length of the IBAN to its country code. Unknown country codes are not supported.
- Author:
- Barend Garvelink https://github.com/barend
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<IBAN> A comparator that puts IBAN's into lexicographic ordering, perString.compareTo(String).static final intThe technically shortest possible IBAN. -
Method Summary
Modifier and TypeMethodDescriptionstatic IBANcompose(CharSequence countryCode, CharSequence bban) Composes an IBAN from the given country code and basic bank account number.booleanReturns the check digits of the IBAN.Returns the Country Code embedded in the IBAN.static intgetLengthForCountryCode(String countryCode) Deprecated.inthashCode()booleanReturns whether the source for this IBAN's format and data is the SWIFT IBAN Registry.booleanisSEPA()Returns whether the IBAN's country participates in SEPA.static IBANparse(CharSequence input) Parses the given string into an IBAN object and confirms the check digits.static StringtoPlain(CharSequence input) Removes any spaces contained in the String thereby converting the input into a plain IBANReturns the IBAN without formatting.static StringtoPretty(CharSequence input) Ensures that the input is pretty printed by first removing any spaces the String might contain and then adding spaces in the right places.toString()Returns the IBAN in standard formatting, with a space every four characters.static IBANvalueOf(CharSequence input) Parses the given string into an IBAN object and confirms the check digits, but returns null for null.
-
Field Details
-
LEXICAL_ORDER
A comparator that puts IBAN's into lexicographic ordering, perString.compareTo(String). -
SHORTEST_POSSIBLE_IBAN
public static final int SHORTEST_POSSIBLE_IBANThe technically shortest possible IBAN. SeeCountryCodes.SHORTEST_IBAN_LENGTHfor shortest valid length.- See Also:
-
-
Method Details
-
parse
Parses the given string into an IBAN object and confirms the check digits.- Parameters:
input- the input, which can be either plain ("CC11ABCD123...") or formatted with (ASCII 0x20) space characters ("CC11 ABCD 123. ..").- Returns:
- the parsed and validated IBAN object, never null.
- Throws:
IllegalArgumentException- if the input is null, malformed or otherwise fails validation.- See Also:
-
valueOf
Parses the given string into an IBAN object and confirms the check digits, but returns null for null.- Parameters:
input- the input, which can be either plain ("CC11ABCD123...") or formatted ("CC11 ABCD 123. ..").- Returns:
- the parsed and validated IBAN object, or null.
- Throws:
IllegalArgumentException- if the input is malformed or otherwise fails validation.- See Also:
-
compose
Composes an IBAN from the given country code and basic bank account number.- Parameters:
countryCode- the country code.bban- the BBAN.- Returns:
- an IBAN object composed from the given parts, if valid.
- Throws:
IllegalArgumentException- if either input is null, if the composed IBAN fails validation.- Since:
- 1.9.0
-
getLengthForCountryCode
Deprecated.invokeCountryCodes.getLengthForCountryCode(CharSequence)instead.- Parameters:
countryCode- the country code for which to return the length.- Returns:
- the length of the IBAN for the given country code, or -1 if unknown.
-
getCountryCode
Returns the Country Code embedded in the IBAN.- Returns:
- the two-letter country code.
-
getCheckDigits
Returns the check digits of the IBAN.- Returns:
- the two check digits.
-
isSEPA
public boolean isSEPA()Returns whether the IBAN's country participates in SEPA.- Returns:
- true if SEPA, false if non-SEPA.
-
isInSwiftRegistry
public boolean isInSwiftRegistry()Returns whether the source for this IBAN's format and data is the SWIFT IBAN Registry.- Returns:
- true if from SWIFT IBAN Registry, false if from Experimental IBANs list.
- Since:
- 1.6.0
-
toPlainString
Returns the IBAN without formatting.- Returns:
- the unformatted IBAN number.
-
equals
-
hashCode
public int hashCode() -
toString
Returns the IBAN in standard formatting, with a space every four characters. -
toPlain
Removes any spaces contained in the String thereby converting the input into a plain IBAN- Parameters:
input- possibly pretty printed IBAN- Returns:
- plain IBAN
-
toPretty
Ensures that the input is pretty printed by first removing any spaces the String might contain and then adding spaces in the right places.This can be useful when prompting a user to correct wrong input
- Parameters:
input- plain or pretty printed IBAN- Returns:
- pretty printed IBAN
-
CountryCodes.getLengthForCountryCode(CharSequence)instead.