|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.josql.functions.AbstractFunctionHandler org.josql.functions.CollectionFunctions
public class CollectionFunctions
Defines a set of functions that operate on "collections" of objects in some way.
Field Summary | |
---|---|
static String |
HANDLER_ID
The id that can be used to get the "CollectionFunctions" handler object from the Query object. |
Fields inherited from class org.josql.functions.AbstractFunctionHandler |
---|
q |
Constructor Summary | |
---|---|
CollectionFunctions()
|
Method Summary | |
---|---|
List |
collect(Expression exp)
|
List |
collect(List allobjs,
Expression exp)
|
List |
collect(List objs,
Expression exp,
String saveValueName)
|
int |
count(Expression exp)
|
int |
count(List allobjs,
Expression exp)
|
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. |
List |
find(List objs,
Expression exp)
Find objects from the List based upon the expression passed in. |
List |
foreach(Expression exp)
|
List |
foreach(Expression listFunction,
Expression exp)
|
List |
foreach(List allobjs,
Expression exp)
|
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. |
Object |
get(List l,
Number n)
Get a value from the specified List. |
Object |
get(Map m,
Expression exp)
Get a value from the specified Map. |
Map |
grp(List objs,
Expression exp)
Group objects from the List based upon the expression passed in. |
Map |
map(List objs,
Expression exp)
Create a map of the objects passed in, the key will be the object in the list and the value will be the result of calling the expression on the object. |
Map |
map(List objs,
Expression keyExp,
Expression valExp)
Create a map of the objects passed in, the key will be the result of calling the keyExp expression on the object in the list and the value will be the result of calling the valExp expression on the object. |
List |
sort(List objs)
Sort a list according to it's "natural" ordering (see Collections.sort(List) ). |
List |
sort(Map m)
Sort a Map by the keys in ascending order (for more optionality in the sort and ordering see: sort(Map,String,String) ). |
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: sort(Map,String,String) ). |
List |
sort(Map m,
String type,
String dir)
Sort a Map by either it's key or value. |
List |
toList(Expression exp)
|
List |
toList(List allobjs,
Expression exp)
|
List |
toList(List allobjs,
Expression exp,
String saveValueName)
|
List |
unique(Expression exp)
|
List |
unique(List objs)
|
List |
unique(List objs,
Expression exp)
|
Methods inherited from class org.josql.functions.AbstractFunctionHandler |
---|
setQuery |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String HANDLER_ID
Constructor Detail |
---|
public CollectionFunctions()
Method Detail |
---|
public List sort(List objs)
Collections.sort(List)
).
objs
- The list of objects to sort.
public List sort(Map m)
sort(Map,String,String)
).
m
- The map to sort.
public List sort(Map m, String type)
sort(Map,String,String)
).
m
- The map to sort.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)
m
- The map to sort.type
- Should be either: "key" or "value" to indicate which item to sort on.
Use null
for key.dir
- The direction you want to sort on, either "asc" or "desc". Use null
for "asc".
public Object get(Map m, Expression exp) throws QueryExecutionException
m
- The map of objects.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.
QueryExecutionException
public Object get(List l, Number n)
l
- The list of objects.n
- The index, indices start at 0.
null
if n is out of range.public int count(List objs, Expression exp, Object value) throws QueryExecutionException
Boolean.valueOf(String)
.
objs
- The list of objects to iterate over.exp
- The expression to use to get the value from the object in the List.value
- The value to compare the result of the accessor against. If the parm is null
then it defaults to Boolean.FALSE
.
QueryExecutionException
- If the value from the accessor cannot be gained or if
the compare cannot be performed.public int count(Expression exp) throws QueryExecutionException
QueryExecutionException
public int count(List allobjs, Expression exp) throws QueryExecutionException
QueryExecutionException
public List toList(List allobjs, Expression exp, String saveValueName) throws QueryExecutionException
QueryExecutionException
public List unique(List objs)
public List unique(Expression exp) throws QueryExecutionException
QueryExecutionException
public List unique(List objs, Expression exp) throws QueryExecutionException
QueryExecutionException
public List collect(List objs, Expression exp, String saveValueName) throws QueryExecutionException
QueryExecutionException
public List collect(Expression exp) throws QueryExecutionException
QueryExecutionException
public List collect(List allobjs, Expression exp) throws QueryExecutionException
QueryExecutionException
public List toList(Expression exp) throws QueryExecutionException
QueryExecutionException
public List toList(List allobjs, Expression exp) throws QueryExecutionException
QueryExecutionException
public List foreach(Expression exp) throws QueryExecutionException
QueryExecutionException
public List foreach(List allobjs, Expression exp) throws QueryExecutionException
QueryExecutionException
public List foreach(List objs, String exp) throws QueryExecutionException
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.
objs
- The list of objects.exp
- The expression (basically a where clause, it is ok for the expression
to start with "WHERE", case-insensitive) to execute for each of the
objects.
QueryExecutionException
public List foreach(Expression listFunction, Expression exp) throws QueryExecutionException
QueryExecutionException
public List find(List objs, Expression exp) throws QueryExecutionException
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.
objs
- The List of objects to search.exp
- The expression to evaulate against each object in the List.
QueryExecutionException
- If the expression cannot be evaulated against each
object.public Map grp(List objs, Expression exp) throws QueryExecutionException
Expression.getValue(Object,Query)
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.
objs
- The List of objects to search.exp
- The expression to evaulate against each object in the List.
QueryExecutionException
- If the expression cannot be evaulated against each
object.public Map map(List objs, Expression exp) throws QueryExecutionException
Expression.getValue(Object,Query)
and the return value used as the value to the Map. 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.
objs
- The List of objects to map.exp
- The expression to evaulate against each object in the List.
QueryExecutionException
- If the expression cannot be evaulated against each
object.public Map map(List objs, Expression keyExp, Expression valExp) throws QueryExecutionException
Expression.getValue(Object,Query)
and the return value used as the value to the Map. 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.
objs
- The List of objects to map.exp
- The expression to evaulate against each object in the List.
QueryExecutionException
- If the expression cannot be evaulated against each
object.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |