Package fr.marcwrobel.jbanking.bic
Class Bic
java.lang.Object
fr.marcwrobel.jbanking.bic.Bic
- All Implemented Interfaces:
Serializable
A Business Identifier Code (also known as BIC, SWIFT-BIC, BIC code, SWIFT ID or SWIFT code, Business Entity Identifier or
BEI) as specified by ISO 9362:2009.
A BIC is either eight (BIC8) or eleven (BIC11) characters made up of :
- 4 letters: institution code (or bank code)
- 2 letters: ISO 3166-1 alpha-2 country code
- 2 letters or digits: location code
- 3 letters or digits (optional): branch code
Where an 8-digit code is given, it is assumed that it refers to the primary office. The primary office is always designated by the branch code "XXX").
Instances of this class are immutable and thread-safe.
Usage:
// Validate a BIC
Assertions.assertTrue(Bic.isValid("PSSTFRPPXXX"));
// Retrieve BIC information
Bic bic = new Bic("psstfrppxxx");
Assertions.assertEquals("PSSTFRPPXXX", bic.toString());
Assertions.assertEquals("PSST", bic.getInstitutionCode());
Assertions.assertEquals("FR", bic.getCountryCode());
Assertions.assertEquals("PP", bic.getLocationCode());
Assertions.assertEquals("XXX", bic.getBranchCode());
Assertions.assertTrue(bic.isLiveBic());
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternA pre-compiled Pattern forBIC_REGEX.static final StringA simple regex that validate well-formed BIC.static final StringThe branch code for primary offices.static final charIf the last character of the location code in a BIC is this one it means that the BIC is a Test BIC. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionTransform this BIC to a test BIC.booleanIndicates whether some other object is “equal to” this one.Extract the branch code from this BIC.Extract the country code from this BIC.Extract the institution code (or bank code) from this BIC.Extract the location code from this BIC.inthashCode()booleanTest whether this BIC is a live bic.booleanTest whether this BIC is a test bic.static booleanCheck whether the given string is valid BIC.toString()Returns a normalized string representation of this BIC.
-
Field Details
-
BIC_REGEX
A simple regex that validate well-formed BIC.- See Also:
-
BIC_PATTERN
A pre-compiled Pattern forBIC_REGEX. -
PRIMARY_OFFICE_BRANCH_CODE
The branch code for primary offices.- See Also:
-
TEST_BIC_INDICATOR
public static final char TEST_BIC_INDICATORIf the last character of the location code in a BIC is this one it means that the BIC is a Test BIC.- See Also:
-
-
Constructor Details
-
Bic
Create a new bic from the given string.The given string may be a BIC8 or a BIC11.
- Parameters:
bic8Or11- A non-null String.- Throws:
IllegalArgumentException- if the given string isnullBicFormatException- if the given BIC8 or BIC11 string does not matchBIC_REGEXor if the given BIC8 or BIC11 country code is not known inIsoCountry.
-
-
Method Details
-
isValid
Check whether the given string is valid BIC.- Parameters:
bic- A String.- Returns:
trueif the given string is valid BIC, otherwisefalse.
-
getInstitutionCode
Extract the institution code (or bank code) from this BIC.- Returns:
- A non-null string representing this BIC institution code.
-
getCountryCode
Extract the country code from this BIC.- Returns:
- A non-null string representing this BIC country code.
-
getLocationCode
Extract the location code from this BIC.- Returns:
- A non-null string representing this BIC location code.
-
getBranchCode
Extract the branch code from this BIC.- Returns:
- A non-null string representing this BIC branch code.
-
isTestBic
public boolean isTestBic()Test whether this BIC is a test bic.A BIC is a test BIC if the last character of the location code is '0'.
- Returns:
trueif this BIC is a test BIC, otherwisefalse.- See Also:
-
isLiveBic
public boolean isLiveBic()Test whether this BIC is a live bic.A BIC is a live BIC if the last character of the location code is not '0'.
- Returns:
trueif this BIC is a live BIC, otherwisefalse.- See Also:
-
asTestBic
Transform this BIC to a test BIC.- Returns:
- this if this BIC is a test BIC, or this BIC corresponding test BIC otherwise.
-
equals
Indicates whether some other object is “equal to” this one.To be equals to this one the other object must be a
Bicand the BICs normalized form (seetoString()) must be equal. -
hashCode
public int hashCode() -
toString
Returns a normalized string representation of this BIC.Normalized means the string is:
- made of uppercase characters
- eleven characters long (BIC11)
-