Skip to content

Commit

Permalink
Add new method IQueryResult.stream()
Browse files Browse the repository at this point in the history
This improves the interoperability of IQueryResult and the Java's modern
Stream-API.
  • Loading branch information
HannesWell committed Sep 2, 2023
1 parent 07c09ad commit 717690c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/equinox/p2/query/IQueryResult.java" type="org.eclipse.equinox.p2.query.IQueryResult">
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.equinox.p2.query.IQueryResult"/>
<message_argument value="stream()"/>
</message_arguments>
</filter>
</resource>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Stream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.metadata.expression.QueryResult;

Expand Down Expand Up @@ -68,4 +69,9 @@ public Set<T> toUnmodifiableSet() {
public String toString() {
return collection.toString();
}

@Override
public Stream<T> stream() {
return collection.stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Stream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.metadata.Messages;
Expand Down Expand Up @@ -178,4 +179,9 @@ public Set<T> toUnmodifiableSet() {
}
return Collections.unmodifiableSet(collected);
}

@Override
public Stream<T> stream() {
return collected == null ? Stream.empty() : collected.stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
******************************************************************************/
package org.eclipse.equinox.p2.query;

import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

/**
* An IQueryResult represents the results of a query.
Expand Down Expand Up @@ -63,4 +66,18 @@ public interface IQueryResult<T> extends IQueryable<T>, Iterable<T> {
* @return A Set backed by this query result.
*/
Set<T> toUnmodifiableSet();

/**
* Returns a sequential {@code Stream} of the collected objects.
*
* @implSpec The default implementation creates a sequential {@code Stream} from
* this query-results {@code Spliterator}. Implementations backed by a
* {@code Collection} should override this method and call
* {@link Collection#stream()}.
* @since 2.7
*/
default Stream<T> stream() {
return StreamSupport.stream(spliterator(), false);
}

}

0 comments on commit 717690c

Please sign in to comment.