Class LangTagUtils

    • Method Detail

      • strip

        public static String strip​(String s)
        Strips the language tag, if any is found, from the specified string. This method is null safe.

        Example:

         "name#bg-BG" => "name"
         "name"       => "name"
         
        Parameters:
        s - The string. May contain a language tag. May be null.
        Returns:
        The string with no language tag, or null if the original string is null.
      • strip

        public static Set<Stringstrip​(Set<String> set)
        Strips the language tags, if any are found, from the specified string set. This method is null safe.

        Example:

         "name#bg-BG" => "name"
         "name"       => "name"
         
        Parameters:
        set - The string set. May contain strings with language tags. May be null.
        Returns:
        The string set with no language tags, or null if the original set is null.
      • strip

        public static List<Stringstrip​(List<String> list)
        Strips the language tags, if any are found, from the specified string list. This method is null safe.

        Example:

         "name#bg-BG" => "name"
         "name"       => "name"
         
        Parameters:
        list - The string list. May contain strings with language tags. May be null.
        Returns:
        The string list with no language tags, or null if the original list is null.
      • extract

        public static LangTag extract​(String s)
                               throws LangTagException
        Extracts the language tag, if any is found, from the specified string.

        Example:

         "name#bg-BG" => "bg-BG"
         "name#"      => null
         "name"       => null
         
        Parameters:
        s - The string. May contain a language tag. May be null.
        Returns:
        The extracted language tag, null if not found.
        Throws:
        LangTagException - If the language tag is invalid.
      • find

        public static <T> Map<LangTag,​T> find​(String baseName,
                                                    Map<String,​T> map)
        Finds all language-tagged entries with the specified base name. Entries with invalid language tags will be skipped.

        Example:

        Map to search for base name "month":

         "month"    => "January"
         "month#de" => "Januar"
         "month#fr" => "janvier"
         "month#pt" => "janeiro"
         

        Result:

         null => "January"
         "de" => "Januar"
         "fr" => "janvier"
         "pt" => "janeiro"
         
        Parameters:
        baseName - The base name to look for (without a language tag) in the map keys. Must not be null.
        map - The map to search. Must not be null.
        Returns:
        A map of all language-tagged entries with the specified base name. A null keyed entry will indicate no language tag (base name only).
      • toStringList

        public static List<StringtoStringList​(Collection<LangTag> langTags)
        Returns a string list representation of the specified language tags collection.
        Parameters:
        langTags - The language tags list. May be null.
        Returns:
        The string list, or null if the original list is null.
      • toStringArray

        public static String[] toStringArray​(Collection<LangTag> langTags)
        Returns a string array representation of the specified language tags collection.
        Parameters:
        langTags - The language tags list. May be null.
        Returns:
        The string list, or null if the original list is null.
      • parseLangTagList

        public static List<LangTagparseLangTagList​(String spaceDelimitedValues)
                                              throws LangTagException
        Parses a language tag list from the specified string containing space delimited values.
        Parameters:
        spaceDelimitedValues - String containing zero or more space delimited values. May be null.
        Returns:
        The language tag list, or null if the parsed string is null.
        Throws:
        LangTagException - If parsing failed.
      • parseLangTagList

        public static List<LangTagparseLangTagList​(Collection<String> collection)
                                              throws LangTagException
        Parses a language tag list from the specified string collection.
        Parameters:
        collection - The string collection. May be null.
        Returns:
        The language tag list, or null if the parsed string collection is null.
        Throws:
        LangTagException - If parsing failed.
      • parseLangTagList

        public static List<LangTagparseLangTagList​(String... values)
                                              throws LangTagException
        Parses a language tag list from the specified string values.
        Parameters:
        values - The string values. May be null.
        Returns:
        The language tag list, or null if the parsed string array is null.
        Throws:
        LangTagException - If parsing failed.
      • parseLangTagArray

        public static LangTag[] parseLangTagArray​(String... values)
                                           throws LangTagException
        Parses a language tag array from the specified string values.
        Parameters:
        values - The string values. May be null.
        Returns:
        The language tag array, or null if the parsed string array is null.
        Throws:
        LangTagException - If parsing failed.
      • split

        public static Map.Entry<String,​LangTagsplit​(String s)
                                                     throws LangTagException
        Splits the specified optionally language tagged string into a string and language tag pair.
        Parameters:
        s - The optionally language-tagged string. May be null.
        Returns:
        The pair, with null language tag if none found. null if the original value is null.
        Throws:
        LangTagException - If parsing failed.
      • concat

        public static String concat​(List<LangTag> langTags)
        Concatenates the specified language tags with a single space.
        Parameters:
        langTags - The language tags list. May be null.
        Returns:
        The string, null if the language tag list was null or empty.