Package org.eclipse.equinox.p2.query

# Class Collector<T>

java.lang.Object
org.eclipse.equinox.p2.query.Collector<T>

Type Parameters:
  `T` - The type of object accepted by this collector

All Implemented Interfaces:
  `Iterable<T>`, `IQueryable<T>`, `IQueryResult<T>`

public class Collector<T> extends Object implements IQueryResult<T>
A collector is a generic visitor that collects objects passed to it, and can then express the result of the visit in various forms. The collector can also short-circuit a traversal by returning `false` from its `accept(Object)` method.

This default collector just accepts all objects passed to it. Clients may subclass to perform different processing on the objects passed to it.

Since:
  2.0

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Collector<?>`
`EMPTY_COLLECTOR`

## Constructor Summary

Constructors
Constructor
Description
`Collector()`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`accept(T object)`
Accepts an object.
`void`
`addAll(IQueryResult<T> queryResult)`
Adds the elements from one collector to this collector
`static final <T> Collector<T>`
`emptyCollector()`
`protected Collection<T>`
`getCollection()`
Returns the collection that is being used to collect results.
`boolean`
`isEmpty()`
Returns whether this collector is empty.
`Iterator<T>`
`iterator()`
Returns an iterator on the collected objects.
`IQueryResult<T>`
`query(IQuery<T> query, IProgressMonitor monitor)`
Performs a query on this results of this collector.
`int`
`size()`
Returns the number of collected objects.
`Stream<T>`
`stream()`
Returns a sequential `Stream` of the collected objects.
`T[]`
`toArray(Class<T> clazz)`
Returns the collected objects as an array
`Set<T>`
`toSet()`
Returns a copy of the collected objects.
`Set<T>`
`toUnmodifiableSet()`
Returns the collected objects as an immutable collection.

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

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

### Methods inherited from interface org.eclipse.equinox.p2.query.IQueryable

`contains`

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

`forEach, spliterator`

## Field Details

### EMPTY_COLLECTOR

public static final Collector<?> EMPTY_COLLECTOR

## Constructor Details

### Collector

public Collector()

## Method Details

### emptyCollector

public static final <T> Collector<T> emptyCollector()

### accept

public boolean accept(T object)
Accepts an object.

This default implementation adds the objects to a list. Clients may override this method to perform additional filtering, add different objects to the list, short-circuit the traversal, or process the objects directly without collecting them.

Parameters:
  `object` - the object to collect or visit
Returns:
  `true` if the traversal should continue, or `false` to indicate the traversal should stop.

### addAll

public void addAll(IQueryResult<T> queryResult)
Adds the elements from one collector to this collector

Parameters:
  `queryResult` - The collector from which the elements should be retrieved

### getCollection

protected Collection<T> getCollection()
Returns the collection that is being used to collect results. Unlike toSet(), this returns the actual modifiable collection that is being used to store results. The return value is only intended to be used within subclasses and should not be exposed outside of a collection class.

Returns:
  the collection being used to collect results.

### isEmpty

public boolean isEmpty()
Returns whether this collector is empty.

Specified by:
  `isEmpty` in interface `IQueryResult<T>`
Returns:
  `true` if this collector has accepted any results, and `false` otherwise.

### iterator

public Iterator<T> iterator()
Returns an iterator on the collected objects.

Specified by:
  `iterator` in interface `IQueryResult<T>`
Specified by:
  `iterator` in interface `Iterable<T>`
Returns:
  an iterator of the collected objects.

### size

public int size()
Returns the number of collected objects.

### toArray

public T[] toArray(Class<T> clazz)
Returns the collected objects as an array

Specified by:
  `toArray` in interface `IQueryResult<T>`
Parameters:
  `clazz` - The type of array to return
Returns:
  The array of results
Throws:
  `ArrayStoreException` - the runtime type of the specified array is not a super-type of the runtime type of every collected object

### toSet

public Set<T> toSet()
Returns a copy of the collected objects.

Specified by:
  `toSet` in interface `IQueryResult<T>`
Returns:
  An modifiable collection of the collected objects

### query

public IQueryResult<T> query(IQuery<T> query, IProgressMonitor monitor)
Performs a query on this results of this collector.

Specified by:
  `query` in interface `IQueryable<T>`
Parameters:
  `query` - The query to perform
  `monitor` - a progress monitor, or `null` if progress reporting is not desired
Returns:
  The collector argument

### toUnmodifiableSet

public Set<T> toUnmodifiableSet()
Returns the collected objects as an immutable collection.

Specified by:
  `toUnmodifiableSet` in interface `IQueryResult<T>`
Returns:
  An unmodifiable collection of the collected objects

### stream

public Stream<T> stream()
Description copied from interface: `IQueryResult`
Returns a sequential `Stream` of the collected objects.

Specified by:
  `stream` in interface `IQueryResult<T>`