Class Bic
- All Implemented Interfaces:
Serializable
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.
This class implements Serializable for convenience, but you are encouraged to use the normalized string representation if possible. Note that no validity check is done during deserialization.
Usage:
// Validate a BIC
Assertions.assertTrue(Bic.isValid(" psstfrppxxx "));
// Get 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
Fields -
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.Gets this BICIsoCountry.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 a valid BIC.toString()Returns a normalized string representation of this BIC.
-
Field Details
-
REGEX
A simple regex that validate well-formed BICs.All strings accepted by
isValid(String)are also accepted by this regex.- See Also:
-
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.This method is neither sensitive to the case nor to the presence of leading or trailing spaces. The given string may be a BIC8 or a BIC11.
- Parameters:
s- a non-null string- Throws:
IllegalArgumentException- if the given string isnullBicFormatException- if the given string does not match "\\s*[a-zA-Z]{4}[a-zA-Z]{2}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?\\s*" or if its country code is not known inIsoCountry
-
-
Method Details
-
isValid
Check whether the given string is a valid BIC.This method is neither sensitive to the case nor to the presence of leading or trailing spaces. The given string may be a BIC8 or a BIC11.
- Parameters:
s- a string, may benull- 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
-
getCountry
Gets this BICIsoCountry.- Returns:
- a non-null
IsoCountry
-
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)
-