| java.lang.Object org.josql.functions.AbstractFunctionHandler org.josql.functions.CollectionFunctions
CollectionFunctions | public class CollectionFunctions extends AbstractFunctionHandler (Code) | | Defines a set of functions that operate on "collections" of objects in some way.
|
Field Summary | |
final public static String | HANDLER_ID The id that can be used to get the "CollectionFunctions" handler object from
the Query object. |
Method Summary | |
public List | collect(List objs, Expression exp, String saveValueName) | public List | collect(Expression exp) | public List | collect(List allobjs, Expression exp) | public int | count(List objs, Expression exp, Object value) For each of the objects in the objs List get the value from each one
using the accessor and compare it to the value parameter. | public int | count(Expression exp) | public int | count(List allobjs, Expression exp) | public List | find(List objs, Expression exp) Find objects from the List based upon the expression passed in. | public List | foreach(Expression exp) | public List | foreach(List allobjs, Expression exp) | public List | foreach(List objs, String exp) Given a list of objects, execute the expression against each one and return
those objects that return a true value for the expression.
In effect this is equivalent to executing the WHERE clause of a JoSQL statement
against each object (which in fact is what happens internally). | public List | foreach(Expression listFunction, Expression exp) | public Object | get(Map m, Expression exp) Get a value from the specified Map.
Parameters: m - The map of objects. Parameters: exp - The expression is evaluated (in the context of the current object) and the value returned used as the key to the Map, the value it maps to (which may be null) is returned. | public Object | get(List l, Number n) Get a value from the specified List.
Parameters: l - The list of objects. Parameters: n - The index, indices start at 0. | public Map | grp(List objs, Expression exp) Group objects from the List based upon the expression passed in. | public List | sort(List objs) Sort a list according to it's "natural" ordering (see
Collections.sort(List) ).
Parameters: objs - The list of objects to sort. | public List | sort(Map m) Sort a Map by the keys in ascending order (for more optionality in the sort and ordering
see:
CollectionFunctions.sort(Map,String,String) ).
Parameters: m - The map to sort. | public List | sort(Map m, String type) Sort a Map by it's keys or values in ascending order (for more optionality in the sort and ordering
see:
CollectionFunctions.sort(Map,String,String) ).
Parameters: m - The map to sort. Parameters: type - Should be either: "key" or "value" to indicate which item to sort on.Use null for key. | public List | sort(Map m, String type, String dir) Sort a Map by either it's key or value.
Parameters: m - The map to sort. Parameters: type - Should be either: "key" or "value" to indicate which item to sort on.Use null for key. Parameters: dir - The direction you want to sort on, either "asc" or "desc". | public List | toList(List allobjs, Expression exp, String saveValueName) | public List | toList(Expression exp) | public List | toList(List allobjs, Expression exp) | public List | unique(List objs) | public List | unique(Expression exp) | public List | unique(List objs, Expression exp) |
HANDLER_ID | final public static String HANDLER_ID(Code) | | The id that can be used to get the "CollectionFunctions" handler object from
the Query object.
|
count | public int count(List objs, Expression exp, Object value) throws QueryExecutionException(Code) | | For each of the objects in the objs List get the value from each one
using the accessor and compare it to the value parameter. The value
param is converted to a string and then to a Boolean value using:
Boolean.valueOf(String) .
Parameters: objs - The list of objects to iterate over. Parameters: exp - The expression to use to get the value from the object in the List. Parameters: value - The value to compare the result of the accessor against. If the parm is null then it defaults to Boolean.FALSE. A count of how many times the accessor evaluated to the same value of the value parm. throws: QueryExecutionException - If the value from the accessor cannot be gained or ifthe compare cannot be performed. |
find | public List find(List objs, Expression exp) throws QueryExecutionException(Code) | | Find objects from the List based upon the expression passed in. If
the expression evaluates to true then the object will
be returned.
Note: in accordance with the general operating methodology for the Query
object, the ":_allobjs" special bind variable will be set to the
the List passed in and the "_currobj" will be set to the relevant
object in the List.
Parameters: objs - The List of objects to search. Parameters: exp - The expression to evaulate against each object in the List. The List of matching objects, if none match then an empty list is returned. throws: QueryExecutionException - If the expression cannot be evaulated against eachobject. |
foreach | public List foreach(List objs, String exp) throws QueryExecutionException(Code) | | Given a list of objects, execute the expression against each one and return
those objects that return a true value for the expression.
In effect this is equivalent to executing the WHERE clause of a JoSQL statement
against each object (which in fact is what happens internally). The class
for the objects if found by examining the list passed in.
Parameters: objs - The list of objects. Parameters: exp - The expression (basically a where clause, it is ok for the expressionto start with "WHERE", case-insensitive) to execute for each of theobjects. The list of matching objects. |
get | public Object get(Map m, Expression exp) throws QueryExecutionException(Code) | | Get a value from the specified Map.
Parameters: m - The map of objects. Parameters: exp - The expression is evaluated (in the context of the current object) and the value returned used as the key to the Map, the value it maps to (which may be null) is returned. The value that the exp value maps to, may be null. |
get | public Object get(List l, Number n)(Code) | | Get a value from the specified List.
Parameters: l - The list of objects. Parameters: n - The index, indices start at 0. The value of the ith element from the list of objects. Return null if n is out of range. |
grp | public Map grp(List objs, Expression exp) throws QueryExecutionException(Code) | | Group objects from the List based upon the expression passed in. The expression
is evaulated for each object, by calling:
Expression.getValue(ObjectQuery) and the return value used as the key to the Map. All objects with that value are
added to a List held against the key. To maintain the ordering of the keys (if
desirable) a
LinkedHashMap is used as the return Map.
Note: in accordance with the general operating methodology for the Query
object, the ":_allobjs" special bind variable will be set to the
the List passed in and the "_currobj" will be set to the relevant
object in the List.
Parameters: objs - The List of objects to search. Parameters: exp - The expression to evaulate against each object in the List. The LinkedHashMap of matching objects, grouped according to the return valueof executing the expression against each object in the input List. throws: QueryExecutionException - If the expression cannot be evaulated against eachobject. |
sort | public List sort(List objs)(Code) | | Sort a list according to it's "natural" ordering (see
Collections.sort(List) ).
Parameters: objs - The list of objects to sort. The sorted list, according to their natural ordering. |
sort | public List sort(Map m, String type)(Code) | | Sort a Map by it's keys or values in ascending order (for more optionality in the sort and ordering
see:
CollectionFunctions.sort(Map,String,String) ).
Parameters: m - The map to sort. Parameters: type - Should be either: "key" or "value" to indicate which item to sort on.Use null for key. A List sorted according to the key in ascending order. |
sort | public List sort(Map m, String type, String dir)(Code) | | Sort a Map by either it's key or value.
Parameters: m - The map to sort. Parameters: type - Should be either: "key" or "value" to indicate which item to sort on.Use null for key. Parameters: dir - The direction you want to sort on, either "asc" or "desc". Use null for "asc". A List sorted according to the key or value. |
Methods inherited from org.josql.functions.AbstractFunctionHandler | public void setQuery(Query q)(Code)(Java Doc)
|
|
|