net.abhinavsarkar.spelhelper
Class ExtensionFunctions

java.lang.Object
  extended by net.abhinavsarkar.spelhelper.ExtensionFunctions

public final class ExtensionFunctions
extends Object

Provides some extension functions to create some basic collection types inline in SpEL expressions. These functions are automatically registered with SpelHelper .

See Also: Spring Docs on extension functions

Author:
Abhinav Sarkar abhinav@abhinavsarkar.net

Method Summary
static
<T> List<T>
list(T... args)
          Creates an unmodifiable List of the arguments provided.
static
<K,V> Map<K,V>
map(List<? extends K> keys, List<? extends V> values)
          Creates an unmodifiable Map using the List of keys provided as the first argument and the List of values provided as the second argument.
static
<T> Set<T>
set(T... args)
          Creates an unmodifiable Set of the arguments provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

list

public static <T> List<T> list(T... args)

Creates an unmodifiable List of the arguments provided.

Example use: "#list('one', 'two', 'three')"

Type Parameters:
T - Type of the arguments provided.
Parameters:
args - Arguments to create list of.
Returns:
An unmodifiable list of the arguments provided.

set

public static <T> Set<T> set(T... args)

Creates an unmodifiable Set of the arguments provided.

Example use: "#set('one', 'two', 'three')"

Type Parameters:
T - Type of the arguments provided.
Parameters:
args - Arguments to create set of.
Returns:
An unmodifiable set of the arguments provided.

map

public static <K,V> Map<K,V> map(List<? extends K> keys,
                                 List<? extends V> values)

Creates an unmodifiable Map using the List of keys provided as the first argument and the List of values provided as the second argument.

Example use: "#map(#list('one', 'two', 'three'), #list(1, 2, 3))"

Type Parameters:
K - Type of the keys of the map.
V - Type of the values of map.
Parameters:
keys - List of the keys.
values - List of the values.
Returns:
A unmodifiable map created from the key and value lists.
Throws:
IllegalArgumentException - if the number of keys and the number of values is not equal.

Code hosted at github

Copyright © 2010. All Rights Reserved.