com.atlassian.jira.util
Class ParameterUtils

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

public class ParameterUtils
extends 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(Map mapOfParameters, String paramName)
          Returns a boolean value from the map of parameters.
static Date getDateParam(Map params, String s, Locale locale)
           
static Double getDoubleParam(Map params, String key)
           
static int getIntParam(Map mapOfParameters, String paramName, int defaultValue)
          Gets a int value from the map and uses the defaultValue if the value can be converted.
static List<String> getListFromStringArray(String[] ar)
           
static List getListParam(Map params, String key)
          Create a List from the parameter with the specified key.
static List getListParamKeepMinusOnes(Map params, String key)
           
static List<Long> getLongListFromStringArray(String[] ar)
          Given an array of Strings, return a list of Longs representing the IDs
static Long getLongParam(Map params, String key)
           
static String[] getStringArrayFromList(Collection entities)
          Given a collection of entities, return an array of Strings representing the IDs
static String[] getStringArrayParam(Map params, String paramName)
          Returns the value of the specified parameter name as a String[]
static String getStringParam(Map params, String key)
           
static String getStringParam(Map params, String targetKey, String targetValue, 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 User getUserParam(Map params, String s)
           
static String makeCommaSeparated(Long[] longs)
           
static List makeListLong(List list)
          Make a list of Strings into a list of Longs
static boolean paramContains(Map params, String key, String value)
          Checks if the given key, value pair exists in the given params Map
static Date parseDate(String paramValue, Locale locale)
           
static Collection swapNulls(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 Date getDateParam(Map params,
                                String s,
                                Locale locale)
                         throws ParameterUtils.DateTooEarlyException
Throws:
ParameterUtils.DateTooEarlyException

parseDate

public static Date parseDate(String paramValue,
                             Locale locale)

getUserParam

public static User getUserParam(Map params,
                                String s)

getListParam

public static List getListParam(Map params,
                                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 List getListParamKeepMinusOnes(Map params,
                                             String key)

makeListLong

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


getStringParam

public static String getStringParam(Map params,
                                    String key)

getStringArrayParam

public static String[] getStringArrayParam(Map params,
                                           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 String getStringParam(Map params,
                                    String targetKey,
                                    String targetValue,
                                    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(Map params,
                                    String key,
                                    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 Long getLongParam(Map params,
                                String key)

getIntParam

public static int getIntParam(Map mapOfParameters,
                              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(Map mapOfParameters,
                                      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 Double getDoubleParam(Map params,
                                    String key)

swapNulls

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


getLongListFromStringArray

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


getListFromStringArray

public static List<String> getListFromStringArray(String[] ar)

getStringArrayFromList

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


makeCommaSeparated

public static String makeCommaSeparated(Long[] longs)


Copyright © 2002-2009 Atlassian. All Rights Reserved.