Class Bic

java.lang.Object
fr.marcwrobel.jbanking.bic.Bic
All Implemented Interfaces:
Serializable

public final class Bic extends Object implements 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.

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 Details

    • REGEX

      public static final String 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

      public static final String PRIMARY_OFFICE_BRANCH_CODE
      The branch code for primary offices.
      See Also:
    • TEST_BIC_INDICATOR

      public static final char TEST_BIC_INDICATOR
      If 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

  • Method Details

    • isValid

      public static boolean isValid(String s)
      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 be null
      Returns:
      true if the given string is valid BIC, otherwise false
    • getInstitutionCode

      public String getInstitutionCode()
      Extract the institution code (or bank code) from this BIC.
      Returns:
      a non-null string representing this BIC institution code
    • getCountryCode

      public String getCountryCode()
      Extract the country code from this BIC.
      Returns:
      a non-null string representing this BIC country code
    • getCountry

      public IsoCountry getCountry()
      Gets this BIC IsoCountry.
      Returns:
      a non-null IsoCountry
    • getLocationCode

      public String getLocationCode()
      Extract the location code from this BIC.
      Returns:
      a non-null string representing this BIC location code
    • getBranchCode

      public String 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:
      true if this BIC is a test BIC, otherwise false
      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:
      true if this BIC is a live BIC, otherwise false
      See Also:
    • asTestBic

      public Bic 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

      public boolean equals(Object o)
      Indicates whether some other object is “equal to” this one.

      To be equals to this one the other object must be a Bic and the BICs normalized form (see toString()) must be equal.

      Overrides:
      equals in class Object
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the obj argument or false otherwise
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also:
    • toString

      public String toString()
      Returns a normalized string representation of this BIC.

      Normalized means the string is:

      • made of uppercase characters
      • eleven characters long (BIC11)
      Overrides:
      toString in class Object
      Returns:
      a normalized string representation of this BIC