Package org.eclipse.equinox.p2.query
Class QueryUtil
- java.lang.Object
-
- org.eclipse.equinox.p2.query.QueryUtil
-
public class QueryUtil extends Object
Helper class for query related tasks.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description static IQuery<IInstallableUnit>
ALL_UNITS
static String
ANY
static IQuery<IInstallableUnit>
NO_UNITS
static String
PROP_TYPE_CATEGORY
static String
PROP_TYPE_GROUP
static String
PROP_TYPE_PATCH
-
Constructor Summary
Constructors Constructor Description QueryUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> IQueryable<T>
compoundQueryable(Collection<? extends IQueryable<T>> queryables)
Creates a queryable that combines the given collection of input queryablesstatic <T> IQueryable<T>
compoundQueryable(IQueryable<T> query1, IQueryable<T> query2)
Creates a queryable that combines the two provided input queryablesstatic <T> IQuery<T>
createCompoundQuery(Collection<? extends IQuery<? extends T>> queries, boolean and)
Creates a compound query that combines the given queries.static <T> IQuery<T>
createCompoundQuery(IQuery<? extends T> query1, IQuery<T> query2, boolean and)
Creates a compound query that combines the two queries.static IQuery<IInstallableUnit>
createIUAnyQuery()
Returns a query that matches allInstallableUnit
elementsstatic IQuery<IInstallableUnit>
createIUCategoryMemberQuery(IInstallableUnit category)
Creates a new query that will return the members of the givencategory
.static IQuery<IInstallableUnit>
createIUCategoryQuery()
Creates a query matching everyIInstallableUnit
that is a category.static IQuery<IInstallableUnit>
createIUGroupQuery()
Creates a query matching everyIInstallableUnit
that is a group.static IQuery<IInstallableUnit>
createIUPatchQuery()
Creates anIInstallableUnit
that will match all patches.static IQuery<IInstallableUnit>
createIUProductQuery()
Creates anIInstallableUnit
that will match all products.static IQuery<IInstallableUnit>
createIUPropertyQuery(String propertyName, String propertyValue)
Creates a query that searches forIInstallableUnit
instances that have a property whose value matches the provided value.static IQuery<IInstallableUnit>
createIUQuery(String id)
Creates a query that will match anyIInstallableUnit
with the given id, regardless of version.static IQuery<IInstallableUnit>
createIUQuery(String id, Version version)
Creates a query that will match anyIInstallableUnit
with the given id and version.static IQuery<IInstallableUnit>
createIUQuery(String id, VersionRange range)
Creates a query that will match anyIInstallableUnit
with the given id, and whose version falls in the provided range.static IQuery<IInstallableUnit>
createIUQuery(IVersionedId versionedId)
Creates a query that will match anyIInstallableUnit
with the given id and version.static IQuery<IInstallableUnit>
createLatestIUQuery()
Creates a query that returns the latest version for each unique id of anIVersionedId
.static <T extends IVersionedId>
IQuery<T>createLatestQuery(IQuery<T> query)
Creates a query that returns the latest version for each unique id of anIVersionedId
from the collection produced byquery
.static <T> IQuery<T>
createLimitQuery(IQuery<T> query, int limit)
Creates a limit query that can be used to limit the number of query results returned.static <T> IQuery<T>
createMatchQuery(Class<? extends T> matchingClass, String matchExpression, Object... parameters)
Parses thematchExpression
and creates an query that will iterate over all candidates and discriminate all candidates that are not instances ofmatchinClass>
or for which the booleanmatchExpression
returns false.static <T> IQuery<T>
createMatchQuery(Class<? extends T> matchingClass, IExpression matchExpression, Object... parameters)
Creates an query that will iterate over all candidates and discriminate all candidates that are not instances ofmatchinClass>
or for which the booleanmatchExpression
returns false.static IQuery<IInstallableUnit>
createMatchQuery(String matchExpression, Object... parameters)
Parses thematchExpression
and creates anIInstallableUnit
query that will iterate over all candidates and discriminate by applying the booleanmatchExpression
on each candidate.static IQuery<IInstallableUnit>
createMatchQuery(IExpression matchExpression, Object... parameters)
Creates anIInstallableUnit
query that will iterate over all candidates and discriminate by applying the booleanmatchExpression
on each candidate.static <T> IQuery<T>
createPipeQuery(Collection<? extends IQuery<? extends T>> queries)
Creates a piped query based on the provided input queries.static <T> IQuery<T>
createPipeQuery(IQuery<? extends T> query1, IQuery<? extends T> query2)
Creates a piped query based on the provided input queries.static <T> IQuery<T>
createQuery(Class<? extends T> matchingClass, String expression, Object... parameters)
Parses theexpression
and creates a query that will limit the result to instances of thematchinClass
.static <T> IQuery<T>
createQuery(Class<? extends T> matchingClass, IExpression expression, Object... parameters)
Creates a query that will limit the result to instances of thematchinClass
.static IQuery<IInstallableUnit>
createQuery(String expression, Object... parameters)
Parses theexpression
and creates anIInstallableUnit
query.static IQuery<IInstallableUnit>
createQuery(IExpression expression, Object... parameters)
Creates anIInstallableUnit
query based on anexpression
that uses all candidates as input.static boolean
isCategory(IInstallableUnit iu)
Test if theIInstallableUnit
is a category.static boolean
isFragment(IInstallableUnit iu)
Test if theIInstallableUnit
is a fragment.static boolean
isGroup(IInstallableUnit iu)
Test if theIInstallableUnit
is a group.static boolean
isPatch(IInstallableUnit iu)
Test if theIInstallableUnit
is a patch.static boolean
isProduct(IInstallableUnit iu)
Test if theIInstallableUnit
is a product.
-
-
-
Field Detail
-
ALL_UNITS
public static final IQuery<IInstallableUnit> ALL_UNITS
-
ANY
public static final String ANY
- See Also:
- Constant Field Values
-
NO_UNITS
public static final IQuery<IInstallableUnit> NO_UNITS
-
PROP_TYPE_CATEGORY
public static final String PROP_TYPE_CATEGORY
- See Also:
- Constant Field Values
-
PROP_TYPE_GROUP
public static final String PROP_TYPE_GROUP
- See Also:
- Constant Field Values
-
PROP_TYPE_PATCH
public static final String PROP_TYPE_PATCH
- See Also:
- Constant Field Values
-
-
Method Detail
-
compoundQueryable
public static <T> IQueryable<T> compoundQueryable(Collection<? extends IQueryable<T>> queryables)
Creates a queryable that combines the given collection of input queryables- Parameters:
queryables
- The collection of queryables to be combined
-
compoundQueryable
public static <T> IQueryable<T> compoundQueryable(IQueryable<T> query1, IQueryable<T> query2)
Creates a queryable that combines the two provided input queryables- Parameters:
query1
- The first queryablequery2
- The second queryable
-
createCompoundQuery
public static <T> IQuery<T> createCompoundQuery(Collection<? extends IQuery<? extends T>> queries, boolean and)
Creates a compound query that combines the given queries. If all queries are candidate match queries, then the queries will be concatenated as a boolean 'and' or a boolean 'or' expression depending on theand
flag. If at least one query is a full query, all queries will instead be evaluated using intersection whenand
istrue
or a union.- Parameters:
queries
- The queries to performand
-true
if this query represents an intersection or a logical 'and', andfalse
if this query represents a union or a logical 'or'.- Returns:
- A compound query
-
createCompoundQuery
public static <T> IQuery<T> createCompoundQuery(IQuery<? extends T> query1, IQuery<T> query2, boolean and)
Creates a compound query that combines the two queries. If both queries are candidate match queries, then the queries will be concatenated as a boolean 'and' or a boolean 'or' expression depending on theand
flag. If at least one query is a full query, all queries will instead be evaluated using intersection whenand
istrue
or a union.- Parameters:
query1
- the first queryquery2
- the second queryand
-true
if this query represents an intersection or a logical 'and', andfalse
if this query represents a union or a logical 'or'.- Returns:
- A compound query
-
createIUAnyQuery
public static IQuery<IInstallableUnit> createIUAnyQuery()
Returns a query that matches allInstallableUnit
elements
-
createIUCategoryMemberQuery
public static IQuery<IInstallableUnit> createIUCategoryMemberQuery(IInstallableUnit category)
Creates a new query that will return the members of the givencategory
. If the specifiedIInstallableUnit
is not a category, then no installable unit will satisfy the query.- Parameters:
category
- The category- Returns:
- A query that returns category members
-
createIUCategoryQuery
public static IQuery<IInstallableUnit> createIUCategoryQuery()
Creates a query matching everyIInstallableUnit
that is a category.- Returns:
- The query that matches categories
- Since:
- 2.0
-
createIUGroupQuery
public static IQuery<IInstallableUnit> createIUGroupQuery()
Creates a query matching everyIInstallableUnit
that is a group.- Returns:
- a query that matches all groups
-
createIUPatchQuery
public static IQuery<IInstallableUnit> createIUPatchQuery()
Creates anIInstallableUnit
that will match all patches.- Returns:
- The created query
-
createIUProductQuery
public static IQuery<IInstallableUnit> createIUProductQuery()
Creates anIInstallableUnit
that will match all products.- Returns:
- The created query
- Since:
- 2.2
-
createIUPropertyQuery
public static IQuery<IInstallableUnit> createIUPropertyQuery(String propertyName, String propertyValue)
Creates a query that searches forIInstallableUnit
instances that have a property whose value matches the provided value. If no property name is specified, then allIInstallableUnit
instances are accepted.- Parameters:
propertyName
- The key of the property to match ornull
to match allpropertyValue
- The value of the property. Can beANY
to match all values exceptnull
- Returns:
- The query matching properties
-
createIUQuery
public static IQuery<IInstallableUnit> createIUQuery(IVersionedId versionedId)
Creates a query that will match anyIInstallableUnit
with the given id and version.- Parameters:
versionedId
- The precise id/version combination that a matching unit must have- Returns:
- a query that matches IU's by id and version
-
createIUQuery
public static IQuery<IInstallableUnit> createIUQuery(String id)
Creates a query that will match anyIInstallableUnit
with the given id, regardless of version.- Parameters:
id
- The installable unit id to match, ornull
to match any id- Returns:
- a query that matches IU's by id
-
createIUQuery
public static IQuery<IInstallableUnit> createIUQuery(String id, Version version)
Creates a query that will match anyIInstallableUnit
with the given id and version.- Parameters:
id
- The installable unit id to match, ornull
to match any idversion
- The precise version that a matching unit must have ornull
to match any version- Returns:
- a query that matches IU's by id and version
-
createIUQuery
public static IQuery<IInstallableUnit> createIUQuery(String id, VersionRange range)
Creates a query that will match anyIInstallableUnit
with the given id, and whose version falls in the provided range.- Parameters:
id
- The installable unit id to match, ornull
to match any idrange
- The version range to match ornull
to match any range.- Returns:
- a query that matches IU's by id and range
-
createLatestIUQuery
public static IQuery<IInstallableUnit> createLatestIUQuery()
Creates a query that returns the latest version for each unique id of anIVersionedId
. All other elements are discarded.- Returns:
- A query matching the latest version for each id.
-
createLatestQuery
public static <T extends IVersionedId> IQuery<T> createLatestQuery(IQuery<T> query)
Creates a query that returns the latest version for each unique id of anIVersionedId
from the collection produced byquery
. All other elements are discarded.- Parameters:
query
- The query that precedes the latest query when evaluating.- Returns:
- A query matching the latest version for each id.
-
createLimitQuery
public static <T> IQuery<T> createLimitQuery(IQuery<T> query, int limit)
Creates a limit query that can be used to limit the number of query results returned. Once the limit is reached, the query is terminated.- Parameters:
query
- The query that should be limitedlimit
- A positive integer denoting the limit- Returns:
- A limited query
- Since:
- 2.0
-
createMatchQuery
public static IQuery<IInstallableUnit> createMatchQuery(IExpression matchExpression, Object... parameters)
Creates anIInstallableUnit
query that will iterate over all candidates and discriminate by applying the booleanmatchExpression
on each candidate.- Parameters:
matchExpression
- The boolean expression used for filtering one candidateparameters
- Values for parameter substitution- Returns:
- The created query
-
createMatchQuery
public static IQuery<IInstallableUnit> createMatchQuery(String matchExpression, Object... parameters)
Parses thematchExpression
and creates anIInstallableUnit
query that will iterate over all candidates and discriminate by applying the booleanmatchExpression
on each candidate.- Parameters:
matchExpression
- The boolean expression used for filtering one candidateparameters
- Values for parameter substitution- Returns:
- The created query
-
createMatchQuery
public static <T> IQuery<T> createMatchQuery(Class<? extends T> matchingClass, IExpression matchExpression, Object... parameters)
Creates an query that will iterate over all candidates and discriminate all candidates that are not instances ofmatchinClass>
or for which the booleanmatchExpression
returns false.- Parameters:
matchingClass
- The class that matching candidates must be an instance ofmatchExpression
- The boolean expression used for filtering one candidateparameters
- Values for parameter substitution- Returns:
- The created query
-
createMatchQuery
public static <T> IQuery<T> createMatchQuery(Class<? extends T> matchingClass, String matchExpression, Object... parameters)
Parses thematchExpression
and creates an query that will iterate over all candidates and discriminate all candidates that are not instances ofmatchinClass>
or for which the booleanmatchExpression
returns false.- Parameters:
matchingClass
- The class that matching candidates must be an instance ofmatchExpression
- The boolean expression used for filtering one candidateparameters
- Values for parameter substitution- Returns:
- The created query
-
createPipeQuery
public static <T> IQuery<T> createPipeQuery(Collection<? extends IQuery<? extends T>> queries)
Creates a piped query based on the provided input queries.
A pipe is a composite query in which each sub-query is executed in succession. The results from the ith sub-query are piped as input into the i+1th sub-query. The query will short-circuit if any query returns an empty result set.
- Parameters:
queries
- the ordered list of queries to perform- Returns:
- A query pipe
-
createPipeQuery
public static <T> IQuery<T> createPipeQuery(IQuery<? extends T> query1, IQuery<? extends T> query2)
Creates a piped query based on the provided input queries.
A pipe is a composite query in which each sub-query is executed in succession. The results from the ith sub-query are piped as input into the i+1th sub-query. The query will short-circuit if any query returns an empty result set.
- Parameters:
query1
- the first queryquery2
- the second query- Returns:
- A query pipe
-
createQuery
public static IQuery<IInstallableUnit> createQuery(IExpression expression, Object... parameters)
Creates anIInstallableUnit
query based on anexpression
that uses all candidates as input.- Parameters:
expression
- The query expressionparameters
- Values for parameter substitution- Returns:
- The created query
-
createQuery
public static IQuery<IInstallableUnit> createQuery(String expression, Object... parameters)
Parses theexpression
and creates anIInstallableUnit
query. Theexpression
is expected to use all candidates as input.- Parameters:
expression
- The query expressionparameters
- Values for parameter substitution- Returns:
- The created query
-
createQuery
public static <T> IQuery<T> createQuery(Class<? extends T> matchingClass, IExpression expression, Object... parameters)
Creates a query that will limit the result to instances of thematchinClass
. Theexpression
is expected to use all candidates as input.- Parameters:
matchingClass
- The class used as discriminator for the resultexpression
- The query expressionparameters
- Values for parameter substitution- Returns:
- The created query
-
createQuery
public static <T> IQuery<T> createQuery(Class<? extends T> matchingClass, String expression, Object... parameters)
Parses theexpression
and creates a query that will limit the result to instances of thematchinClass
. Theexpression
is expected to use all candidates as input.- Parameters:
matchingClass
- The class used as discriminator for the resultexpression
- The query expressionparameters
- Values for parameter substitution- Returns:
- The created query
-
isCategory
public static boolean isCategory(IInstallableUnit iu)
Test if theIInstallableUnit
is a category.- Parameters:
iu
- the element being tested.- Returns:
true
if the parameter is a category.
-
isFragment
public static boolean isFragment(IInstallableUnit iu)
Test if theIInstallableUnit
is a fragment.- Parameters:
iu
- the element being tested.- Returns:
true
if the parameter is a fragment.
-
isGroup
public static boolean isGroup(IInstallableUnit iu)
Test if theIInstallableUnit
is a group.- Parameters:
iu
- the element being tested.- Returns:
true
if the parameter is a group.
-
isProduct
public static boolean isProduct(IInstallableUnit iu)
Test if theIInstallableUnit
is a product.- Parameters:
iu
- the element being tested.- Returns:
true
if the parameter is a group.- Since:
- 2.2
-
isPatch
public static boolean isPatch(IInstallableUnit iu)
Test if theIInstallableUnit
is a patch.- Parameters:
iu
- the element being tested.- Returns:
true
if the parameter is a patch.
-
-