Class StringValueHelper


  • public class StringValueHelper
    extends java.lang.Object
    Helps turning an object into a string. Note that this mechanism is different than toString as usual for POJOs.
    Author:
    Holger Eichelberger
    • Constructor Detail

      • StringValueHelper

        public StringValueHelper()
    • Method Detail

      • firstToUpperCase

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

        public static java.lang.String firstToUpperCase​(java.lang.String string,
                                                        java.util.Locale locale)
        Turns the first character into an upper case character using the given locale.
        Parameters:
        string - the string to be transformed
        locale - the locale to use
        Returns:
        the transformed string
      • lastToUpperCase

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

        public static java.lang.String lastToUpperCase​(java.lang.String string,
                                                       java.util.Locale locale)
        Turns the last character into an upper case character using the given locale.
        Parameters:
        string - the string to be transformed
        locale - the locale to use
        Returns:
        the transformed string
      • firstToLowerCase

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

        public static java.lang.String firstToLowerCase​(java.lang.String string,
                                                        java.util.Locale locale)
        Turns the first character into a lower case character using the given locale.
        Parameters:
        string - the string to be transformed
        locale - the locale to use
        Returns:
        the transformed string
      • lastToLowerCase

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

        public static java.lang.String lastToLowerCase​(java.lang.String string,
                                                       java.util.Locale locale)
        Turns the last character into a lower case character using the given locale.
        Parameters:
        string - the string to be transformed
        locale - the locale to use
        Returns:
        the transformed string
      • getStringValueInReplacement

        public static java.lang.String getStringValueInReplacement​(java.lang.Object object,
                                                                   IStringValueProvider.StringComparator comparator)
        Returns the string value in case of value or expression replacements. In this situation, further conversions may apply, such as that IvmlElements are converted into their actual value rather than returning their name.
        Parameters:
        object - the object to be turned into a string
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        Returns:
        the string value
      • registerStringValueProvider

        public static void registerStringValueProvider​(java.lang.Class<?> objectClass,
                                                       IRegisteredStringValueProvider provider)
        Registers a string value provider.
        Parameters:
        objectClass - the class to register the provider for
        provider - the provider
      • getStringValueProvider

        public static IRegisteredStringValueProvider getStringValueProvider​(java.lang.Class<?> objectClass)
        Returns the registered string value provider.
        Parameters:
        objectClass - the class the provider was registered for
        Returns:
        the registered provider (or null if none was found)
      • getStringValue

        public static java.lang.String getStringValue​(java.lang.Object object,
                                                      IStringValueProvider.StringComparator comparator)
        Turns the given object into a string using IStringValueProvider.
        Parameters:
        object - the object to be turned into a string
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        Returns:
        the string value
      • getStringValue

        public static java.lang.String getStringValue​(Collection<?> collection,
                                                      IStringValueProvider.StringComparator comparator)
        Turns the given collection into a string.
        Parameters:
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        collection - the collection to be turned into a string
        Returns:
        the string value
      • sortCollection

        public static <T> Collection<T> sortCollection​(Collection<T> collection,
                                                       IStringValueProvider.StringComparator comparator)
        Sorts a given collection according to the string values of the contained elements.
        Type Parameters:
        T - the entry type of the collection
        Parameters:
        collection - the collection to be sorted
        comparator - the comparator to be used for sorting
        Returns:
        a sorted collection of the same type or collection if no comparator is given, or collection is null