Class 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").

    This class is immutable.

    Since:
    1.0
    Author:
    Marc Wrobel
    See Also:
    http://wikipedia.org/wiki/Bank_Identifier_Code, Serialized Form
    • Field Detail

      • BIC_PATTERN

        public static final Pattern BIC_PATTERN
        A pre-compiled Pattern for BIC_REGEX.
      • PRIMARY_OFFICE_BRANCH_CODE

        public static final String PRIMARY_OFFICE_BRANCH_CODE
        The branch code for primary offices.
        See Also:
        Constant Field Values
      • 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:
        Constant Field Values
    • Constructor Detail

      • Bic

        public Bic​(String bic8Or11)
        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 is null
        BicFormatException - if the given BIC8 or BIC11 string does not match BIC_REGEX or if the given BIC8 or BIC11 country code is not known in IsoCountry.
    • Method Detail

      • isValid

        public static boolean isValid​(String bic)
        Check whether the given string is valid BIC.
        Parameters:
        bic - A String.
        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.
      • 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 48.

        Returns:
        true if this BIC is a test BIC, otherwise false.
        See Also:
        isLiveBic()
      • 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 48.

        Returns:
        true if this BIC is a live BIC, otherwise false.
        See Also:
        isTestBic()
      • 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:
        Object.toString()
      • 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