Class PseudoString

  • All Implemented Interfaces:
    IVilType

    public class PseudoString
    extends java.lang.Object
    implements IVilType
    Implements a pseudo class for strings.
    Author:
    Holger Eichelberger
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected PseudoString()
      Prevents external instantiation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String at​(java.lang.String string, int index)
      Returns the character at given position as String.
      static Sequence<java.lang.String> characters​(java.lang.String string)
      Returns the characters of a string.
      static java.lang.String concat​(java.lang.String s1, java.lang.Object s2)
      Represents the string concatenation operation.
      static java.lang.String convertAny​(java.lang.Object any)
      The last resort - converts any object to a String using StringValueHelper.
      private static void deleteNonJavaIdentifierParts​(java.lang.StringBuilder name)
      Deletes non-Java identifier parts from name.
      static boolean endsWith​(java.lang.String string, java.lang.String postfix)
      Returns whether the given string has the given postfix.
      static boolean equals​(java.lang.String s1, java.lang.String s2)
      Represents the equality operation for Strings.
      static boolean equals​(java.lang.String string, TypeDescriptor<?> type)
      Represents the equality operation for types vs.
      static boolean equalsIgnoreCase​(java.lang.String string1, java.lang.String string2)
      Returns whether two strings are equal ignoring cases for the current locale.
      static java.lang.String firstToLowerCase​(java.lang.String string)
      Turns the first character into a lower case character.
      static java.lang.String firstToUpperCase​(java.lang.String string)
      Turns the first character into an upper case character.
      static java.lang.String format​(java.lang.String format, java.lang.Object value)
      Fills format with values from value.
      private static java.lang.String formatImpl​(java.lang.String format, java.lang.Object... values)
      Implements the generic format operation with exception handling.
      private static java.lang.String formatImpl​(java.lang.String format, java.util.List<?> values)
      Implements the format operation for list values.
      private static java.lang.String formatImpl​(java.lang.String format, java.util.Map<?,​?> value)
      Implements the format operation for map values.
      static java.lang.String getProperty​(java.lang.String key, java.lang.String dflt)
      Returns the value of a JVM property.
      static TypeDescriptor<?> getType​(java.lang.String value)
      Returns the type of value.
      static boolean greaterThan​(java.lang.String string1, java.lang.String string2)
      Returns whether string1 is greater than string2 with respect to the current locale.
      static boolean greaterThanEqual​(java.lang.String string1, java.lang.String string2)
      Returns whether string1 is greater than or equal string2 with respect to the current locale.
      static java.lang.Integer indexOf​(java.lang.String string, java.lang.String part)
      Returns the first position of part in string.
      static boolean isQuoted​(java.lang.String string, java.lang.String quote)
      Returns whether string is quoted by quote, i.e., starts and ends with quote.
      static java.lang.String lastToLowerCase​(java.lang.String string)
      Turns the last character into a lower case character.
      static java.lang.String lastToUpperCase​(java.lang.String string)
      Turns the last character into an upper case character (QVT).
      static int length​(java.lang.String string)
      The length of the string.
      static boolean lessThan​(java.lang.String string1, java.lang.String string2)
      Returns whether string1 is less than string2 with respect to the current locale.
      static boolean lessThanEqual​(java.lang.String string1, java.lang.String string2)
      Returns whether string1 is less than or equal string2 with respect to the current locale.
      static boolean matchBoolean​(java.lang.String string)
      Returns whether string represents a Boolean value.
      static boolean matches​(java.lang.String string, java.lang.String regEx)
      Returns whether string matches the given regular expression.
      static boolean matchIdentifier​(java.lang.String string)
      Returns whether string complies with the rules for a Java identifier.
      static boolean matchInteger​(java.lang.String string)
      Returns whether string represents an Integer value.
      static boolean matchReal​(java.lang.String string)
      Returns whether string represents a Real value.
      static java.lang.String normalizeSpace​(java.lang.String string)
      Normalizes spaces, i.e., trims and replaces all internal multi-whitespaces by a single one.
      static boolean notEquals​(java.lang.String string, TypeDescriptor<?> type)
      Represents the un-equality operation for types vs.
      static java.lang.String osName()
      Returns the name/version of the operating system.
      static java.lang.String plus​(java.lang.String s1, java.lang.Object s2)
      Represents the string concatenation operation.
      static java.lang.String quotify​(java.lang.String string, java.lang.String quote)
      Quotifies string by adding quote around string.
      static java.lang.String replace​(java.lang.String string, java.lang.String search, java.lang.String replacement)
      Replaces all occurrences of search in string by replacement.
      static java.lang.Integer rfind​(java.lang.String string, java.lang.String part)
      Returns the last position of part in string.
      static Sequence<java.lang.String> split​(java.lang.String string, java.lang.String regEx)
      Splits this string around matches of the given Java regular expression.
      static boolean startsWith​(java.lang.String string, java.lang.String prefix)
      Returns whether the given string has the given prefix.
      static java.lang.String substitute​(java.lang.String string, java.lang.String regEx, java.lang.String replacement)
      Replaces all occurrences of regEx in string by replacement.
      static java.lang.String substring​(java.lang.String in, int start)
      Returns the specified substring of in from start to end of in.
      static java.lang.String substring​(java.lang.String in, int start, int end)
      Returns the specified substring of in.
      static java.lang.String substringAfter​(java.lang.String string, java.lang.String match)
      Returns the substring of string after the (first) occurrence of match.
      static java.lang.String substringBefore​(java.lang.String string, java.lang.String match)
      Returns the substring of string before the (first) occurrence of match.
      static java.lang.Boolean toBoolean​(java.lang.String string)
      Turns the given string into a Boolean.
      static java.lang.String toCamelCaseIdentifier​(java.lang.String string)
      Turns the given string into a typical (Java) camel-case programming language identifier by turning all lower case characters after whitespaces into upper case characters and removing all non-Java identifier parts (akin to toIdentifier(String).
      static java.lang.String toIdentifier​(java.lang.String string)
      Turns the given string into a (Java) programming language identifier by removing all non identifier characters.
      static java.lang.String toIdentifier​(java.lang.String string, java.lang.String prefix)
      Turns the given string into a (Java) programming language identifier by removing all non identifier characters.
      static java.lang.Integer toInteger​(java.lang.String string)
      Turns the given string into an integer.
      static Sequence<java.lang.String> tokenize​(java.lang.String string, java.lang.String delimiters)
      Tokenizes the given string along delimiters.
      static java.lang.String toLowerCase​(java.lang.String string)
      Transforms all characters to lower case.
      static java.lang.Double toReal​(java.lang.String string)
      Turns the given string into a double.
      static java.lang.String toString​(java.lang.String string)
      Returns the string representation of string (OCL).
      static java.lang.String toUpperCase​(java.lang.String string)
      Transforms all characters to upper case.
      static java.lang.String trim​(java.lang.String string)
      Transforms the string by removing all leading and trailing spaces.
      static boolean unequals​(java.lang.String s1, java.lang.String s2)
      Represents the unequality operation for Strings.
      static java.lang.String unquotify​(java.lang.String string, java.lang.String quote)
      Unquotifies string if quote is quoted.
      • Methods inherited from class java.lang.Object

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

      • PseudoString

        protected PseudoString()
        Prevents external instantiation.
    • Method Detail

      • plus

        public static java.lang.String plus​(java.lang.String s1,
                                            java.lang.Object s2)
        Represents the string concatenation operation.
        Parameters:
        s1 - the first String to be considered
        s2 - the second String (as object)to be considered
        Returns:
        s1 + s2
      • concat

        public static java.lang.String concat​(java.lang.String s1,
                                              java.lang.Object s2)
        Represents the string concatenation operation.
        Parameters:
        s1 - the first String to be considered
        s2 - the second String (as object)to be considered
        Returns:
        s1 + s2
      • equals

        public static boolean equals​(java.lang.String s1,
                                     java.lang.String s2)
        Represents the equality operation for Strings.
        Parameters:
        s1 - the first boolean to be considered
        s2 - the second boolean to be considered
        Returns:
        s1 == s2
      • unequals

        public static boolean unequals​(java.lang.String s1,
                                       java.lang.String s2)
        Represents the unequality operation for Strings.
        Parameters:
        s1 - the first boolean to be considered
        s2 - the second boolean to be considered
        Returns:
        s1 != s2
      • length

        public static int length​(java.lang.String string)
        The length of the string.
        Parameters:
        string - the string to return the length for
        Returns:
        the length of the string
      • matches

        public static boolean matches​(java.lang.String string,
                                      java.lang.String regEx)
        Returns whether string matches the given regular expression.
        Parameters:
        string - the string to be considered
        regEx - the (Java) regular expression
        Returns:
        true if it matches, false else
      • split

        public static Sequence<java.lang.String> split​(java.lang.String string,
                                                       java.lang.String regEx)
        Splits this string around matches of the given Java regular expression.
        Parameters:
        string - the string to be split
        regEx - the delimiting regular expression
        Returns:
        the splitted string
      • substitute

        public static java.lang.String substitute​(java.lang.String string,
                                                  java.lang.String regEx,
                                                  java.lang.String replacement)
        Replaces all occurrences of regEx in string by replacement.
        Parameters:
        string - the string to be considered as basis
        regEx - the Java regular expression to be replaced
        replacement - the replacement string
        Returns:
        the modified string
      • replace

        public static java.lang.String replace​(java.lang.String string,
                                               java.lang.String search,
                                               java.lang.String replacement)
        Replaces all occurrences of search in string by replacement.
        Parameters:
        string - the string to be considered as basis
        search - the search string to be replaced
        replacement - the replacement string
        Returns:
        the modified string
      • toInteger

        public static java.lang.Integer toInteger​(java.lang.String string)
        Turns the given string into an integer.
        Parameters:
        string - the input string
        Returns:
        the converted integer (null if conversion is not possible)
        See Also:
        matchInteger(String)
      • matchInteger

        public static boolean matchInteger​(java.lang.String string)
        Returns whether string represents an Integer value. (QVT)
        Parameters:
        string - the string to test
        Returns:
        true if string represents an Integer value, false
        See Also:
        toInteger(String)
      • toReal

        public static java.lang.Double toReal​(java.lang.String string)
        Turns the given string into a double.
        Parameters:
        string - the input string
        Returns:
        the converted double (null if conversion is not possible)
        See Also:
        matchReal(String)
      • matchReal

        public static boolean matchReal​(java.lang.String string)
        Returns whether string represents a Real value. (QVT)
        Parameters:
        string - the string to test
        Returns:
        true if string represents a Real
        See Also:
        toReal(String)
      • toBoolean

        public static java.lang.Boolean toBoolean​(java.lang.String string)
        Turns the given string into a Boolean. False is implicitly assumed for all values that do not represent true.
        Parameters:
        string - the input string
        Returns:
        the converted Boolean (null if conversion is not possible)
        See Also:
        matchBoolean(String)
      • matchBoolean

        public static boolean matchBoolean​(java.lang.String string)
        Returns whether string represents a Boolean value. (QVT)
        Parameters:
        string - the string to test
        Returns:
        true if string represents a Boolean
        See Also:
        toBoolean(String)
      • substring

        public static java.lang.String substring​(java.lang.String in,
                                                 int start,
                                                 int end)
        Returns the specified substring of in.
        Parameters:
        in - the string to be considered
        start - the inclusive start position
        end - the exclusive end position
        Returns:
        the substring (or in in case of any parameter problem)
      • substring

        public static java.lang.String substring​(java.lang.String in,
                                                 int start)
        Returns the specified substring of in from start to end of in.
        Parameters:
        in - the string to be considered
        start - the inclusive start position
        Returns:
        the substring (or in in case of any parameter problem)
      • startsWith

        public static boolean startsWith​(java.lang.String string,
                                         java.lang.String prefix)
        Returns whether the given string has the given prefix.
        Parameters:
        string - the string to be considered
        prefix - the prefix
        Returns:
        true if string starts with prefix, false else
      • endsWith

        public static boolean endsWith​(java.lang.String string,
                                       java.lang.String postfix)
        Returns whether the given string has the given postfix.
        Parameters:
        string - the string to be considered
        postfix - the postfix
        Returns:
        true if string ends with postfix, false else
      • trim

        public static java.lang.String trim​(java.lang.String string)
        Transforms the string by removing all leading and trailing spaces. (QVT)
        Parameters:
        string - the string to be transformed
        Returns:
        the transformed string
      • normalizeSpace

        public static java.lang.String normalizeSpace​(java.lang.String string)
        Normalizes spaces, i.e., trims and replaces all internal multi-whitespaces by a single one. (QVT)
        Parameters:
        string - the string to normalize
        Returns:
        the normalized string
      • substringBefore

        public static java.lang.String substringBefore​(java.lang.String string,
                                                       java.lang.String match)
        Returns the substring of string before the (first) occurrence of match. (QVT)
        Parameters:
        string - the string to search within
        match - the string to match for
        Returns:
        the substring before the match, an empty string in case of no match
      • substringAfter

        public static java.lang.String substringAfter​(java.lang.String string,
                                                      java.lang.String match)
        Returns the substring of string after the (first) occurrence of match. (QVT)
        Parameters:
        string - the string to search within
        match - the string to match for
        Returns:
        the substring after the match, an empty string in case of no match
      • toUpperCase

        public static java.lang.String toUpperCase​(java.lang.String string)
        Transforms all characters to upper case.
        Parameters:
        string - the string to be transformed
        Returns:
        the transformed string
      • toLowerCase

        public static java.lang.String toLowerCase​(java.lang.String string)
        Transforms all characters to lower case.
        Parameters:
        string - the string to be transformed
        Returns:
        the transformed string
      • firstToUpperCase

        public static java.lang.String firstToUpperCase​(java.lang.String string)
        Turns the first character into an upper case character.
        Parameters:
        string - the string to be transformed
        Returns:
        the transformed string
      • firstToLowerCase

        public static java.lang.String firstToLowerCase​(java.lang.String string)
        Turns the first character into a lower case character.
        Parameters:
        string - the string to be transformed
        Returns:
        the transformed string
      • lastToUpperCase

        public static java.lang.String lastToUpperCase​(java.lang.String string)
        Turns the last character into an upper case character (QVT).
        Parameters:
        string - the string to be transformed
        Returns:
        the transformed string
      • lastToLowerCase

        public static java.lang.String lastToLowerCase​(java.lang.String string)
        Turns the last character into a lower case character.
        Parameters:
        string - the string to be transformed
        Returns:
        the transformed string
      • toIdentifier

        public static java.lang.String toIdentifier​(java.lang.String string)
        Turns the given string into a (Java) programming language identifier by removing all non identifier characters. The beginning of the result may not be an identifier.
        Parameters:
        string - the string to be turned into an identifier
        Returns:
        the identifier (may be empty in the extreme case)
        See Also:
        matchIdentifier(String)
      • toIdentifier

        public static java.lang.String toIdentifier​(java.lang.String string,
                                                    java.lang.String prefix)
        Turns the given string into a (Java) programming language identifier by removing all non identifier characters. If the beginning of the result is not an identifier, prepend prefix.
        Parameters:
        string - the string to be turned into an identifier
        prefix - string to be prepended if the beginning of the result is not an identifier
        Returns:
        the identifier (may be empty in the extreme case)
        See Also:
        toIdentifier(String, String)
      • deleteNonJavaIdentifierParts

        private static void deleteNonJavaIdentifierParts​(java.lang.StringBuilder name)
        Deletes non-Java identifier parts from name.
        Parameters:
        name - the name to clean
      • toCamelCaseIdentifier

        public static java.lang.String toCamelCaseIdentifier​(java.lang.String string)
        Turns the given string into a typical (Java) camel-case programming language identifier by turning all lower case characters after whitespaces into upper case characters and removing all non-Java identifier parts (akin to toIdentifier(String).
        Parameters:
        string - the string to be turned into an identifier
        Returns:
        the identifier (may be empty in the extreme case)
        See Also:
        matchIdentifier(String)
      • matchIdentifier

        public static boolean matchIdentifier​(java.lang.String string)
        Returns whether string complies with the rules for a Java identifier. (QVT) If true, toIdentifier(String) returns string, else a string with all characters removed that are not allowed in a Java identifier.
        Parameters:
        string - the string to be tested
        Returns:
        true if string represents an identifier, false else
      • convertAny

        public static java.lang.String convertAny​(java.lang.Object any)
        The last resort - converts any object to a String using StringValueHelper. This operation is absolutely necessary as the operation resolution in AbstractCallExpression tries to find a matching operation with operand converted to String using this method.
        Parameters:
        any - the object to be converted
        Returns:
        the resulting value
      • tokenize

        public static Sequence<java.lang.String> tokenize​(java.lang.String string,
                                                          java.lang.String delimiters)
        Tokenizes the given string along delimiters.
        Parameters:
        string - the string to tokenize
        delimiters - the delimiters between two tokens. Delimiter characters themselves will not be treated as tokens.
        Returns:
        the tokens in sequence of occurrence
      • toString

        public static java.lang.String toString​(java.lang.String string)
        Returns the string representation of string (OCL).
        Parameters:
        string - the string to be turned into a string
        Returns:
        the string value
      • indexOf

        public static java.lang.Integer indexOf​(java.lang.String string,
                                                java.lang.String part)
        Returns the first position of part in string. Find alias is due to QVT.
        Parameters:
        string - the string to search
        part - the part to search for
        Returns:
        the first 0-based position or -1 if part is not a substring of string
      • rfind

        public static java.lang.Integer rfind​(java.lang.String string,
                                              java.lang.String part)
        Returns the last position of part in string. (QVT)
        Parameters:
        string - the string to search
        part - the part to search for
        Returns:
        the last 0-based position or -1 if part is not a substring of string
      • isQuoted

        public static boolean isQuoted​(java.lang.String string,
                                       java.lang.String quote)
        Returns whether string is quoted by quote, i.e., starts and ends with quote. (QVT)
        Parameters:
        string - the string to test
        quote - the quote string/character
        Returns:
        true if string is quoted, false else
      • quotify

        public static java.lang.String quotify​(java.lang.String string,
                                               java.lang.String quote)
        Quotifies string by adding quote around string. (QVT)
        Parameters:
        string - the string
        quote - the quote string/character
        Returns:
        the quoted string
      • unquotify

        public static java.lang.String unquotify​(java.lang.String string,
                                                 java.lang.String quote)
        Unquotifies string if quote is quoted. (QVT)
        Parameters:
        string - the string
        quote - the quote string/character
        Returns:
        the unquoted string, if not quoted string
      • at

        public static java.lang.String at​(java.lang.String string,
                                          int index)
        Returns the character at given position as String.
        Parameters:
        string - the string to take the character from
        index - the 0-based index to return the character for
        Returns:
        the character at index
      • osName

        public static java.lang.String osName()
        Returns the name/version of the operating system.
        Returns:
        the name of the operating system
      • getProperty

        public static java.lang.String getProperty​(java.lang.String key,
                                                   java.lang.String dflt)
        Returns the value of a JVM property.
        Parameters:
        key - the property key
        dflt - the default value to be returned if the key is not defined
        Returns:
        the value of the property, dflt if the property is not defined
      • equalsIgnoreCase

        public static boolean equalsIgnoreCase​(java.lang.String string1,
                                               java.lang.String string2)
        Returns whether two strings are equal ignoring cases for the current locale.
        Parameters:
        string1 - the first string
        string2 - the second string
        Returns:
        true if both strings are considered equal for the current locale, false else
      • lessThan

        public static boolean lessThan​(java.lang.String string1,
                                       java.lang.String string2)
        Returns whether string1 is less than string2 with respect to the current locale.
        Parameters:
        string1 - the first string
        string2 - the second string
        Returns:
        whether string1 is less than string2
      • lessThanEqual

        public static boolean lessThanEqual​(java.lang.String string1,
                                            java.lang.String string2)
        Returns whether string1 is less than or equal string2 with respect to the current locale.
        Parameters:
        string1 - the first string
        string2 - the second string
        Returns:
        whether string1 is less than or equal string2
      • greaterThan

        public static boolean greaterThan​(java.lang.String string1,
                                          java.lang.String string2)
        Returns whether string1 is greater than string2 with respect to the current locale.
        Parameters:
        string1 - the first string
        string2 - the second string
        Returns:
        whether string1 is greater than string2
      • greaterThanEqual

        public static boolean greaterThanEqual​(java.lang.String string1,
                                               java.lang.String string2)
        Returns whether string1 is greater than or equal string2 with respect to the current locale.
        Parameters:
        string1 - the first string
        string2 - the second string
        Returns:
        whether string1 is greater than or equal string2
      • characters

        public static Sequence<java.lang.String> characters​(java.lang.String string)
        Returns the characters of a string.
        Parameters:
        string - the string to be turned into characters
        Returns:
        the characters of string as string sequence
      • getType

        public static TypeDescriptor<?> getType​(java.lang.String value)
        Returns the type of value. "Overrides" PseudoAny.getType(Object).
        Parameters:
        value - the String to return the type for
        Returns:
        the type of object (null if ob is null)
      • equals

        public static boolean equals​(java.lang.String string,
                                     TypeDescriptor<?> type)
        Represents the equality operation for types vs. Strings (legacy). Use simple or qualified name of type for comparison.
        Parameters:
        string - the string to compare
        type - the type to compare
        Returns:
        string == type.getName() || string == type.getQualifiedName()
      • notEquals

        public static boolean notEquals​(java.lang.String string,
                                        TypeDescriptor<?> type)
        Represents the un-equality operation for types vs. Strings (legacy). Use simple or qualified name of type for comparison.
        Parameters:
        string - the string to compare
        type - the type to compare
        Returns:
        string != type.getName() && string != type.getQualifiedName()
      • format

        public static java.lang.String format​(java.lang.String format,
                                              java.lang.Object value)
        Fills format with values from value. Follows the QVT specification of this operation as far as possible.
        Parameters:
        format - the format in Java format specification, including %(x) for keys if value is a map
        value - the value - if sequence, assign the values to the positions of the format specification; if map, replace %(key) by string representation; if value, just apply format.
        Returns:
        the formatted string, null in case of any formatting problems
      • formatImpl

        private static java.lang.String formatImpl​(java.lang.String format,
                                                   java.util.Map<?,​?> value)
        Implements the format operation for map values.
        Parameters:
        format - the format operation
        value - the map value
        Returns:
        the formatted string
      • formatImpl

        private static java.lang.String formatImpl​(java.lang.String format,
                                                   java.util.List<?> values)
        Implements the format operation for list values.
        Parameters:
        format - the format operation
        values - the list value(s)
        Returns:
        the formatted string
      • formatImpl

        private static java.lang.String formatImpl​(java.lang.String format,
                                                   java.lang.Object... values)
        Implements the generic format operation with exception handling.
        Parameters:
        format - the format operation
        values - the values
        Returns:
        the formatted string