Class CreditorIdentifier
- All Implemented Interfaces:
Serializable
The CI structure is:
- Position 1-2 filled with the ISO country code.
- Position 3-4 filled with the check digit according to ISO 7064 Mod 97-10.
- Position 5-7 filled with the Creditor Business Code, if not used then filled with ZZZ.
- Position 8 onwards filled with the country specific part of the identifier being a national identifier of the Creditor, as defined by the National Community.
This class handles validation of the check digit and validation of the Creditor Identifier Structure described above without going into the validation of the national identifier.
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 creditor identifier
Assertions.assertTrue(CreditorIdentifier.isValid(" fr72zzz123456 "));
// Get creditor identifier information
CreditorIdentifier ci = new CreditorIdentifier(" fr72zzz123456 ");
Assertions.assertEquals("FR72ZZZ123456", ci.toString());
Assertions.assertEquals("FR", ci.getCountryCode());
Assertions.assertEquals("72", ci.getCheckDigit());
Assertions.assertEquals("ZZZ", ci.getBusinessCode());
Assertions.assertEquals("123456", ci.getNationalIdentifier());
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreditorIdentifier(IsoCountry country, String businessCode, String nationalId) Create a new Creditor Identifier from the given country code, the creditor business code and the creditor national identifier.Create a new Creditor Identifier from the given string. -
Method Summary
Modifier and TypeMethodDescriptionbooleanExtract the business code from this Creditor Identifier.Extract the check digit from this Creditor Identifier.Gets this Creditor IdentifierIsoCountry.Extract the ISO 3166-1-alpha-2 country code from this Creditor Identifier.Extract the creditor national identifier from this Creditor Identifier.inthashCode()static booleanCheck whether the given string is a valid creditor identifier.toString()Returns a normalized string representation of this Creditor Identifier.
-
Field Details
-
REGEX
A simple regex that validate well-formed Creditor Identifiers.All strings accepted by
isValid(String)are also accepted by this regex.- See Also:
-
-
Constructor Details
-
CreditorIdentifier
Create a new Creditor Identifier from the given string.This method is neither sensitive to the case nor to the presence of leading or trailing spaces.
- Parameters:
s- a non-null string- Throws:
IllegalArgumentException- if the given string isnullCreditorIdentifierFormatException- if the given string does not match "\\s*[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{3}[a-zA-Z0-9]+\\s*" or if its country code is not known inIsoCountryor if its check digit is wrong
-
CreditorIdentifier
Create a new Creditor Identifier from the given country code, the creditor business code and the creditor national identifier.This method is neither sensitive to the case nor to the presence of leading or trailing spaces.
- Parameters:
country- a non-null IsoCountrybusinessCode- a non-null stringnationalId- a non-null string- Throws:
IllegalArgumentException- if either of the given strings is nullCreditorIdentifierFormatException- if the resulting creditor identifier does not match "\\s*[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{3}[a-zA-Z0-9]+\\s*"
-
-
Method Details
-
isValid
Check whether the given string is a valid creditor identifier.This method is neither sensitive to the case nor to the presence of leading or trailing spaces.
- Parameters:
s- a string, may benull- Returns:
trueif the given String is a valid Creditor Identifier,falseotherwise
-
getCountryCode
Extract the ISO 3166-1-alpha-2 country code from this Creditor Identifier.- Returns:
- a non-null string representing this Creditor Identifier ISO 3166-1-alpha-2 country code
-
getCountry
Gets this Creditor IdentifierIsoCountry.- Returns:
- a non-null
IsoCountry
-
getCheckDigit
Extract the check digit from this Creditor Identifier.- Returns:
- a non-null string representing this Creditor Identifier check digit
-
getBusinessCode
Extract the business code from this Creditor Identifier.- Returns:
- a non-null string representing this Creditor Identifier business code
-
getNationalIdentifier
Extract the creditor national identifier from this Creditor Identifier.- Returns:
- a non-null string representing this Creditor Identifier National ID
-
toString
Returns a normalized string representation of this Creditor Identifier.Normalized means the string is:
- made of uppercase characters
- contains no spaces
-
equals
-
hashCode
public int hashCode()
-