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 11, 2023
1 parent 5058924 commit a55a707
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
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 @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.p2.metadata;singleton:=true
Bundle-Version: 2.7.100.qualifier
Bundle-Version: 2.8.0.qualifier

Check warning on line 5 in bundles/org.eclipse.equinox.p2.metadata/META-INF/MANIFEST.MF

View workflow job for this annotation

GitHub Actions / build / Verify Linux

The minor version should be the same for version 2.8.0, since no new APIs have been added since version 2.7.100

Check warning on line 5 in bundles/org.eclipse.equinox.p2.metadata/META-INF/MANIFEST.MF

View workflow job for this annotation

GitHub Actions / build / Verify Windows

The minor version should be the same for version 2.8.0, since no new APIs have been added since version 2.7.100

Check warning on line 5 in bundles/org.eclipse.equinox.p2.metadata/META-INF/MANIFEST.MF

View workflow job for this annotation

GitHub Actions / build / Verify MacOS

The minor version should be the same for version 2.8.0, since no new APIs have been added since version 2.7.100
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.equinox.internal.p2.metadata;
Expand Down
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.8
*/
default Stream<T> stream() {
return StreamSupport.stream(spliterator(), false);
}

}

0 comments on commit a55a707

Please sign in to comment.