org.nuiton.util.decorator
Class DecoratorUtil

java.lang.Object
  extended by org.nuiton.util.decorator.DecoratorUtil

public class DecoratorUtil
extends Object

Some usefull methods on Decorator to create, and sort data with decorators.

To create a new decorator, use one of the methods :

To sort a list of data, using a JXPathDecorator, use the method sort(JXPathDecorator, List, int).

Since:
2.3
Author:
tchemit

Constructor Summary
DecoratorUtil()
           
 
Method Summary
static
<O> JXPathDecorator.Context<O>
createJXPathContext(String expression)
           
static
<O> JXPathDecorator.Context<O>[]
createMultiJXPathContext(String expression, String separator, String separatorReplacement)
           
protected static
<O> JXPathDecorator.Context<O>[]
newInstance(int size)
           
static
<O> JXPathDecorator<O>
newJXPathDecorator(Class<O> type, String expression)
          Factory method to instanciate a new JXPathDecorator for the given class internalClass and expression.
static
<O> MultiJXPathDecorator<O>
newMultiJXPathDecorator(Class<O> type, String expression, String separator)
           
static
<O> MultiJXPathDecorator<O>
newMultiJXPathDecorator(Class<O> type, String expression, String separator, String separatorReplacement)
           
static
<O> PropertyDecorator<O>
newPropertyDecorator(Class<O> type, String property)
          Factory method to instanciate a new PropertyDecorator for the given class internlaClass and a readable property name.
static
<O> void
sort(JXPathDecorator<O> decorator, List<O> datas, int pos)
          Sort a list of data based on the first token property of a given context in a given decorator.
static
<O> void
sort(JXPathDecorator<O> decorator, List<O> datas, int pos, boolean reverse)
          Sort a list of data based on the first token property of a given context in a given decorator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DecoratorUtil

public DecoratorUtil()
Method Detail

newPropertyDecorator

public static <O> PropertyDecorator<O> newPropertyDecorator(Class<O> type,
                                                            String property)
                                                 throws IllegalArgumentException,
                                                        NullPointerException
Factory method to instanciate a new PropertyDecorator for the given class internlaClass and a readable property name.

Type Parameters:
O - the generic type of class to be decorated by the new decorator
Parameters:
type - the class of the objects decorated by the new decorator
property - the property
Returns:
the new instanciated decorator
Throws:
IllegalArgumentException - if the expression is not valid, says:

- a missing right brace was detected.

- a ${ was found in a jxpath token.

NullPointerException - if type parameter is null.

newJXPathDecorator

public static <O> JXPathDecorator<O> newJXPathDecorator(Class<O> type,
                                                        String expression)
                                             throws IllegalArgumentException,
                                                    NullPointerException
Factory method to instanciate a new JXPathDecorator for the given class internalClass and expression.

Type Parameters:
O - the generic type of class to be decorated by the new decorator
Parameters:
type - the class of the objects decorated by the new decorator
expression - the expression to use to decorated objects
Returns:
the new instanciated decorator
Throws:
IllegalArgumentException - if the expression is not valid, says:

- a missing right brace was detected.

- a ${ was found in a jxpath token.

NullPointerException - if type parameter is null.

newMultiJXPathDecorator

public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator(Class<O> type,
                                                                  String expression,
                                                                  String separator)
                                                       throws IllegalArgumentException,
                                                              NullPointerException
Throws:
IllegalArgumentException
NullPointerException

newMultiJXPathDecorator

public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator(Class<O> type,
                                                                  String expression,
                                                                  String separator,
                                                                  String separatorReplacement)
                                                       throws IllegalArgumentException,
                                                              NullPointerException
Throws:
IllegalArgumentException
NullPointerException

sort

public static <O> void sort(JXPathDecorator<O> decorator,
                            List<O> datas,
                            int pos)
Sort a list of data based on the first token property of a given context in a given decorator.

Type Parameters:
O - type of data to sort
Parameters:
decorator - the decorator to use to sort
datas - the list of data to sort
pos - the index of context to used in decorator to obtain sorted property.

sort

public static <O> void sort(JXPathDecorator<O> decorator,
                            List<O> datas,
                            int pos,
                            boolean reverse)
Sort a list of data based on the first token property of a given context in a given decorator.

Type Parameters:
O - type of data to sort
Parameters:
decorator - the decorator to use to sort
datas - the list of data to sort
pos - the index of context to used in decorator to obtain sorted property.
reverse - flag to sort in reverse order if sets to true
Since:
2.2

createJXPathContext

public static <O> JXPathDecorator.Context<O> createJXPathContext(String expression)

createMultiJXPathContext

public static <O> JXPathDecorator.Context<O>[] createMultiJXPathContext(String expression,
                                                                        String separator,
                                                                        String separatorReplacement)

newInstance

protected static <O> JXPathDecorator.Context<O>[] newInstance(int size)


Copyright © 2004-2012 CodeLutin. All Rights Reserved.