Class ParseUtils


  • public abstract class ParseUtils
    extends Object
    Simple utility class used to help parsing CQL values (mainly UDT and collection ones).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String doubleQuote​(String value)
      Double quote the given string; double quotes are escaped.
      static String formatTime​(long value)
      Format the given long value as a CQL time literal, using the following time pattern: hh:mm:ss[.fffffffff].
      static boolean isBlank​(int c)
      Return true if the given character is a valid whitespace character in CQL, that is, if it is a regular space, a tabulation sign, or a new line sign.
      static boolean isDoubleQuoted​(String value)
      Return true if the given string is surrounded by double quotes, and false otherwise.
      static boolean isIdentifierChar​(int c)
      Return true if the given character is allowed in a CQL identifier, that is, if it is in the range: [0..9a..zA..Z-+._&].
      static boolean isLongLiteral​(String str)
      Check whether the given string corresponds to a valid CQL long literal.
      static boolean isQuoted​(String value)
      Return true if the given string is surrounded by single quotes, and false otherwise.
      static Date parseDate​(String str)
      Parse the given string as a date, using one of the accepted ISO-8601 date patterns.
      static Date parseDate​(String str, String pattern)
      Parse the given string as a date, using the supplied date pattern.
      static long parseTime​(String str)
      Parse the given string as a time, using the following time pattern: hh:mm:ss[.fffffffff].
      static String quote​(String value)
      Quote the given string; single quotes are escaped.
      static int skipCQLId​(String toParse, int idx)
      Assuming that idx points to the beginning of a CQL identifier in toParse, returns the index of the first character after this identifier.
      static int skipCQLValue​(String toParse, int idx)
      Assuming that idx points to the beginning of a CQL value in toParse, returns the index of the first character after this value.
      static int skipSpaces​(String toParse, int idx)
      Returns the index of the first character in toParse from idx that is not a "space".
      static String unDoubleQuote​(String value)
      Unquote the given string if it is double quoted; double quotes are unescaped.
      static String unquote​(String value)
      Unquote the given string if it is quoted; single quotes are unescaped.
    • Method Detail

      • skipSpaces

        public static int skipSpaces​(String toParse,
                                     int idx)
        Returns the index of the first character in toParse from idx that is not a "space".
        Parameters:
        toParse - the string to skip space on.
        idx - the index to start skipping space from.
        Returns:
        the index of the first character in toParse from idx that is not a "space.
      • skipCQLValue

        public static int skipCQLValue​(String toParse,
                                       int idx)
        Assuming that idx points to the beginning of a CQL value in toParse, returns the index of the first character after this value.
        Parameters:
        toParse - the string to skip a value form.
        idx - the index to start parsing a value from.
        Returns:
        the index ending the CQL value starting at idx.
        Throws:
        IllegalArgumentException - if idx doesn't point to the start of a valid CQL value.
      • skipCQLId

        public static int skipCQLId​(String toParse,
                                    int idx)
        Assuming that idx points to the beginning of a CQL identifier in toParse, returns the index of the first character after this identifier.
        Parameters:
        toParse - the string to skip an identifier from.
        idx - the index to start parsing an identifier from.
        Returns:
        the index ending the CQL identifier starting at idx.
        Throws:
        IllegalArgumentException - if idx doesn't point to the start of a valid CQL identifier.
      • isIdentifierChar

        public static boolean isIdentifierChar​(int c)
        Return true if the given character is allowed in a CQL identifier, that is, if it is in the range: [0..9a..zA..Z-+._&].
        Parameters:
        c - The character to inspect.
        Returns:
        true if the given character is allowed in a CQL identifier, false otherwise.
      • isBlank

        public static boolean isBlank​(int c)
        Return true if the given character is a valid whitespace character in CQL, that is, if it is a regular space, a tabulation sign, or a new line sign.
        Parameters:
        c - The character to inspect.
        Returns:
        true if the given character is a valid whitespace character, false otherwise.
      • isLongLiteral

        public static boolean isLongLiteral​(String str)
        Check whether the given string corresponds to a valid CQL long literal. Long literals are composed solely by digits, but can have an optional leading minus sign.
        Parameters:
        str - The string to inspect.
        Returns:
        true if the given string corresponds to a valid CQL integer literal, false otherwise.
      • isQuoted

        public static boolean isQuoted​(String value)
        Return true if the given string is surrounded by single quotes, and false otherwise.
        Parameters:
        value - The string to inspect.
        Returns:
        true if the given string is surrounded by single quotes, and false otherwise.
      • quote

        public static String quote​(String value)
        Quote the given string; single quotes are escaped. If the given string is null, this method returns a quoted empty string ('').
        Parameters:
        value - The value to quote.
        Returns:
        The quoted string.
      • unquote

        public static String unquote​(String value)
        Unquote the given string if it is quoted; single quotes are unescaped. If the given string is not quoted, it is returned without any modification.
        Parameters:
        value - The string to unquote.
        Returns:
        The unquoted string.
      • isDoubleQuoted

        public static boolean isDoubleQuoted​(String value)
        Return true if the given string is surrounded by double quotes, and false otherwise.
        Parameters:
        value - The string to inspect.
        Returns:
        true if the given string is surrounded by double quotes, and false otherwise.
      • doubleQuote

        public static String doubleQuote​(String value)
        Double quote the given string; double quotes are escaped. If the given string is null, this method returns a quoted empty string ("").
        Parameters:
        value - The value to double quote.
        Returns:
        The double quoted string.
      • unDoubleQuote

        public static String unDoubleQuote​(String value)
        Unquote the given string if it is double quoted; double quotes are unescaped. If the given string is not double quoted, it is returned without any modification.
        Parameters:
        value - The string to un-double quote.
        Returns:
        The un-double quoted string.
      • parseTime

        public static long parseTime​(String str)
                              throws ParseException
        Parse the given string as a time, using the following time pattern: hh:mm:ss[.fffffffff].

        This method is loosely based on java.sql.Timestamp.

        Parameters:
        str - The string to parse.
        Returns:
        A long value representing the number of nanoseconds since midnight.
        Throws:
        ParseException - if the string cannot be parsed.
        See Also:
        'Working with time' section of CQL specification
      • formatTime

        public static String formatTime​(long value)
        Format the given long value as a CQL time literal, using the following time pattern: hh:mm:ss[.fffffffff].
        Parameters:
        value - A long value representing the number of nanoseconds since midnight.
        Returns:
        The formatted value.
        See Also:
        'Working with time' section of CQL specification