Package com.nimbusds.langtag
Class LangTagUtils
- java.lang.Object
-
- com.nimbusds.langtag.LangTagUtils
-
public final class LangTagUtils extends Object
Language tag utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringconcat(List<LangTag> langTags)Concatenates the specified language tags with a single space.static LangTagextract(String s)Extracts the language tag, if any is found, from the specified string.static <T> Map<LangTag,T>find(String baseName, Map<String,T> map)Finds all language-tagged entries with the specified base name.static LangTag[]parseLangTagArray(String... values)Parses a language tag array from the specified string values.static List<LangTag>parseLangTagList(String... values)Parses a language tag list from the specified string values.static List<LangTag>parseLangTagList(Collection<String> collection)Parses a language tag list from the specified string collection.static Map.Entry<String,LangTag>split(String s)Splits the specified optionally language tagged string into a string and language tag pair.static Stringstrip(String s)Strips the language tag, if any is found, from the specified string.static List<String>strip(List<String> list)Strips the language tags, if any are found, from the specified string list.static Set<String>strip(Set<String> set)Strips the language tags, if any are found, from the specified string set.static String[]toStringArray(Collection<LangTag> langTags)Returns a string array representation of the specified language tags collection.static List<String>toStringList(Collection<LangTag> langTags)Returns a string list representation of the specified language tags collection.
-
-
-
Method Detail
-
strip
public static String strip(String s)
Strips the language tag, if any is found, from the specified string. This method isnullsafe.Example:
"name#bg-BG" => "name" "name" => "name"
- Parameters:
s- The string. May contain a language tag. May benull.- Returns:
- The string with no language tag.
-
strip
public static Set<String> strip(Set<String> set)
Strips the language tags, if any are found, from the specified string set. This method isnullsafe.Example:
"name#bg-BG" => "name" "name" => "name"
- Parameters:
set- The string set. May contain strings with language tags. May benull.- Returns:
- The string set with no language tags.
-
strip
public static List<String> strip(List<String> list)
Strips the language tags, if any are found, from the specified string list. This method isnullsafe.Example:
"name#bg-BG" => "name" "name" => "name"
- Parameters:
list- The string list. May contain strings with language tags. May benull.- Returns:
- The string list with no language tags.
-
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 benull.- Returns:
- The extracted language tag,
nullif 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 benull.map- The map to search. Must not benull.- Returns:
- A map of all language-tagged entries with the specified
base name. A
nullkeyed entry will indicate no language tag (base name only).
-
toStringList
public static List<String> toStringList(Collection<LangTag> langTags)
Returns a string list representation of the specified language tags collection.- Parameters:
langTags- The language tags list. May benull.- Returns:
- The string list, or
nullif the original list isnull.
-
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 benull.- Returns:
- The string list, or
nullif the original list isnull.
-
parseLangTagList
public static List<LangTag> parseLangTagList(Collection<String> collection) throws LangTagException
Parses a language tag list from the specified string collection.- Parameters:
collection- The string collection. May benull.- Returns:
- The language tag list, or
nullif the parsed string collection is null. - Throws:
LangTagException- If parsing failed.
-
parseLangTagList
public static List<LangTag> parseLangTagList(String... values) throws LangTagException
Parses a language tag list from the specified string values.- Parameters:
values- The string values. May benull.- Returns:
- The language tag list, or
nullif 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 benull.- Returns:
- The language tag array, or
nullif the parsed string array is null. - Throws:
LangTagException- If parsing failed.
-
split
public static Map.Entry<String,LangTag> split(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 benull.- Returns:
- The pair, with
nulllanguage tag if none found.nullif the original value isnull. - Throws:
LangTagException- If parsing failed.
-
-