Class SwiftParseUtils


  • public class SwiftParseUtils
    extends java.lang.Object
    This class provides methods to parse field components.
    Since:
    6.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getAlphaPrefix​(java.lang.String value)
      Returns the alphabetic starting substring of the value.
      static java.lang.String getAlphaPrefixTrimSlash​(java.lang.String value)
      Same as getAlphaPrefix(String) but if the result consist only of slash characters, then null is returned.
      static java.lang.String getAlphaSuffix​(java.lang.String value)
      Returns the alpha suffix of the value.
      static java.util.List<java.lang.String> getLines​(java.lang.String value)
      Separate the given string in lines, removing trailing empty lines.
      static java.lang.String getNumericPrefix​(java.lang.String value)
      Returns the numeric starting substring of the value.
      static java.lang.String getNumericSuffix​(java.lang.String value)
      Returns the numeric suffix of the value.
      static java.lang.String getTokenFirst​(java.lang.String line, java.lang.String separator)  
      static java.lang.String getTokenFirst​(java.lang.String line, java.lang.String starting, java.lang.String separator)
      Split components of a line with an optional starting string and a component separator and returns the first token found or null if the string without starting substring is empty or null.
      This method does not validate the starting string presence, it just strips it if present.
      static java.lang.String getTokenForth​(java.lang.String line, java.lang.String separator)
      Split components of a line using the parameter separator and returns the forth token found or null if forth component is missing.
      static java.lang.String getTokenForthLast​(java.lang.String line, java.lang.String separator)
      Split components of a line using the parameter separator and returns the forth token found or null if forth component is missing.
      static java.lang.String getTokenSecond​(java.lang.String line, java.lang.String separator)
      Split components of a line using the parameter separator and returns the second token found or null if second component is missing.
      static java.lang.String getTokenSecond​(java.lang.String line, java.lang.String starting, java.lang.String separator)
      Split components of a line with an optional starting string and a component separator and returns the second token found or null if the string without starting substring is empty or null.
      This method does not validate the starting string presence, it just strips it if present.
      static java.lang.String getTokenSecondLast​(java.lang.String line, java.lang.String separator)
      Split components of a line using the parameter separator and returns the second token found or null if second component is missing.
      static java.lang.String getTokenSecondLast​(java.lang.String line, java.lang.String starting, java.lang.String separator)
      Split components of a line with an optional starting string and a component separator and returns the second token found or null if the string without starting substring is empty or null.
      static java.lang.String getTokenThird​(java.lang.String line, java.lang.String separator)
      Split components of a line using the parameter separator and returns the third token found or null if third component is missing.
      static java.lang.String getTokenThirdLast​(java.lang.String line, java.lang.String separator)
      Split components of a line using the parameter separator and returns the third token found or null if third component is missing.
      static boolean isAllAsciiDigits​(java.lang.String value)
      Checks if a string contains only ASCII digits
      static java.lang.String removePrefix​(java.lang.String value, java.lang.String prefix)  
      static void setComponentsFromLines​(Field f, int startingComponentNumber, java.lang.Integer linesToSet, int startingLine, java.util.List<java.lang.String> lines)
      Populates a multiline field with content from an array of Strings.
      static void setComponentsFromTokens​(Field f, int startingComponentNumber, int componentsToSet, int tokenSize, java.lang.String value)
      Populates field with content from of a String splited into fixed length tokens.
      static java.util.List<java.lang.String> splitComponents​(java.lang.String line, java.lang.String starting, java.lang.String separator)
      Split components of a line, with an optional starting string and a component separator.
      • Methods inherited from class java.lang.Object

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

      • isAllAsciiDigits

        public static boolean isAllAsciiDigits​(java.lang.String value)
        Checks if a string contains only ASCII digits
        Parameters:
        value - the value to check
        Returns:
        true if all the characters are ASCII digits, false otherwise
      • splitComponents

        public static java.util.List<java.lang.String> splitComponents​(java.lang.String line,
                                                                       java.lang.String starting,
                                                                       java.lang.String separator)
        Split components of a line, with an optional starting string and a component separator. Adjacent separators are treated as one separator. This method does not validate the starting string presence, it just strips it if present. this methods uses StringUtils.splitByWholeSeparator(String, String)
        Parameters:
        line - the string to parse
        starting - an optional starting string
        separator - the components separator
        Returns:
        a list of String with the found components or an empty list if none is found
      • getTokenFirst

        public static java.lang.String getTokenFirst​(java.lang.String line,
                                                     java.lang.String starting,
                                                     java.lang.String separator)
        Split components of a line with an optional starting string and a component separator and returns the first token found or null if the string without starting substring is empty or null.
        This method does not validate the starting string presence, it just strips it if present.
        Returns:
        the first token found or null
      • getTokenFirst

        public static java.lang.String getTokenFirst​(java.lang.String line,
                                                     java.lang.String separator)
        Returns:
        found token
        See Also:
        getTokenFirst(String, String, String)
      • removePrefix

        public static java.lang.String removePrefix​(java.lang.String value,
                                                    java.lang.String prefix)
        Returns:
        s
      • getTokenSecond

        public static java.lang.String getTokenSecond​(java.lang.String line,
                                                      java.lang.String separator)
        Split components of a line using the parameter separator and returns the second token found or null if second component is missing. Two adjacent separators are NOT treated as one.
        Examples with slash as separator:
        • for the literal "abc//def/ghi" will return null.
        • for the literal "abc/foo/def" will return "foo".
        • for the literal "abc/foo/def/ghi" will return "foo".
        Returns:
        s
      • getTokenSecondLast

        public static java.lang.String getTokenSecondLast​(java.lang.String line,
                                                          java.lang.String separator)
        Split components of a line using the parameter separator and returns the second token found or null if second component is missing. Two adjacent separators are NOT treated as one. The second component is assumed as the last one so its content may have additional separators if present.
        Examples with slash as separator:
        • for the literal "abc//def/ghi" will return null.
        • for the literal "abc/foo" will return "foo".
        • for the literal "abc/foo/def/ghi" will return "foo/def/ghi".
        Returns:
        s
      • getTokenSecond

        public static java.lang.String getTokenSecond​(java.lang.String line,
                                                      java.lang.String starting,
                                                      java.lang.String separator)
        Split components of a line with an optional starting string and a component separator and returns the second token found or null if the string without starting substring is empty or null.
        This method does not validate the starting string presence, it just strips it if present.
        Returns:
        the second token found or null
        Since:
        7.4
      • getTokenSecondLast

        public static java.lang.String getTokenSecondLast​(java.lang.String line,
                                                          java.lang.String starting,
                                                          java.lang.String separator)
        Split components of a line with an optional starting string and a component separator and returns the second token found or null if the string without starting substring is empty or null.
        Two adjacent separators are NOT treated as one. The second component is assumed as the last one so its content may have additional separators if present.
        This method does not validate the starting string presence, it just strips it if present.
        Returns:
        the second token found or null
        Since:
        7.4
      • getTokenThird

        public static java.lang.String getTokenThird​(java.lang.String line,
                                                     java.lang.String separator)
        Split components of a line using the parameter separator and returns the third token found or null if third component is missing. Two adjacent separators are NOT treated as one.
        Examples with slash as separator:
        • for the literal "abc/def//ghi" will return null.
        • for the literal "abc/foo" will return "null".
        • for the literal "abc/def/foo" will return "foo".
        • for the literal "abc/def/foo/ghi" will return "foo".
        Returns:
        s
      • getTokenThirdLast

        public static java.lang.String getTokenThirdLast​(java.lang.String line,
                                                         java.lang.String separator)
        Split components of a line using the parameter separator and returns the third token found or null if third component is missing. Two adjacent separators are NOT treated as one. The third component is assumed as the last one so its content may have additional separators if present.
        Examples with slash as separator:
        • for the literal "abc/def//ghi" will return null.
        • for the literal "abc/foo" will return "null".
        • for the literal "abc/def/foo" will return "foo".
        • for the literal "abc/def/foo/ghi" will return "foo/ghi".
        Returns:
        s
      • getTokenForth

        public static java.lang.String getTokenForth​(java.lang.String line,
                                                     java.lang.String separator)
        Split components of a line using the parameter separator and returns the forth token found or null if forth component is missing. Two adjacent separators are NOT treated as one.
        Examples with slash as separator:
        • for the literal "abc/def/ghi//ghi" will return null.
        • for the literal "abc/foo/ghi" will return "null".
        • for the literal "abc/def/ghi/foo" will return "foo".
        • for the literal "abc/def/ghi/foo/ghi" will return "foo".
        Returns:
        s
      • getTokenForthLast

        public static java.lang.String getTokenForthLast​(java.lang.String line,
                                                         java.lang.String separator)
        Split components of a line using the parameter separator and returns the forth token found or null if forth component is missing. Two adjacent separators are NOT treated as one. The forth component is assumed as the last one so its content may have additional separators if present.
        Examples with slash as separator:
        • for the literal "abc/def/ghi//ghi" will return null.
        • for the literal "abc/foo/ghi" will return "null".
        • for the literal "abc/def/ghi/foo" will return "foo".
        • for the literal "abc/def/ghi/foo/ghi" will return "foo/ghi".
        Returns:
        s
      • getAlphaPrefix

        public static java.lang.String getAlphaPrefix​(java.lang.String value)
        Returns the alphabetic starting substring of the value. The split is made when the first numeric character is found. For example:
        ABCD2345,33 will be return ABCD
        If the value does not contain any alphabetic character null is returned.
        Returns:
        s
      • getAlphaPrefixTrimSlash

        public static java.lang.String getAlphaPrefixTrimSlash​(java.lang.String value)
        Same as getAlphaPrefix(String) but if the result consist only of slash characters, then null is returned. This implementation variant is helpful when parsing fields that uses the slash as component separator, to avoid spurious components consisting of just the separator, when a malformed field is parsed.
        Since:
        9.2.9
      • getNumericPrefix

        public static java.lang.String getNumericPrefix​(java.lang.String value)
        Returns the numeric starting substring of the value. The split is made when the first alpha character (not number or comma) is found. For example:
        2345,33ABCD will be return 2345,33
        If the value does not contain any numeric or comma character null is returned.
        Returns:
        s
      • getNumericSuffix

        public static java.lang.String getNumericSuffix​(java.lang.String value)
        Returns the numeric suffix of the value. The split is made when the first numeric character is found. For example:
        ABCD2345,33 will be return 2345,33
        If the value does not contain any numeric character null is returned.
        Returns:
        s
      • getAlphaSuffix

        public static java.lang.String getAlphaSuffix​(java.lang.String value)
        Returns the alpha suffix of the value. The split is made when the first alpha (not numetic or comma) character is found. For example:
        2345,33ABCD will be return ABCD
        If the value does not contain any alpha character null is returned.
        Returns:
        s
      • getLines

        public static java.util.List<java.lang.String> getLines​(java.lang.String value)
        Separate the given string in lines, removing trailing empty lines.

        The implementation uses using BufferedReader.readLine() so if the string ends with a LF, the trailing "empty" line is not returned in the result.

        Returns:
        list of found lines
      • setComponentsFromLines

        public static void setComponentsFromLines​(Field f,
                                                  int startingComponentNumber,
                                                  java.lang.Integer linesToSet,
                                                  int startingLine,
                                                  java.util.List<java.lang.String> lines)
        Populates a multiline field with content from an array of Strings.
        Parameters:
        f - field to populate with components' values
        startingComponentNumber - first component number to be set, then it will increment on each line added
        linesToSet - how many components must to be set, or null to set all available lines as components
        startingLine - lines list offset, zero based
        lines - list of lines from where to get components content
      • setComponentsFromTokens

        public static void setComponentsFromTokens​(Field f,
                                                   int startingComponentNumber,
                                                   int componentsToSet,
                                                   int tokenSize,
                                                   java.lang.String value)
        Populates field with content from of a String splited into fixed length tokens.
        Parameters:
        f - field to populate with components' values
        startingComponentNumber - first component number to be set, then it will increment on each token added
        componentsToSet - how many components must to be set
        tokenSize - fixed size for each token grabbed from the String value
        value - from where to get components content
        Since:
        7.4