net.abhinavsarkar.spelhelper
Class ImplicitMethods

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

public final class ImplicitMethods
extends Object

Provides some implicit methods which can be invoked on the instances of class of the first parameter of the method inside a SpEL expression.

Author:
Abhinav Sarkar abhinav@abhinavsarkar.net

Constructor Summary
ImplicitMethods()
           
 
Method Summary
static
<T> Set<T>
distinct(List<? extends T> list)
          Provides implicit method distinct on the List class.
static
<T> List<T>
drop(List<T> list, int n)
          Provides implicit method drop on the List class.
static
<T> List<T>
reversed(List<? extends T> list)
          Provides implicit method reversed on the List class.
static
<T extends Comparable<? super T>>
List<T>
sorted(List<? extends T> list)
          Provides implicit method sorted on the List class.
static
<T> List<T>
take(List<T> list, int n)
          Provides implicit method take on the List class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImplicitMethods

public ImplicitMethods()
Method Detail

distinct

public static <T> Set<T> distinct(List<? extends T> list)

Provides implicit method distinct on the List class.

Example: "#list('a','b','a').distinct()" //should return List('a','b')

With implicit property support provided by SpelHelper this can also be written as:

"#list('a','b','a').distinct" //same output as earlier

Type Parameters:
T - Type of the list's elements.
Parameters:
list - The list to call this method upon.
Returns:
An unmodifiable Set containing the distinct items of the list.

sorted

public static <T extends Comparable<? super T>> List<T> sorted(List<? extends T> list)

Provides implicit method sorted on the List class.

Example: "#list('c','b','a').sorted()" //should return List('a','b','c')

With implicit property support provided by SpelHelper this can also be written as:

"#list('c','b','a').sorted" //same output as earlier

Type Parameters:
T - Type of the list's elements.
Parameters:
list - The list to call this method upon.
Returns:
An unmodifiable List containing the sorted items of the list.
See Also:
Collections.sort(List)

reversed

public static <T> List<T> reversed(List<? extends T> list)

Provides implicit method reversed on the List class.

Example: "#list('c','b','a').reversed()" //should return List('a','b','c')

With implicit property support provided by SpelHelper this can also be written as:

"#list('c','b','a').reversed" //same output as earlier

Type Parameters:
T - Type of the list's elements.
Parameters:
list - The list to call this method upon.
Returns:
An unmodifiable List containing the items of the list in reverse order.
See Also:
Collections.reverse(List)

take

public static <T> List<T> take(List<T> list,
                               int n)

Provides implicit method take on the List class.

Example: "#list('c','b','a').take(2)" //should return List('a','b')

Type Parameters:
T - Type of the list's elements.
Parameters:
list - The list to call this method upon.
n - Number of items to take from the list.
Returns:
An unmodifiable List containing the first n items of the list.

drop

public static <T> List<T> drop(List<T> list,
                               int n)

Provides implicit method drop on the List class.

Example: "#list('c','b','a').drop(2)" //should return List('a')

Type Parameters:
T - Type of the list's elements.
Parameters:
list - The list to call this method upon.
n - Number of items to drop from the list.
Returns:
An unmodifiable List containing the items after the first n items of the list.

Code hosted at github

Copyright © 2010. All Rights Reserved.