Class CollectionHelper
- java.lang.Object
-
- com.sun.identity.shared.datastruct.CollectionHelper
-
public class CollectionHelper extends Object
This class contains various Collection manipulation methods.
-
-
Constructor Summary
Constructors Constructor Description CollectionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleangetBooleanMapAttr(Map map, String name, boolean defaultValue)Gets a boolean attribute from aMap<String, Set<String>>, defaulting to the given default value if the attribute is not present.static booleangetBooleanMapAttrThrows(Map map, String name)Gets a boolean attribute from aMap<String, Set<String>>, throwing an exception if no boolean value (case insensitive comparisons against "true" or "false") is found for the given key.static intgetIntMapAttr(Map map, String name, int defaultValue, Debug debug)Returns integer value from a Map of String of Set of String.static intgetIntMapAttrThrows(Map map, String name)Returns integer value from a Map of String of Set of String.static Map<Locale,String>getLocaleMapAttrThrows(Map<String,Set<String>> map, String key)The key we are given must refer to an entry in the Map which is a set of lines of the form:
en_GB|Here is some text in English
fr_FR|Voici un texte en français
All the text must fit onto one line.static longgetLongMapAttr(Map<String,Set<String>> config, String name, long defaultValue, Debug debug)Returns a long value from the given configuration map.static longgetLongMapAttrThrows(Map<String,Set<String>> map, String name)Given the map attempts to return the named value as a long.static StringgetMapAttr(Map<?,?> map, String name)Returns String from a map of string to set of string.static StringgetMapAttr(Map map, String name, String defaultValue)Returns String from a map of string of set of string.static longgetMapAttrAsDateLong(Map<String,Set<String>> config, String name, org.slf4j.Logger logger)Returns the first attribute value for the corresponding name in the config map and parses it to a long.static StringgetMapAttrThrows(Map map, String key)Return String from a map of strings to set of strings.static Set<String>getMapSetThrows(Map<String,Set<String>> map, String key)Gets the set based on the passed key.static StringgetServerMapAttr(Map map, String attrName)This convenience method is for getting server specific attributes from a list attribute.static Set<String>getServerMapAttrs(Map<String,Set<String>> map, String attrName)This convenience method is for getting server specific attributes from a list attribute.
-
-
-
Method Detail
-
getMapAttr
public static String getMapAttr(Map<?,?> map, String name)
Returns String from a map of string to set of string.- Parameters:
map- Map of string to set of string.name- Key of the map entry.- Returns:
- String from a map of string to set of string
-
getMapAttr
public static String getMapAttr(Map map, String name, String defaultValue)
Returns String from a map of string of set of string.- Parameters:
map- Map of string of set of string.name- Key of the map entry.defaultValue- Default value if the string is not found.- Returns:
- String from a map of string of set of string
-
getMapAttrThrows
public static String getMapAttrThrows(Map map, String key) throws ValueNotFoundException
Return String from a map of strings to set of strings.- Parameters:
map- Map of string of set of string.name- Key of the map entry.- Returns:
- the String value from a map of strings to set of strings.
- Throws:
ValueNotFoundException- if no value is found for the key.
-
getMapSetThrows
public static Set<String> getMapSetThrows(Map<String,Set<String>> map, String key) throws ValueNotFoundException
Gets the set based on the passed key.- Parameters:
map- the mapkey- key to lookup- Returns:
- associated set
- Throws:
ValueNotFoundException- should the key not exist
-
getLocaleMapAttrThrows
public static Map<Locale,String> getLocaleMapAttrThrows(Map<String,Set<String>> map, String key) throws ValueNotFoundException
The key we are given must refer to an entry in the Map which is a set of lines of the form:
en_GB|Here is some text in English
fr_FR|Voici un texte en français
All the text must fit onto one line. If it does not, we are unlikely to be able to cope since lines will be retrieved from theSetin an almost random order. Also if you specify the same locale on two or more lines, only one can be added to the map (a random one due to the random order - although you will get a warning. Caveat administrator.- Parameters:
map- The map of strings (keys) to sets of stringskey- The key to use to access the map- Returns:
- A map of locales to localized text.
- Throws:
ValueNotFoundException- if the set of values we need are not present
-
getBooleanMapAttr
public static boolean getBooleanMapAttr(Map map, String name, boolean defaultValue)
Gets a boolean attribute from aMap<String, Set<String>>, defaulting to the given default value if the attribute is not present.- Parameters:
map- the attribute map.name- the name of the attribute to retrieve.defaultValue- the value to use if the attribute is not present.- Returns:
- the boolean value using
Boolean.parseBoolean(String).
-
getBooleanMapAttrThrows
public static boolean getBooleanMapAttrThrows(Map map, String name) throws ValueNotFoundException
Gets a boolean attribute from aMap<String, Set<String>>, throwing an exception if no boolean value (case insensitive comparisons against "true" or "false") is found for the given key.- Parameters:
map- the attribute map.name- the name of the attribute to retrieve.- Returns:
- the boolean value using
Boolean.parseBoolean(String). - Throws:
ValueNotFoundException- if no boolean value is found for the given key.
-
getIntMapAttr
public static int getIntMapAttr(Map map, String name, int defaultValue, Debug debug)
Returns integer value from a Map of String of Set of String.- Parameters:
map- Map of String of Set of String.name- Key of the map entry.defaultValue- Default value if the integer value is not found.debug- Debug object.- Returns:
- integer value from a Map of String of Set of String.
-
getIntMapAttrThrows
public static int getIntMapAttrThrows(Map map, String name) throws ValueNotFoundException
Returns integer value from a Map of String of Set of String.- Parameters:
map- Map of String of Set of String.name- Key of the map entry.- Returns:
- integer value from a Map of String of Set of String.
- Throws:
ValueNotFoundException- if there is no parsable value for the key provided.
-
getLongMapAttr
public static long getLongMapAttr(Map<String,Set<String>> config, String name, long defaultValue, Debug debug)
Returns a long value from the given configuration map.- Parameters:
config- the map of attribute values.name- the attribute name to get.defaultValue- the default value to use if the attribute is not set or is not a long.debug- the debug object to report format errors to.- Returns:
- the long value of the attribute or the defaultValue if not set/not a long.
-
getLongMapAttrThrows
public static long getLongMapAttrThrows(Map<String,Set<String>> map, String name) throws ValueNotFoundException
Given the map attempts to return the named value as a long.- Parameters:
map- the mapname- the named value- Returns:
- the corresponding long value
- Throws:
ValueNotFoundException- should the value fail to parse
-
getMapAttrAsDateLong
public static long getMapAttrAsDateLong(Map<String,Set<String>> config, String name, org.slf4j.Logger logger)
Returns the first attribute value for the corresponding name in the config map and parses it to a long.- Parameters:
config- The map where the attribute should be retrieved from.name- The name of the attribute that should be retrieved from the map.- Returns:
- The attribute from the map corresponding to the provided attribute name, parsed to a long. If the attribute does not exist the current date time will be returned.
-
getServerMapAttr
public static String getServerMapAttr(Map map, String attrName)
This convenience method is for getting server specific attributes from a list attribute. Server specific is determined by prefixing a list attribute value with DSAME local server name followed by the | character. If the list has more than one entry but no matching local server prefixes than null is returned as this is an invalid configuration for these type of attributes. This allows services like authentication to support a geographic directory configuration.- Parameters:
map- Map of String of Set of String.attrName- Key of the map entry of interest.- Returns:
- the server name.
-
getServerMapAttrs
public static Set<String> getServerMapAttrs(Map<String,Set<String>> map, String attrName)
This convenience method is for getting server specific attributes from a list attribute. Server specific is determined by prefixing a list attribute value with DSAME local server name followed by the | character. The priority order of the attributes as follows. 1- LDAP Servers belong to current OpenAM Server, localDsameServer is prefixed with the attribute 2- LDAP Servers belong to no OpenAM Server, no server prefix 3- All other servers - LDAP Servers prefixed with other OpenAM Servers This allows services like authentication to support a geographic directory configuration.- Parameters:
map- Map of String of Set of String.attrName- Key of the map entry of interest.- Returns:
- attributes based on the prioritization.
-
-