Class QueryUtil


  • public class QueryUtil
    extends Object
    Helper class for query related tasks.
    Since:
    2.0
    • Constructor Detail

      • QueryUtil

        public QueryUtil()
    • 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 queryable
        query2 - 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 the and flag. If at least one query is a full query, all queries will instead be evaluated using intersection when and is true or a union.
        Parameters:
        queries - The queries to perform
        and - true if this query represents an intersection or a logical 'and', and false 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 the and flag. If at least one query is a full query, all queries will instead be evaluated using intersection when and is true or a union.
        Parameters:
        query1 - the first query
        query2 - the second query
        and - true if this query represents an intersection or a logical 'and', and false 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 all InstallableUnit elements
      • createIUCategoryMemberQuery

        public static IQuery<IInstallableUnit> createIUCategoryMemberQuery​(IInstallableUnit category)
        Creates a new query that will return the members of the given category. If the specified IInstallableUnit 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 every IInstallableUnit that is a category.
        Returns:
        The query that matches categories
        Since:
        2.0
      • createIUPropertyQuery

        public static IQuery<IInstallableUnit> createIUPropertyQuery​(String propertyName,
                                                                     String propertyValue)
        Creates a query that searches for IInstallableUnit instances that have a property whose value matches the provided value. If no property name is specified, then all IInstallableUnit instances are accepted.
        Parameters:
        propertyName - The key of the property to match or null to match all
        propertyValue - The value of the property. Can be ANY to match all values except null
        Returns:
        The query matching properties
      • createIUQuery

        public static IQuery<IInstallableUnit> createIUQuery​(IVersionedId versionedId)
        Creates a query that will match any IInstallableUnit 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 any IInstallableUnit with the given id, regardless of version.
        Parameters:
        id - The installable unit id to match, or null 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 any IInstallableUnit with the given id and version.
        Parameters:
        id - The installable unit id to match, or null to match any id
        version - The precise version that a matching unit must have or null 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 any IInstallableUnit with the given id, and whose version falls in the provided range.
        Parameters:
        id - The installable unit id to match, or null to match any id
        range - The version range to match or null 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 an IVersionedId. All other elements are discarded.
        Returns:
        A query matching the latest version for each id.
      • createLatestQuery

        public static <T extends IVersionedIdIQuery<T> createLatestQuery​(IQuery<T> query)
        Creates a query that returns the latest version for each unique id of an IVersionedId from the collection produced by query. 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 limited
        limit - A positive integer denoting the limit
        Returns:
        A limited query
        Since:
        2.0
      • createMatchQuery

        public static IQuery<IInstallableUnit> createMatchQuery​(IExpression matchExpression,
                                                                Object... parameters)
        Creates an IInstallableUnit query that will iterate over all candidates and discriminate by applying the boolean matchExpression on each candidate.
        Parameters:
        matchExpression - The boolean expression used for filtering one candidate
        parameters - Values for parameter substitution
        Returns:
        The created query
      • createMatchQuery

        public static IQuery<IInstallableUnit> createMatchQuery​(String matchExpression,
                                                                Object... parameters)
        Parses the matchExpression and creates an IInstallableUnit query that will iterate over all candidates and discriminate by applying the boolean matchExpression on each candidate.
        Parameters:
        matchExpression - The boolean expression used for filtering one candidate
        parameters - 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 of matchinClass> or for which the boolean matchExpression returns false.
        Parameters:
        matchingClass - The class that matching candidates must be an instance of
        matchExpression - The boolean expression used for filtering one candidate
        parameters - Values for parameter substitution
        Returns:
        The created query
      • createMatchQuery

        public static <T> IQuery<T> createMatchQuery​(Class<? extends T> matchingClass,
                                                     String matchExpression,
                                                     Object... parameters)
        Parses the matchExpression and creates an query that will iterate over all candidates and discriminate all candidates that are not instances of matchinClass> or for which the boolean matchExpression returns false.
        Parameters:
        matchingClass - The class that matching candidates must be an instance of
        matchExpression - The boolean expression used for filtering one candidate
        parameters - 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 query
        query2 - the second query
        Returns:
        A query pipe
      • createQuery

        public static IQuery<IInstallableUnit> createQuery​(IExpression expression,
                                                           Object... parameters)
        Creates an IInstallableUnit query based on an expression that uses all candidates as input.
        Parameters:
        expression - The query expression
        parameters - Values for parameter substitution
        Returns:
        The created query
      • createQuery

        public static IQuery<IInstallableUnit> createQuery​(String expression,
                                                           Object... parameters)
        Parses the expression and creates an IInstallableUnit query. The expression is expected to use all candidates as input.
        Parameters:
        expression - The query expression
        parameters - 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 the matchinClass. The expression is expected to use all candidates as input.
        Parameters:
        matchingClass - The class used as discriminator for the result
        expression - The query expression
        parameters - Values for parameter substitution
        Returns:
        The created query
      • createQuery

        public static <T> IQuery<T> createQuery​(Class<? extends T> matchingClass,
                                                String expression,
                                                Object... parameters)
        Parses the expression and creates a query that will limit the result to instances of the matchinClass. The expression is expected to use all candidates as input.
        Parameters:
        matchingClass - The class used as discriminator for the result
        expression - The query expression
        parameters - Values for parameter substitution
        Returns:
        The created query
      • isCategory

        public static boolean isCategory​(IInstallableUnit iu)
        Test if the IInstallableUnit 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 the IInstallableUnit 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 the IInstallableUnit 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 the IInstallableUnit 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 the IInstallableUnit is a patch.
        Parameters:
        iu - the element being tested.
        Returns:
        true if the parameter is a patch.