Class SwiftCharsetUtils


  • public class SwiftCharsetUtils
    extends java.lang.Object
    Helper class to validate SWIFT char sets (named after the SWIFT User Handbook).

    Note that when a SWIFT character set refers to a set of letters, lowercase or uppercase, it means only letters in English. Therefore this implementation does not use the Character API as being Character.isLetter because that would accept letters with internationalization. Instead, the integer values of the characters are used to compare them with the set of allowed characters in each case.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int OK  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String filter​(java.lang.String s, SwiftCharset charset)
      Returns a new string removing all characters that not belong to the parameter charset
      static char[] get_a()
      Gets SWIFT a charset; alphabetic capital letters (A through Z), upper case only.
      static char[] get_A()
      Gets SWIFT A charset; alphabetic, upper case or lower case A through Z, a through z.
      static char[] get_B()
      Gets SWIFT B charset; alphanumeric upper case or lower case A through Z, a through z and 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
      static char[] get_c()
      Gets SWIFT c charset; alpha-numeric capital letters (upper case), and digits only.
      static char[] get_n()
      Gets SWIFT n charset; numeric digits (0 through 9) only.
      static char[] get_x()
      Gets SWIFT x charset; any character of the X permitted set (General FIN application set) upper case and lower case allowed.
      static char[] get_y()
      Gets SWIFT y charset; any character of the Y permitted set (EDI service specific set), upper case only.
      static char[] get_z()
      Gets SWIFT z charset; all characters included in the X and Y sets, plus a couple of special characters.
      static java.lang.String getAsString​(char[] charset)
      Returns a human-friendly description of the charset
      static java.lang.String getAsString​(SwiftCharset charset)
      Returns a human-friendly description of the charset
      static boolean is​(char c, SwiftCharset charset)
      Checks if the character belogs to a given SWIFT charset
      static int is​(java.lang.String s, SwiftCharset charset)
      Checks if the string character belogs to a given SWIFT charset
      static boolean is_a​(char character)
      Returns true if the parameter char is part of the a character set; alphabetic capital letters (A through Z), upper case only
      static int is_a​(java.lang.String s)
      Returns this.OK (-1) if all characters of parameter string are part of the a character set.
      static boolean is_A​(char character)
      Returns true if the parameter char is part of the A character set; alphabetic, upper case or lower case A through Z, a through z
      static int is_A​(java.lang.String s)
      Returns this.OK (-1) if all characters of parameter string are part of the A character set.
      static boolean is_B​(char character)
      Returns true if the parameter char is part of the B character set; alphanumeric upper case or lower case A through Z, a through z and digits
      static int is_B​(java.lang.String s)
      Returns this.OK (-1) if all characters of parameter string are part of the B character set.
      static boolean is_c​(char character)
      Returns true if the parameter char is part of the c character set; alpha-numeric capital letters (upper case), and digits only
      static int is_c​(java.lang.String s)
      Returns this.OK (-1) if all characters of parameter string are part of the c character set.
      static boolean is_n​(char character)
      Returns true if the parameter char is part of the n character set; numeric digits (0 through 9) only
      static int is_n​(java.lang.String s)
      Returns this.OK (-1) if all characters of parameter string are part of the n character set.
      static boolean is_x​(char character)
      Returns true if the parameter char is part of the x character set; any character of the X permitted set (General FIN application set) upper case and lower case allowed
      static int is_x​(java.lang.String s)
      Returns this.OK (-1) if all characters of parameter string are part of the x character set.
      static boolean is_y​(char character)
      Returns true if the parameter char is part of the y character set; any character of the Y permitted set (EDI service specific set), upper case only
      static int is_y​(java.lang.String s)
      Returns this.OK (-1) if all characters of parameter string are part of the y character set.
      static boolean is_z​(char character)
      Returns true if the parameter char is part of the z character set; all characters included in the X and Y sets, plus a couple of special characters
      static int is_z​(java.lang.String s)
      Returns this.OK (-1) if all characters of parameter string are part of the z character set.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • is_n

        public static boolean is_n​(char character)
        Returns true if the parameter char is part of the n character set; numeric digits (0 through 9) only
      • is_n

        public static int is_n​(java.lang.String s)
        Returns this.OK (-1) if all characters of parameter string are part of the n character set. Otherwise returns the position (zero based) of the first invalid character found.
        See Also:
        get_n()
      • is_a

        public static boolean is_a​(char character)
        Returns true if the parameter char is part of the a character set; alphabetic capital letters (A through Z), upper case only
      • is_a

        public static int is_a​(java.lang.String s)
        Returns this.OK (-1) if all characters of parameter string are part of the a character set. Otherwise returns the position (zero based) of the first invalid character found.
        See Also:
        get_a()
      • is_x

        public static boolean is_x​(char character)
        Returns true if the parameter char is part of the x character set; any character of the X permitted set (General FIN application set) upper case and lower case allowed
      • is_x

        public static int is_x​(java.lang.String s)
        Returns this.OK (-1) if all characters of parameter string are part of the x character set. Otherwise returns the position (zero based) of the first invalid character found.
        See Also:
        get_x()
      • is_y

        public static boolean is_y​(char character)
        Returns true if the parameter char is part of the y character set; any character of the Y permitted set (EDI service specific set), upper case only
      • is_y

        public static int is_y​(java.lang.String s)
        Returns this.OK (-1) if all characters of parameter string are part of the y character set. Otherwise returns the position (zero based) of the first invalid character found.
        See Also:
        get_y()
      • is_z

        public static boolean is_z​(char character)
        Returns true if the parameter char is part of the z character set; all characters included in the X and Y sets, plus a couple of special characters
      • is_z

        public static int is_z​(java.lang.String s)
        Returns this.OK (-1) if all characters of parameter string are part of the z character set. Otherwise returns the position (zero based) of the first invalid character found.
        See Also:
        get_z()
      • is_c

        public static boolean is_c​(char character)
        Returns true if the parameter char is part of the c character set; alpha-numeric capital letters (upper case), and digits only
      • is_c

        public static int is_c​(java.lang.String s)
        Returns this.OK (-1) if all characters of parameter string are part of the c character set. Otherwise returns the position (zero based) of the first invalid character found.
        See Also:
        get_c()
      • is_A

        public static boolean is_A​(char character)
        Returns true if the parameter char is part of the A character set; alphabetic, upper case or lower case A through Z, a through z
      • is_A

        public static int is_A​(java.lang.String s)
        Returns this.OK (-1) if all characters of parameter string are part of the A character set. Otherwise returns the position (zero based) of the first invalid character found.
        See Also:
        get_A()
      • is_B

        public static boolean is_B​(char character)
        Returns true if the parameter char is part of the B character set; alphanumeric upper case or lower case A through Z, a through z and digits
      • is_B

        public static int is_B​(java.lang.String s)
        Returns this.OK (-1) if all characters of parameter string are part of the B character set. Otherwise returns the position (zero based) of the first invalid character found.
        See Also:
        get_B()
      • is

        public static int is​(java.lang.String s,
                             SwiftCharset charset)
        Checks if the string character belogs to a given SWIFT charset
        Returns:
        Returns this.OK (-1) if all characters in the string matches a char defined in the charset or the position (zero based) of the first invalid character found
      • is

        public static boolean is​(char c,
                                 SwiftCharset charset)
        Checks if the character belogs to a given SWIFT charset
        Returns:
        true if character matches a char defined in the charset
      • getAsString

        public static java.lang.String getAsString​(SwiftCharset charset)
        Returns a human-friendly description of the charset
        Parameters:
        charset - a list of character defining a charset
        Returns:
        a string describing the charset
      • get_n

        public static char[] get_n()
        Gets SWIFT n charset; numeric digits (0 through 9) only.
      • get_a

        public static char[] get_a()
        Gets SWIFT a charset; alphabetic capital letters (A through Z), upper case only.
      • get_A

        public static char[] get_A()
        Gets SWIFT A charset; alphabetic, upper case or lower case A through Z, a through z.
      • get_x

        public static char[] get_x()
        Gets SWIFT x charset; any character of the X permitted set (General FIN application set) upper case and lower case allowed.
      • get_y

        public static char[] get_y()
        Gets SWIFT y charset; any character of the Y permitted set (EDI service specific set), upper case only.
      • get_z

        public static char[] get_z()
        Gets SWIFT z charset; all characters included in the X and Y sets, plus a couple of special characters.
      • get_c

        public static char[] get_c()
        Gets SWIFT c charset; alpha-numeric capital letters (upper case), and digits only.
      • get_B

        public static char[] get_B()
        Gets SWIFT B charset; alphanumeric upper case or lower case A through Z, a through z and 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
      • getAsString

        public static java.lang.String getAsString​(char[] charset)
        Returns a human-friendly description of the charset
        Parameters:
        charset - a list of character defining a charset
        Returns:
        a string describing the charset
      • filter

        public static java.lang.String filter​(java.lang.String s,
                                              SwiftCharset charset)
        Returns a new string removing all characters that not belong to the parameter charset
        Parameters:
        s - the string to filter
        charset - a charset to match
        Returns:
        a new string with non matching characters removed