Package org.apache.sling.query

## Class AbstractQuery<T,​Q extends AbstractQuery<T,​Q>>

- java.lang.Object
- - org.apache.sling.query.AbstractQuery<T,​Q>

All Implemented Interfaces:
  `Iterable<T>`

Direct Known Subclasses:
  `SlingQuery`

    @ProviderType
    public abstract class AbstractQuery<T,​Q extends AbstractQuery<T,​Q>>
    extends Object
    implements Iterable<T>

### Field Summary

Fields
`protected List<Function<?,​?>>` `functions`

### Constructor Summary

Constructors
`protected` `AbstractQuery​(AbstractQuery<T,​Q> original, SearchStrategy searchStrategy)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`Q` `add​(Iterable<T> iterable)` Include resources to the collection.
`Q` `add​(T... resources)` Include resources to the collection.
`List<T>` `asList()` Transform SlingQuery collection into a lazy list.
`Q` `children()` Get list of the children for each Resource in the collection.
`Q` `children​(Iterable<T> filter)` Get list of the children for each Resource in the collection.
`Q` `children​(String filter)` Get list of the children for each Resource in the collection.
`Q` `children​(Predicate<T> filter)` Get list of the children for each Resource in the collection.
`protected abstract Q` `clone​(AbstractQuery<T,​Q> original, SearchStrategy strategy)`
`Q` `closest​(Iterable<T> iterable)` For each Resource in the collection, return the first element matching the selector testing the Resource itself and traversing up its ancestors.
`Q` `closest​(String selector)` For each Resource in the collection, return the first element matching the selector testing the Resource itself and traversing up its ancestors.
`Q` `closest​(Predicate<T> predicate)` For each Resource in the collection, return the first element matching the selector testing the Resource itself and traversing up its ancestors.
`Q` `eq​(int index)` Reduce Resource collection to the one Resource at the given 0-based index.
`Q` `filter​(Iterable<T> iterable)` Filter Resource collection using given iterable.
`Q` `filter​(String selector)` Filter Resource collection using given selector.
`Q` `filter​(Predicate<T> predicate)` Filter Resource collection using given predicate object.
`Q` `find()` For each Resource in collection use depth-first search to return all its descendants.
`Q` `find​(Iterable<T> iterable)` For each Resource in collection use breadth-first search to return all its descendants.
`Q` `find​(String selector)` For each Resource in collection use breadth-first search to return all its descendants.
`Q` `find​(Predicate<T> predicate)` For each Resource in collection use breadth-first search to return all its descendants.
`Q` `first()` Filter Resource collection to the first element.
`Q` `has​(Iterable<T> iterable)` Pick such Resources from the collection that have descendant matching the selector.
`Q` `has​(String selector)` Pick such Resources from the collection that have descendant matching the selector.
`Q` `has​(Predicate<T> predicate)` Pick such Resources from the collection that have descendant matching the selector.
`Iterator<T>` `iterator()`
`Q` `last()` Filter Resource collection to the last element.
`Q` `next()` Return the next sibling for each Resource in the collection.
`Q` `next​(Iterable<T> iterable)` Return the next sibling for each Resource in the collection and filter it by a selector.
`Q` `next​(String selector)` Return the next sibling for each Resource in the collection and filter it by a selector.
`Q` `next​(Predicate<T> predicate)` Return the next sibling for each Resource in the collection and filter it by a selector.
`Q` `nextAll()` Return all following siblings for each Resource in the collection.
`Q` `nextAll​(Iterable<T> iterable)` Return all following siblings for each Resource in the collection, filtering them by a selector.
`Q` `nextAll​(String selector)` Return all following siblings for each Resource in the collection, filtering them by a selector.
`Q` `nextAll​(Predicate<T> predicate)` Return all following siblings for each Resource in the collection, filtering them by a selector.
`Q` `nextUntil​(Iterable<T> iterable)` Return all following siblings for each Resource in the collection up to, but not including, Resource matched by a selector.
`Q` `nextUntil​(String until)` Return all following siblings for each Resource in the collection up to, but not including, Resource matched by a selector.
`Q` `nextUntil​(Predicate<T> predicate)` Return all following siblings for each Resource in the collection up to, but not including, Resource matched by a selector.
`Q` `not​(Iterable<T> iterable)` Remove elements from the collection.
`Q` `not​(String selector)` Remove elements from the collection.
`Q` `not​(Predicate<T> predicate)` Remove elements from the collection.
`Q` `parent()` Replace each element in the collection with its parent.
`Q` `parents()` For each element in the collection find its all ancestor.
`Q` `parents​(Iterable<T> iterable)` For each element in the collection find its all ancestor, filtered by a selector.
`Q` `parents​(String selector)` For each element in the collection find its all ancestor, filtered by a selector.
`Q` `parents​(Predicate<T> predicate)` For each element in the collection find its all ancestor, filtered by a selector.
`Q` `parentsUntil​(Iterable<T> iterable)` For each element in the collection find all of its ancestors until the predicate is met.
`Q` `parentsUntil​(String until)` For each element in the collection find all of its ancestors until the predicate is met.
`Q` `parentsUntil​(Predicate<T> predicate)` For each element in the collection find all of its ancestors until the predicate is met.
`Q` `prev()` Return the previous sibling for each Resource in the collection.
`Q` `prev​(Iterable<T> iterable)` Return the previous sibling for each Resource in the collection and filter it by a selector.
`Q` `prev​(String selector)` Return the previous sibling for each Resource in the collection and filter it by a selector.
`Q` `prev​(Predicate<T> predicate)` Return the previous sibling for each Resource in the collection and filter it by a selector.
`Q` `prevAll()` Return all previous siblings for each Resource in the collection.
`Q` `prevAll​(Iterable<T> iterable)` Return all previous siblings for each Resource in the collection, filtering them by a selector.
`Q` `prevAll​(String selector)` Return all previous siblings for each Resource in the collection, filtering them by a selector.
`Q` `prevAll​(Predicate<T> predicate)` Return all previous siblings for each Resource in the collection, filtering them by a selector.
`Q` `prevUntil​(Iterable<T> iterable)` Return all previous siblings for each Resource in the collection up to, but not including, Resource matched by a selector.
`Q` `prevUntil​(String until)` Return all previous siblings for each Resource in the collection up to, but not including, Resource matched by a selector.
`Q` `prevUntil​(Predicate<T> predicate)` Return all previous siblings for each Resource in the collection up to, but not including, Resource matched by a selector.
`Q` `searchStrategy​(SearchStrategy strategy)` Set new search strategy, which will be used in `find()` and `has(String)` functions.
`Q` `siblings()` Return siblings for the given Ts.
`Q` `siblings​(Iterable<T> iterable)` Return siblings for the given Resources filtered by a selector.
`Q` `siblings​(String selector)` Return siblings for the given Resources filtered by a selector.
`Q` `siblings​(Predicate<T> predicate)` Return siblings for the given Resources filtered by a selector.
`Q` `slice​(int from)` Filter out first `from` Resources from the collection.
`Q` `slice​(int from, int to)` Reduce the collection to a subcollection specified by a given range.
`Stream<T>` `stream()`
`String` `toString()`
`Q` `unique()` Filter out repeated resources.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Field Detail

#### functions

    protected final List<Function<?,​?>> functions

### Constructor Detail

#### AbstractQuery

    protected AbstractQuery​(AbstractQuery<T,​Q> original,
                            SearchStrategy searchStrategy)

### Method Detail

#### iterator

    public Iterator<T> iterator()

Specified by:
  `iterator` in interface `Iterable<T>`

#### stream

    public Stream<T> stream()

#### add

    public Q add​(T... resources)

Include resources to the collection.

Parameters:
  `resources` - Resources to include
Returns:
  new SlingQuery object transformed by this operation

#### add

    public Q add​(Iterable<T> iterable)

Include resources to the collection.

Parameters:
  `iterable` - Resources to include
Returns:
  new SlingQuery object transformed by this operation

#### asList

    public List<T> asList()

Transform SlingQuery collection into a lazy list.

Returns:
  List containing all elements from the collection.

#### children

    public Q children()

Get list of the children for each Resource in the collection.

Returns:
  new SlingQuery object transformed by this operation

#### children

    public Q children​(String filter)

Get list of the children for each Resource in the collection.

Parameters:
  `filter` - Children filter
Returns:
  new SlingQuery object transformed by this operation

#### children

    public Q children​(Predicate<T> filter)

Get list of the children for each Resource in the collection.

Parameters:
  `filter` - Children filter
Returns:
  new SlingQuery object transformed by this operation

#### children

    public Q children​(Iterable<T> filter)

Get list of the children for each Resource in the collection.

Parameters:
  `filter` - Children filter
Returns:
  new SlingQuery object transformed by this operation

#### closest

    public Q closest​(String selector)

For each Resource in the collection, return the first element matching the selector testing the Resource itself and traversing up its ancestors.

Parameters:
  `selector` - Ancestor filter
Returns:
  new SlingQuery object transformed by this operation

#### closest

    public Q closest​(Iterable<T> iterable)

For each Resource in the collection, return the first element matching the selector testing the Resource itself and traversing up its ancestors.

Parameters:
  `iterable` - Ancestor filter
Returns:
  new SlingQuery object transformed by this operation

#### closest

    public Q closest​(Predicate<T> predicate)

For each Resource in the collection, return the first element matching the selector testing the Resource itself and traversing up its ancestors.

Parameters:
  `predicate` - Ancestor filter
Returns:
  new SlingQuery object transformed by this operation

#### eq

    public Q eq​(int index)

Reduce Resource collection to the one Resource at the given 0-based index.

Parameters:
  `index` - 0-based index
Returns:
  new SlingQuery object transformed by this operation

#### filter

    public Q filter​(String selector)

Filter Resource collection using given selector.

Parameters:
  `selector` - Selector
Returns:
  new SlingQuery object transformed by this operation

#### filter

    public Q filter​(Predicate<T> predicate)

Filter Resource collection using given predicate object.

Parameters:
  `predicate` - Collection filter
Returns:
  new SlingQuery object transformed by this operation

#### filter

    public Q filter​(Iterable<T> iterable)

Filter Resource collection using given iterable.

Parameters:
  `iterable` - Collection filter
Returns:
  new SlingQuery object transformed by this operation

#### find

    public Q find()

For each Resource in collection use depth-first search to return all its descendants. Please notice that invoking this method on a Resource being a root of a large subtree may and will cause performance problems.

Returns:
  new SlingQuery object transformed by this operation

#### find

    public Q find​(String selector)

For each Resource in collection use breadth-first search to return all its descendants. Please notice that invoking this method on a Resource being a root of a large subtree may and will cause performance problems.

Parameters:
  `selector` - descendants filter
Returns:
  new SlingQuery object transformed by this operation

#### find

    public Q find​(Predicate<T> predicate)

For each Resource in collection use breadth-first search to return all its descendants. Please notice that invoking this method on a Resource being a root of a large subtree may and will cause performance problems.

Parameters:
  `predicate` - descendants filter
Returns:
  new SlingQuery object transformed by this operation

#### find

    public Q find​(Iterable<T> iterable)

For each Resource in collection use breadth-first search to return all its descendants. Please notice that invoking this method on a Resource being a root of a large subtree may and will cause performance problems.

Parameters:
  `iterable` - descendants filter
Returns:
  new SlingQuery object transformed by this operation

#### first

    public Q first()

Filter Resource collection to the first element. Equivalent to `eq(0)` or `slice(0, 0)`.

Returns:
  new SlingQuery object transformed by this operation

#### has

    public Q has​(String selector)

Pick such Resources from the collection that have descendant matching the selector.

Parameters:
  `selector` - Descendant selector
Returns:
  new SlingQuery object transformed by this operation

#### has

    public Q has​(Predicate<T> predicate)

Pick such Resources from the collection that have descendant matching the selector.

Parameters:
  `predicate` - Descendant selector
Returns:
  new SlingQuery object transformed by this operation

#### has

    public Q has​(Iterable<T> iterable)

Pick such Resources from the collection that have descendant matching the selector.

Parameters:
  `iterable` - Descendant selector
Returns:
  new SlingQuery object transformed by this operation

#### last

    public Q last()

Filter Resource collection to the last element.

Returns:
  new SlingQuery object transformed by this operation

#### next

    public Q next()

Return the next sibling for each Resource in the collection.

Returns:
  new SlingQuery object transformed by this operation

#### next

    public Q next​(String selector)

Return the next sibling for each Resource in the collection and filter it by a selector. If the next sibling doesn't match it, empty collection will be returned.

Parameters:
  `selector` - Next sibling filter
Returns:
  new SlingQuery object transformed by this operation

#### next

    public Q next​(Predicate<T> predicate)

Return the next sibling for each Resource in the collection and filter it by a selector. If the next sibling doesn't match it, empty collection will be returned.

Parameters:
  `predicate` - Next sibling filter
Returns:
  new SlingQuery object transformed by this operation

#### next

    public Q next​(Iterable<T> iterable)

Return the next sibling for each Resource in the collection and filter it by a selector. If the next sibling doesn't match it, empty collection will be returned.

Parameters:
  `iterable` - Next sibling filter
Returns:
  new SlingQuery object transformed by this operation

#### nextAll

    public Q nextAll()

Return all following siblings for each Resource in the collection.

Returns:
  new SlingQuery object transformed by this operation

#### nextAll

    public Q nextAll​(String selector)

Return all following siblings for each Resource in the collection, filtering them by a selector.

Parameters:
  `selector` - Following siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### nextAll

    public Q nextAll​(Predicate<T> predicate)

Return all following siblings for each Resource in the collection, filtering them by a selector.

Parameters:
  `predicate` - Following siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### nextAll

    public Q nextAll​(Iterable<T> iterable)

Return all following siblings for each Resource in the collection, filtering them by a selector.

Parameters:
  `iterable` - Following siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### nextUntil

    public Q nextUntil​(String until)

Return all following siblings for each Resource in the collection up to, but not including, Resource matched by a selector.

Parameters:
  `until` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### nextUntil

    public Q nextUntil​(Predicate<T> predicate)

Return all following siblings for each Resource in the collection up to, but not including, Resource matched by a selector.

Parameters:
  `predicate` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### nextUntil

    public Q nextUntil​(Iterable<T> iterable)

Return all following siblings for each Resource in the collection up to, but not including, Resource matched by a selector.

Parameters:
  `iterable` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### not

    public Q not​(String selector)

Remove elements from the collection.

Parameters:
  `selector` - Selector used to remove Resources
Returns:
  new SlingQuery object transformed by this operation

#### not

    public Q not​(Predicate<T> predicate)

Remove elements from the collection.

Parameters:
  `predicate` - Selector used to remove Resources
Returns:
  new SlingQuery object transformed by this operation

#### not

    public Q not​(Iterable<T> iterable)

Remove elements from the collection.

Parameters:
  `iterable` - Selector used to remove Resources
Returns:
  new SlingQuery object transformed by this operation

#### parent

    public Q parent()

Replace each element in the collection with its parent.

Returns:
  new SlingQuery object transformed by this operation

#### parents

    public Q parents()

For each element in the collection find its all ancestor.

Returns:
  new SlingQuery object transformed by this operation

#### parents

    public Q parents​(String selector)

For each element in the collection find its all ancestor, filtered by a selector.

Parameters:
  `selector` - Parents filter
Returns:
  new SlingQuery object transformed by this operation

#### parents

    public Q parents​(Predicate<T> predicate)

For each element in the collection find its all ancestor, filtered by a selector.

Parameters:
  `predicate` - Parents filter
Returns:
  new SlingQuery object transformed by this operation

#### parents

    public Q parents​(Iterable<T> iterable)

For each element in the collection find its all ancestor, filtered by a selector.

Parameters:
  `iterable` - Parents filter
Returns:
  new SlingQuery object transformed by this operation

#### parentsUntil

    public Q parentsUntil​(String until)

For each element in the collection find all of its ancestors until the predicate is met.

Parameters:
  `until` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### parentsUntil

    public Q parentsUntil​(Predicate<T> predicate)

For each element in the collection find all of its ancestors until the predicate is met.

Parameters:
  `predicate` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### parentsUntil

    public Q parentsUntil​(Iterable<T> iterable)

For each element in the collection find all of its ancestors until the predicate is met.

Parameters:
  `iterable` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### prev

    public Q prev()

Return the previous sibling for each Resource in the collection.

Returns:
  new SlingQuery object transformed by this operation

#### prev

    public Q prev​(String selector)

Return the previous sibling for each Resource in the collection and filter it by a selector. If the previous sibling doesn't match it, empty collection will be returned.

Parameters:
  `selector` - Previous sibling filter
Returns:
  new SlingQuery object transformed by this operation

#### prev

    public Q prev​(Predicate<T> predicate)

Return the previous sibling for each Resource in the collection and filter it by a selector. If the previous sibling doesn't match it, empty collection will be returned.

Parameters:
  `predicate` - Previous sibling filter
Returns:
  new SlingQuery object transformed by this operation

#### prev

    public Q prev​(Iterable<T> iterable)

Return the previous sibling for each Resource in the collection and filter it by a selector. If the previous sibling doesn't match it, empty collection will be returned.

Parameters:
  `iterable` - Previous sibling filter
Returns:
  new SlingQuery object transformed by this operation

#### prevAll

    public Q prevAll()

Return all previous siblings for each Resource in the collection.

Returns:
  new SlingQuery object transformed by this operation

#### prevAll

    public Q prevAll​(String selector)

Return all previous siblings for each Resource in the collection, filtering them by a selector.

Parameters:
  `selector` - Previous siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### prevAll

    public Q prevAll​(Predicate<T> predicate)

Return all previous siblings for each Resource in the collection, filtering them by a selector.

Parameters:
  `predicate` - Previous siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### prevAll

    public Q prevAll​(Iterable<T> iterable)

Return all previous siblings for each Resource in the collection, filtering them by a selector.

Parameters:
  `iterable` - Previous siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### prevUntil

    public Q prevUntil​(String until)

Return all previous siblings for each Resource in the collection up to, but not including, Resource matched by a selector.

Parameters:
  `until` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### prevUntil

    public Q prevUntil​(Predicate<T> predicate)

Return all previous siblings for each Resource in the collection up to, but not including, Resource matched by a selector.

Parameters:
  `predicate` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### prevUntil

    public Q prevUntil​(Iterable<T> iterable)

Return all previous siblings for each Resource in the collection up to, but not including, Resource matched by a selector.

Parameters:
  `iterable` - Selector marking when the operation should stop
Returns:
  new SlingQuery object transformed by this operation

#### searchStrategy

    public Q searchStrategy​(SearchStrategy strategy)

Set new search strategy, which will be used in `find()` and `has(String)` functions.

Parameters:
  `strategy` - Search strategy type
Returns:
  new SlingQuery object transformed by this operation

#### siblings

    public Q siblings()

Return siblings for the given Ts.

Returns:
  new SlingQuery object transformed by this operation

#### siblings

    public Q siblings​(String selector)

Return siblings for the given Resources filtered by a selector.

Parameters:
  `selector` - Siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### siblings

    public Q siblings​(Predicate<T> predicate)

Return siblings for the given Resources filtered by a selector.

Parameters:
  `predicate` - Siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### siblings

    public Q siblings​(Iterable<T> iterable)

Return siblings for the given Resources filtered by a selector.

Parameters:
  `iterable` - Siblings filter
Returns:
  new SlingQuery object transformed by this operation

#### slice

    public Q slice​(int from)

Filter out first `from` Resources from the collection.

Parameters:
  `from` - How many Resources to cut out
Returns:
  new SlingQuery object transformed by this operation

#### slice

    public Q slice​(int from,
                   int to)

Reduce the collection to a subcollection specified by a given range. Both from and to are inclusive, 0-based indices.

Parameters:
  `from` - Low endpoint (inclusive) of the subcollection
  `to` - High endpoint (inclusive) of the subcollection
Returns:
  new SlingQuery object transformed by this operation

#### unique

    public Q unique()

Filter out repeated resources. The implementation of this method uses a `HashSet` to store the processed elements, which may result in an increased memory usage for the big collections.

Returns:
  new SlingQuery object transformed by this operation

#### clone

    protected abstract Q clone​(AbstractQuery<T,​Q> original,
                               SearchStrategy strategy)

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`