org.vladnput
Class VladUtil

java.lang.Object
  extended by org.vladnput.VladUtil

public class VladUtil
extends java.lang.Object

Various static utility routines.

Author:
Patrick Higgins

Field Summary
static java.util.regex.Pattern INTERPOLATE_REGEX
          The regular expression defining what variables in message bodies look like.
 
Method Summary
static java.lang.Boolean booleanKey(java.util.Map<java.lang.String,java.lang.Object> args, java.lang.String key)
          Removes and returns the mapping associated with key in args, or null if there is not one.
static java.util.Date dateKey(java.util.Map<java.lang.String,java.lang.Object> args, java.lang.String key, java.text.DateFormat format)
          Removes and returns the string mapping associated with key in args after parsing it as a date, or null if there is not one.
static java.lang.Double floatKey(java.util.Map<java.lang.String,java.lang.Object> args, java.lang.String key)
          Removes and returns the mapping associated with key in args, or null if there is not one.
static java.lang.Integer integerKey(java.util.Map<java.lang.String,java.lang.Object> args, java.lang.String key)
          Removes and returns the mapping associated with key in args, or null if there is not one.
static java.lang.String interpolate(java.lang.String text, VladMessageVars vars)
          Replaces all variable references within text with the variable values in vars.
static
<V> java.util.ArrayList<V>
newArrayList()
          Uses type-inference to make ArrayList declarations compact.
static
<K,V> java.util.HashMap<K,V>
newHashMap()
          Uses type-inference to make HashMap declarations compact.
static
<V> java.util.HashSet<V>
newHashSet()
          Uses type-inference to make HashSet declarations compact.
static
<K,V> java.util.LinkedHashMap<K,V>
newLinkedHashMap()
          Uses type-inference to make LinkedHashMap declarations compact.
static java.util.Date parseDate(java.lang.String value, java.text.DateFormat format)
          Parses value as a date using format.
static java.lang.String stringKey(java.util.Map<java.lang.String,java.lang.Object> args, java.lang.String key)
          Removes and returns the mapping associated with key in args, or null if there is not one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERPOLATE_REGEX

public static final java.util.regex.Pattern INTERPOLATE_REGEX
The regular expression defining what variables in message bodies look like.

Method Detail

stringKey

public static java.lang.String stringKey(java.util.Map<java.lang.String,java.lang.Object> args,
                                         java.lang.String key)
Removes and returns the mapping associated with key in args, or null if there is not one.

Parameters:
args - Arguments
key - Argument name
Returns:
Argument value, or null if there is not one.

integerKey

public static java.lang.Integer integerKey(java.util.Map<java.lang.String,java.lang.Object> args,
                                           java.lang.String key)
Removes and returns the mapping associated with key in args, or null if there is not one.

Parameters:
args - Arguments
key - Argument name
Returns:
Argument value, or null if there is not one.

floatKey

public static java.lang.Double floatKey(java.util.Map<java.lang.String,java.lang.Object> args,
                                        java.lang.String key)
Removes and returns the mapping associated with key in args, or null if there is not one.

Parameters:
args - Arguments
key - Argument name
Returns:
Argument value, or null if there is not one.

booleanKey

public static java.lang.Boolean booleanKey(java.util.Map<java.lang.String,java.lang.Object> args,
                                           java.lang.String key)
Removes and returns the mapping associated with key in args, or null if there is not one.

Parameters:
args - Arguments
key - Argument name
Returns:
Argument value, or null if there is not one.

dateKey

public static java.util.Date dateKey(java.util.Map<java.lang.String,java.lang.Object> args,
                                     java.lang.String key,
                                     java.text.DateFormat format)
                              throws java.lang.IllegalArgumentException
Removes and returns the string mapping associated with key in args after parsing it as a date, or null if there is not one.

Parameters:
args - Arguments
key - Argument name
format - Date format
Returns:
Argument value, or null if there is not one.
Throws:
java.lang.IllegalArgumentException - If the date is invalid

parseDate

public static java.util.Date parseDate(java.lang.String value,
                                       java.text.DateFormat format)
                                throws java.lang.IllegalArgumentException
Parses value as a date using format. Returns null if value is null. Uses DateFormat.getDateInstance() if format is null.

Parameters:
value - Value to parse
format - Date format
Returns:
Parsed value, or null if value is null
Throws:
java.lang.IllegalArgumentException - If the date is invalid

interpolate

public static java.lang.String interpolate(java.lang.String text,
                                           VladMessageVars vars)
Replaces all variable references within text with the variable values in vars.

Parameters:
text - Text to replace variables in
vars - Variable values to replace with
Returns:
Text with variables replace

newHashMap

public static <K,V> java.util.HashMap<K,V> newHashMap()
Uses type-inference to make HashMap declarations compact. You can write Map m = VladUtil.newHashMap() instead of the more verbose Map m = new HashMap()


newLinkedHashMap

public static <K,V> java.util.LinkedHashMap<K,V> newLinkedHashMap()
Uses type-inference to make LinkedHashMap declarations compact. You can write Map m = VladUtil.newLinkedHashMap() instead of the more verbose Map m = new LinkedHashMap()


newArrayList

public static <V> java.util.ArrayList<V> newArrayList()
Uses type-inference to make ArrayList declarations compact. You can write List l = VladUtil.newArrayList() instead of the more verbose List l = new ArrayList()


newHashSet

public static <V> java.util.HashSet<V> newHashSet()
Uses type-inference to make HashSet declarations compact. You can write Set s = VladUtil.newHashSet() instead of the more verbose Set s = new HashSet()



Copyright © 2009 Patrick Higgins. All Rights Reserved.