org.jage.query
Class CollectionQuery<E,T>

java.lang.Object
  extended by org.jage.query.MultiElementQuery<E,Collection<E>,Collection<T>>
      extended by org.jage.query.CollectionQuery<E,T>
Type Parameters:
E - A type of elements in the queried collection.
T - A type of elements in the result.
All Implemented Interfaces:
IQuery<Collection<E>,Collection<T>>
Direct Known Subclasses:
PropertyContainerCollectionQuery

public class CollectionQuery<E,T>
extends MultiElementQuery<E,Collection<E>,Collection<T>>

Query implementation that can be used with subclasses of the Collection class. The queried object must be an instance of the Collection class and the provided results also are of this type.

Author:
AGH AgE Team

Field Summary
 
Fields inherited from class org.jage.query.MultiElementQuery
elementClass, functions, initialSelectors, resultClass, targetClass, valueFilter, valueSelectors
 
Constructor Summary
CollectionQuery(Class<?> elementClass)
          Constructs a new CollectionQuery instance.
CollectionQuery(Class<?> elementClass, Class<?> targetClass, Class<?> resultClass)
          Constructs a new CollectionQuery instance.
 
Method Summary
protected  Collection<T> convertToResult(List<?> newSelected)
          Converts a provided list of selected elements (raw results of the query) to the object of the type required (and specified) by the user.
 CollectionQuery<E,T> from(IInitialSelector selector)
          Adds a selector to the query.
 CollectionQuery<E,T> matching(IValueFilter<E> filter)
          Adds a value filter to the query.
<S> CollectionQuery<E,T>
matching(String fieldName, IValueFilter<S> filter)
          Adds a value filter that operates on a specific field of the element class to the query.
 CollectionQuery<E,T> process(IQueryFunction<Collection<T>> queryFunction)
          Adds a function that will process results.
<S> CollectionQuery<E,T>
select(IValueSelector<E,S> valueSelector)
          Adds a selector to the query.
 CollectionQuery<E,T> select(String... fields)
          Adds a selector to the query.
 
Methods inherited from class org.jage.query.MultiElementQuery
addInitialSelector, addQueryFunction, addValueFilter, addValueSelector, execute, getListFromTarget
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionQuery

public CollectionQuery(Class<?> elementClass,
                       Class<?> targetClass,
                       Class<?> resultClass)
Constructs a new CollectionQuery instance. CollectionQuery requires the target, the result and the element class being provided. It will use them for creating the result object.

The execution of an empty query will result in the same object being returned. No operation will be performed.

Parameters:
elementClass - A class of the components in the queried composition.
targetClass - A class of the queried object.
resultClass - A class of the result, it must be a class that can be instantiated. If it is not, a QueryException will be thrown during query execution.

CollectionQuery

public CollectionQuery(Class<?> elementClass)
Constructs a new CollectionQuery instance. This constructor requires only the element class being provided. Collection is used as the target class and ArrayList as the result class.

Parameters:
elementClass - A class of the components in the queried composition.
Method Detail

convertToResult

protected Collection<T> convertToResult(List<?> newSelected)
Description copied from class: MultiElementQuery
Converts a provided list of selected elements (raw results of the query) to the object of the type required (and specified) by the user.

This implementation requires a result class (MultiElementQuery.resultClass) to implement a Collection interface.

Overrides:
convertToResult in class MultiElementQuery<E,Collection<E>,Collection<T>>
Parameters:
newSelected - Raw results to convert.
Returns:
Results packed into the proper type.

from

public CollectionQuery<E,T> from(IInitialSelector selector)
Adds a selector to the query.

Overrides:
from in class MultiElementQuery<E,Collection<E>,Collection<T>>
Parameters:
selector - A selector to add.
Returns:
This query.

select

public <S> CollectionQuery<E,T> select(IValueSelector<E,S> valueSelector)
Adds a selector to the query.

Overrides:
select in class MultiElementQuery<E,Collection<E>,Collection<T>>
Type Parameters:
S - A type of the selected value.
Parameters:
valueSelector - A selector to add.
Returns:
This query.

select

public CollectionQuery<E,T> select(String... fields)
Adds a selector to the query.

Overrides:
select in class MultiElementQuery<E,Collection<E>,Collection<T>>
Parameters:
fields - A fields to select. Fields needs to be accessible by getters in the JavaBean naming convention.
Returns:
This query.

matching

public CollectionQuery<E,T> matching(IValueFilter<E> filter)
Adds a value filter to the query.

Overrides:
matching in class MultiElementQuery<E,Collection<E>,Collection<T>>
Parameters:
filter - A value filter to add.
Returns:
This query.

matching

public <S> CollectionQuery<E,T> matching(String fieldName,
                                         IValueFilter<S> filter)
Adds a value filter that operates on a specific field of the element class to the query.

Overrides:
matching in class MultiElementQuery<E,Collection<E>,Collection<T>>
Type Parameters:
S - A type of the field.
Parameters:
fieldName - A field name that will be used in matching.
filter - A value filter to add.
Returns:
This query.

process

public CollectionQuery<E,T> process(IQueryFunction<Collection<T>> queryFunction)
Adds a function that will process results.

Overrides:
process in class MultiElementQuery<E,Collection<E>,Collection<T>>
Parameters:
queryFunction - A function to execute on results.
Returns:
This query.


Copyright © 2006-2011 AGH University of Science and Technology. All Rights Reserved.