com.vaadin.fusion.generator.

Class GeneratorUtils


  • public final class GeneratorUtils
    extends Object

    A set of static methods used in CCDM generators, so as flow do not depend on external libraries for these operations.

    • Method Detail

      • capitalize

        public static String capitalize(String s)

        Capitalizes the string.

        Parameters:

        s - string to capitalize.

        Returns:

        result of capitalization.

      • compare

        public static int compare(String s1,
                                  String s2)

        Compares two strings lexicographically.

        Parameters:

        s1 - first string.

        s2 - second string.

        Returns:

        result of comparison. Can be -1, 0, 1.

        See Also:

        String.compareTo(java.lang.String)

      • contains

        public static boolean contains(String s,
                                       String p)

        Checks if the string s contains string p with an additional check for them to not be blank.

        Parameters:

        s - a string where search to be performed.

        p - a string to be used for search.

        Returns:

        the result of a check.

      • defaultIfNull

        public static <T> T defaultIfNull(T o,
                                          T def)

        Returns a value if it is not null; otherwise, returns default value.

        Type Parameters:

        T - value type

        Parameters:

        o - value

        def - defaultValue

        Returns:

        value or default value

      • firstNonBlank

        public static String firstNonBlank(String... values)

        Searches a first non-blank string in the received arguments.

        Parameters:

        values - a vararg array to search within.

        Returns:

        a result of the search.

      • hasAnnotation

        public static boolean hasAnnotation(com.github.javaparser.ast.nodeTypes.NodeWithAnnotations<?> declaration,
                                            com.github.javaparser.ast.CompilationUnit compilationUnit,
                                            Class<? extends Annotation> annotation)

        Checks whether the declaration has the specific annotation.

        Parameters:

        declaration - a declaration that is checked to have an annotation.

        compilationUnit - a compilation unit.

        annotation - an annotation to check.

        Returns:

        the result of a check.

      • isBlank

        public static boolean isBlank(String s)

        Checks if the string contains only whitespaces.

        Parameters:

        s - a string to check.

        Returns:

        a result of a check.

      • isNotBlank

        public static boolean isNotBlank(String s)

        Checks if the string contains not only whitespaces.

        Parameters:

        s - a string to check.

        Returns:

        a result of a check.

      • isNotTrue

        public static boolean isNotTrue(Boolean b)

        Checks a value for being not truth (or null).

        Parameters:

        b - a boolean to check.

        Returns:

        a result of a check.

      • isTrue

        public static boolean isTrue(Boolean b)

        Checks a value for being true with an additional null check.

        Parameters:

        b - a boolean to check for truth.

        Returns:

        a result of a check.

      • removeEnd

        public static String removeEnd(String s,
                                       String p)

        Removes the end of a string.

        Parameters:

        s - a string to remove an end.

        p - an end part of a string.

        Returns:

        a result string.

      • replaceChars

        public static String replaceChars(String s,
                                          char c1,
                                          char c2)

        Replaces one char with another in a string with an additional null check.

        Parameters:

        s - a string to perform replace within.

        c1 - a char to be replaced.

        c2 - a char to be replacement.

        Returns:

        a result string.

      • substringAfter

        public static String substringAfter(String s,
                                            String p)

        Gets the substring of an s string that goes after the first entry of the p string.

        Parameters:

        s - a string to get substring of.

        p - a string to be searched.

        Returns:

        a substring.

      • substringAfterLast

        public static String substringAfterLast(String s,
                                                String p)

        Gets the substring of an s string that goes after the last entry of the p string.

        Parameters:

        s - a string to get substring of.

        p - a string to be searched.

        Returns:

        a substring.

      • substringBeforeLast

        public static String substringBeforeLast(String s,
                                                 String p)

        Gets the substring of an s string that goes before the last entry of the p string.

        Parameters:

        s - a string to get substring of.

        p - a string to be searched.

        Returns:

        a substring.

      • zip

        public static <P1,P2,R> Stream<R> zip(List<P1> first,
                                              List<P2> second,
                                              BiFunction<P1,P2,R> zipper)

        Runs a lambda against elements of two lists at once.

        Type Parameters:

        P1 - a type of item of a first list.

        P2 - a type of item of a second list.

        R - a type of the streamed result.

        Parameters:

        first - a first list.

        second - a second list.

        zipper - a lambda function that accepts elements from both lists at once.

        Returns:

        a stream with the values zipper produced.