| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2009, 2017 EclipseSource and others. |
| 3 |
* |
| 4 |
* This |
| 5 |
* program and the accompanying materials are made available under the terms of |
| 6 |
* the Eclipse Public License 2.0 which accompanies this distribution, and is |
| 7 |
* available at |
| 8 |
* https://www.eclipse.org/legal/epl-2.0/ |
| 9 |
* |
| 10 |
* SPDX-License-Identifier: EPL-2.0 |
| 11 |
* |
| 12 |
* Contributors: |
| 13 |
* EclipseSource - initial API and implementation |
| 14 |
******************************************************************************/ |
| 15 |
package org.eclipse.equinox.p2.query; |
| 16 |
|
| 17 |
import java.util.Collection; |
| 18 |
import java.util.Iterator; |
| 19 |
import java.util.Set; |
| 20 |
import java.util.stream.Stream; |
| 21 |
import java.util.stream.StreamSupport; |
| 22 |
|
| 23 |
/** |
| 24 |
* An IQueryResult represents the results of a query. |
| 25 |
* |
| 26 |
* @since 2.0 |
| 27 |
*/ |
| 28 |
public interface IQueryResult<T> extends IQueryable<T>, Iterable<T> { |
| 29 |
/** |
| 30 |
* Returns whether this QueryResult is empty. |
| 31 |
* |
| 32 |
* @return <code>true</code> if this QueryResult has accepted any results, and |
| 33 |
* <code>false</code> otherwise. |
| 34 |
*/ |
| 35 |
boolean isEmpty(); |
| 36 |
|
| 37 |
/** |
| 38 |
* Returns an iterator on the collected objects. |
| 39 |
* |
| 40 |
* @return an iterator of the collected objects. |
| 41 |
*/ |
| 42 |
@Override |
| 43 |
Iterator<T> iterator(); |
| 44 |
|
| 45 |
/** |
| 46 |
* Returns the collected objects as an array |
| 47 |
* |
| 48 |
* @param clazz The type of array to return |
| 49 |
* @return The array of results |
| 50 |
* @throws ArrayStoreException the runtime type of the specified array is |
| 51 |
* not a super-type of the runtime type of every collected object |
| 52 |
*/ |
| 53 |
T[] toArray(Class<T> clazz); |
| 54 |
|
| 55 |
/** |
| 56 |
* Creates a new Set copy with the contents of this query result. The copy can |
| 57 |
* be altered without any side effects on its origin. |
| 58 |
* |
| 59 |
* @return A detached copy of the result. |
| 60 |
*/ |
| 61 |
Set<T> toSet(); |
| 62 |
|
| 63 |
/** |
| 64 |
* Returns a Set backed by this query result. The set is immutable. |
| 65 |
* |
| 66 |
* @return A Set backed by this query result. |
| 67 |
*/ |
| 68 |
Set<T> toUnmodifiableSet(); |
| 69 |
|
| 70 |
/** |
| 71 |
* Returns a sequential {@code Stream} of the collected objects. |
| 72 |
* |
| 73 |
* @implSpec The default implementation creates a sequential {@code Stream} from |
| 74 |
* this query-results {@code Spliterator}. Implementations backed by a |
| 75 |
* {@code Collection} should override this method and call |
| 76 |
* {@link Collection#stream()}. |
| 77 |
* @since 2.8 |
| 78 |
*/ |
| 79 |
default Stream<T> stream() { |
| 80 |
return StreamSupport.stream(spliterator(), false); |
| 81 |
} |
| 82 |
|
| 83 |
} |