com.atlassian.jira.util
Class ParameterUtils

java.lang.Object
  extended by com.atlassian.jira.util.ParameterUtils

public class ParameterUtils
extends java.lang.Object

This class can be used to "parse" values from a map of parameters. This is really intended to be used in Action code that needs to read input parameters from ActionContext.getParameters() }


Nested Class Summary
static class ParameterUtils.DateTooEarlyException
           
 
Constructor Summary
ParameterUtils()
           
 
Method Summary
static boolean getBooleanParam(java.util.Map mapOfParameters, java.lang.String paramName)
          Returns a boolean value from the map of parameters.
static java.util.Date getDateParam(java.util.Map params, java.lang.String s, java.util.Locale locale)
           
static java.lang.Double getDoubleParam(java.util.Map params, java.lang.String key)
           
static int getIntParam(java.util.Map mapOfParameters, java.lang.String paramName, int defaultValue)
          Gets a int value from the map and uses the defaultValue if the value can be converted.
static java.util.List<java.lang.String> getListFromStringArray(java.lang.String[] ar)
           
static java.util.List getListParam(java.util.Map params, java.lang.String key)
          Create a List from the parameter with the specified key.
static java.util.List getListParamKeepMinusOnes(java.util.Map params, java.lang.String key)
           
static java.util.List<java.lang.Long> getLongListFromStringArray(java.lang.String[] ar)
          Given an array of Strings, return a list of Longs representing the IDs
static java.lang.Long getLongParam(java.util.Map params, java.lang.String key)
           
static java.lang.String[] getStringArrayFromList(java.util.Collection entities)
          Given a collection of entities, return an array of Strings representing the IDs
static java.lang.String[] getStringArrayParam(java.util.Map params, java.lang.String paramName)
          Returns the value of the specified parameter name as a String[]
static java.lang.String getStringParam(java.util.Map params, java.lang.String key)
           
static java.lang.String getStringParam(java.util.Map params, java.lang.String targetKey, java.lang.String targetValue, java.lang.String desiredKey)
          Searches through the Map (params) for the given targetKey and targetValue extracting the index (i) and uses this to extract the corresponding index value with the desiredKey.
static com.opensymphony.user.User getUserParam(java.util.Map params, java.lang.String s)
           
static java.lang.String makeCommaSeparated(java.lang.Long[] longs)
           
static java.util.List makeListLong(java.util.List list)
          Make a list of Strings into a list of Longs
static boolean paramContains(java.util.Map params, java.lang.String key, java.lang.String value)
          Checks if the given key, value pair exists in the given params Map
static java.util.Date parseDate(java.lang.String paramValue, java.util.Locale locale)
           
static java.util.Collection swapNulls(java.util.Collection col)
          Convert all null values in a collection into "-1"s.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParameterUtils

public ParameterUtils()
Method Detail

getDateParam

public static java.util.Date getDateParam(java.util.Map params,
                                          java.lang.String s,
                                          java.util.Locale locale)
                                   throws ParameterUtils.DateTooEarlyException
Throws:
ParameterUtils.DateTooEarlyException

parseDate

public static java.util.Date parseDate(java.lang.String paramValue,
                                       java.util.Locale locale)

getUserParam

public static com.opensymphony.user.User getUserParam(java.util.Map params,
                                                      java.lang.String s)

getListParam

public static java.util.List getListParam(java.util.Map params,
                                          java.lang.String key)
Create a List from the parameter with the specified key.

Returns:
null if the object is not a String array, or has no elements
otherwise it returns a List containing all elements of the String array, with the Strings over value ("-1") turned into null's. (Strings with value "" are ignored).

getListParamKeepMinusOnes

public static java.util.List getListParamKeepMinusOnes(java.util.Map params,
                                                       java.lang.String key)

makeListLong

public static java.util.List makeListLong(java.util.List list)
Make a list of Strings into a list of Longs


getStringParam

public static java.lang.String getStringParam(java.util.Map params,
                                              java.lang.String key)

getStringArrayParam

public static java.lang.String[] getStringArrayParam(java.util.Map params,
                                                     java.lang.String paramName)
Returns the value of the specified parameter name as a String[]

Parameters:
params - the map of parameters
paramName - the name of the parameter
Returns:
a String[] of values or null if there are no parameters

getStringParam

public static java.lang.String getStringParam(java.util.Map params,
                                              java.lang.String targetKey,
                                              java.lang.String targetValue,
                                              java.lang.String desiredKey)
Searches through the Map (params) for the given targetKey and targetValue extracting the index (i) and uses this to extract the corresponding index value with the desiredKey. if there is no match, the first value or null is returned

Returns:
desiredValue - corresponding value to desiredKey with the same index as the targetKey and targetValue, or the first value if there is only one, otherwise null

paramContains

public static boolean paramContains(java.util.Map params,
                                    java.lang.String key,
                                    java.lang.String value)
Checks if the given key, value pair exists in the given params Map

Parameters:
params - the map of web parameters
key - the name of the parameter to check
value - the value to check for
Returns:
true of this key/value pair exists

getLongParam

public static java.lang.Long getLongParam(java.util.Map params,
                                          java.lang.String key)

getIntParam

public static int getIntParam(java.util.Map mapOfParameters,
                              java.lang.String paramName,
                              int defaultValue)
Gets a int value from the map and uses the defaultValue if the value can be converted.

Parameters:
mapOfParameters - the map of parameters
paramName - the parameter name to use
defaultValue - the default value in case things cant be converted
Returns:
the converted value or the defaultValue if it cant be converted

getBooleanParam

public static boolean getBooleanParam(java.util.Map mapOfParameters,
                                      java.lang.String paramName)
Returns a boolean value from the map of parameters. if it does no exist in the map, then false is returned

Parameters:
mapOfParameters - the map of parameters
paramName - the parameter name to use
Returns:
true if the value converted to true or false otherwise

getDoubleParam

public static java.lang.Double getDoubleParam(java.util.Map params,
                                              java.lang.String key)

swapNulls

public static java.util.Collection swapNulls(java.util.Collection col)
Convert all null values in a collection into "-1"s.


getLongListFromStringArray

public static java.util.List<java.lang.Long> getLongListFromStringArray(java.lang.String[] ar)
Given an array of Strings, return a list of Longs representing the IDs


getListFromStringArray

public static java.util.List<java.lang.String> getListFromStringArray(java.lang.String[] ar)

getStringArrayFromList

public static java.lang.String[] getStringArrayFromList(java.util.Collection entities)
Given a collection of entities, return an array of Strings representing the IDs


makeCommaSeparated

public static java.lang.String makeCommaSeparated(java.lang.Long[] longs)


Copyright © 2002-2010 Atlassian. All Rights Reserved.