Class SharedUtil

  • All Implemented Interfaces:
    Serializable

    public class SharedUtil
    extends Object
    implements Serializable
    Misc internal utility methods used by both the server and the client package.
    Since:
    1.0
    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • Constructor Detail

      • SharedUtil

        public SharedUtil()
    • Method Detail

      • trimTrailingSlashes

        public static String trimTrailingSlashes​(String value)
        Trims trailing slashes (if any) from a string.
        Parameters:
        value - The string value to be trimmed. Cannot be null.
        Returns:
        String value without trailing slashes.
      • splitCamelCase

        public static String[] splitCamelCase​(String camelCaseString)
        Splits a camelCaseString into an array of words with the casing preserved.
        Parameters:
        camelCaseString - The input string in camelCase format
        Returns:
        An array with one entry per word in the input string
      • camelCaseToHumanFriendly

        public static String camelCaseToHumanFriendly​(String camelCaseString)
        Converts a camelCaseString to a human friendly format (Camel case string).

        In general splits words when the casing changes but also handles special cases such as consecutive upper case characters. Examples:

        MyBeanContainer becomes My Bean Container AwesomeURLFactory becomes Awesome URL Factory SomeUriAction becomes Some Uri Action

        Parameters:
        camelCaseString - The input string in camelCase format
        Returns:
        A human friendly version of the input
      • join

        public static String join​(String[] parts,
                                  String separator)
        Joins the words in the input array together into a single string by inserting the separator string between each word.
        Parameters:
        parts - The array of words
        separator - The separator string to use between words
        Returns:
        The constructed string of words and separators
      • capitalize

        public static String capitalize​(String string)
        Capitalizes the first character in the given string in a way suitable for use in code (methods, properties etc).
        Parameters:
        string - The string to capitalize
        Returns:
        The capitalized string
      • firstToLower

        public static String firstToLower​(String string)
        Changes the first character in the given string to lower case in a way suitable for use in code (methods, properties etc).
        Parameters:
        string - The string to change
        Returns:
        The string with initial character turned into lower case
      • propertyIdToHumanFriendly

        public static String propertyIdToHumanFriendly​(Object propertyId)
        Converts a property id to a human friendly format. Handles nested properties by only considering the last part, e.g. "address.streetName" is equal to "streetName" for this method.
        Parameters:
        propertyId - The propertyId to format
        Returns:
        A human friendly version of the property id
      • addGetParameter

        public static String addGetParameter​(String uri,
                                             String parameter,
                                             String value)
        Adds the given get parameter to the URI and returns the new URI.
        Parameters:
        uri - the URI to which the parameter should be added.
        parameter - the name of the parameter
        value - the value of the parameter
        Returns:
        The modified URI with the parameter added
      • addGetParameter

        public static String addGetParameter​(String uri,
                                             String parameter,
                                             int value)
        Adds the given get parameter to the URI and returns the new URI.
        Parameters:
        uri - the URI to which the parameter should be added.
        parameter - the name of the parameter
        value - the value of the parameter
        Returns:
        The modified URI with the parameter added
      • addGetParameters

        public static String addGetParameters​(String uri,
                                              String extraParams)
        Adds the get parameters to the uri and returns the new uri that contains the parameters.
        Parameters:
        uri - The uri to which the parameters should be added.
        extraParams - One or more parameters in the format "a=b" or "c=d&e=f". An empty string is allowed but will not modify the url.
        Returns:
        The modified URI with the get parameters in extraParams added.
      • dashSeparatedToCamelCase

        public static String dashSeparatedToCamelCase​(String dashSeparated)
        Converts a dash ("-") separated string into camelCase.

        Examples:

        foo becomes foo foo-bar becomes fooBar foo--bar becomes fooBar

        Parameters:
        dashSeparated - The dash separated string to convert
        Returns:
        a camelCase version of the input string
      • camelCaseToDashSeparated

        public static String camelCaseToDashSeparated​(String camelCaseString)
        Converts a camelCase string into dash ("-") separated.

        Examples:

        foo becomes foo fooBar becomes foo-bar MyBeanContainer becomes -my-bean-container AwesomeURLFactory becomes -awesome-uRL-factory someUriAction becomes some-uri-action

        Parameters:
        camelCaseString - The input string in camelCase format
        Returns:
        A human friendly version of the input
      • prefixIfRelative

        public static String prefixIfRelative​(String url,
                                              String prefix)
        Prepend the given url with the prefix if it is not absolute and doesn't have a protocol.
        Parameters:
        url - url to check
        prefix - prefix to add to url
        Returns:
        prefixed url or url if absolute or has a protocol