diff options
author | ibull | 2009-12-07 18:30:40 +0000 |
---|---|---|
committer | ibull | 2009-12-07 18:30:40 +0000 |
commit | bca569eeb1e0a3e7d721c20d6a4681c9860961b2 (patch) | |
tree | fd43f747fbf739e5b1cc49ae6573f5444aeb35ce | |
parent | f55d120f6d45a5341b641683f19a0fc8b754b2e0 (diff) | |
download | rt.equinox.p2-bca569eeb1e0a3e7d721c20d6a4681c9860961b2.tar.gz rt.equinox.p2-bca569eeb1e0a3e7d721c20d6a4681c9860961b2.tar.xz rt.equinox.p2-bca569eeb1e0a3e7d721c20d6a4681c9860961b2.zip |
295533: [query] Use the Limit query instead of custom collectors to short circuit a query https://bugs.eclipse.org/bugs/show_bug.cgi?id=295533
This removes the different short curcuit collectors and replaces them with the limit query.
6 files changed, 10 insertions, 110 deletions
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/HasMatchCollector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/HasMatchCollector.java deleted file mode 100644 index 058e3b3a7..000000000 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/HasMatchCollector.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.p2.director; - -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; - -/** - * A collector that short-circuits on the first match. - */ -public class HasMatchCollector extends Collector { - private boolean hasMatch = false; - - public boolean accept(Object object) { - hasMatch = true; - return false; - } - - public boolean isEmpty() { - return !hasMatch; - } - -} diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java index 1b36f6029..11ab1d001 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java @@ -10,8 +10,6 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.director; -import org.eclipse.equinox.p2.metadata.IInstallableUnit; - import java.net.URI; import java.util.*; import java.util.Map.Entry; @@ -27,6 +25,7 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.Inst import org.eclipse.equinox.internal.provisional.p2.metadata.query.*; import org.eclipse.equinox.p2.engine.IProvisioningPlan; import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.IRequirement; import org.eclipse.equinox.p2.metadata.query.IQuery; import org.eclipse.equinox.p2.repository.IRepositoryManager; @@ -373,7 +372,7 @@ public class SimplePlanner implements IPlanner { Collection allMetaRequirements = extractMetaRequirements(newProfile, initialPlan); for (Iterator iterator = allMetaRequirements.iterator(); iterator.hasNext();) { IRequirement requirement = (IRequirement) iterator.next(); - if (oldProfile.query(requirement.getMatches(), new HasMatchCollector(), null).isEmpty()) + if (oldProfile.query(new LimitQuery(requirement.getMatches(), 1), new Collector(), null).isEmpty()) return allMetaRequirements; } return null; diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/SingleElementCollector.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/SingleElementCollector.java deleted file mode 100644 index 23fb74956..000000000 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/SingleElementCollector.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation - ******************************************************************************/ -package org.eclipse.equinox.internal.p2.publisher; - -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; - -/** - * Collect a single element and stop the Query - */ -public class SingleElementCollector extends Collector { - - public boolean accept(Object object) { - super.accept(object); - return false; - } - - public Object getElement() { - if (!isEmpty()) - return iterator().next(); - return null; - } -} diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java index 19f8c0718..5acb37236 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java @@ -19,7 +19,8 @@ import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.FileUtils.IPathComputer; import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability; import org.eclipse.equinox.internal.p2.metadata.LDAPQuery; -import org.eclipse.equinox.internal.p2.publisher.*; +import org.eclipse.equinox.internal.p2.publisher.Activator; +import org.eclipse.equinox.internal.p2.publisher.QuotedTokenizer; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.*; import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription; @@ -524,13 +525,11 @@ public abstract class AbstractPublisherAction implements IPublisherAction { */ protected IInstallableUnit queryForIU(IPublisherResult publisherResult, String iuId, Version version) { IQuery query = null; - Collector collector = null; + Collector collector = new Collector(); if (version != null && !Version.emptyVersion.equals(version)) { - query = new InstallableUnitQuery(iuId, version); - collector = new SingleElementCollector(); + query = new LimitQuery(new InstallableUnitQuery(iuId, version), 1); } else { query = new PipedQuery(new IQuery[] {new InstallableUnitQuery(iuId), new LatestIUVersionQuery()}); - collector = new Collector(); } NullProgressMonitor progress = new NullProgressMonitor(); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/QueryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/QueryTest.java index f72ec5569..93c7455c7 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/QueryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/QueryTest.java @@ -64,19 +64,8 @@ public class QueryTest extends TestCase { } /** - * A collector that only accepts the first element and then short-circuits. - */ - static class ShortCircuitCollector extends Collector { - @Override - public boolean accept(Object object) { - super.accept(object); - return false; - } - } - - /** - * Tests a simple perform where all items match. - */ + * Tests a simple perform where all items match. + */ public void testPerformSimple() { List items = Arrays.asList("red", "green", "blue"); IQuery query = new AnyStringQuery(); @@ -266,30 +255,6 @@ public class QueryTest extends TestCase { assertTrue("1.9", query2.areHooksExecutedProperly()); } - /** - * Tests a perform where the collector decides to short-circuit the query. - */ - public void testShortCircuit() { - List items = Arrays.asList("red", "green", "blue"); - IQuery query = new AnyStringQuery(); - Collector collector = new ShortCircuitCollector(); - query.perform(items.iterator(), collector); - Collection result = collector.toCollection(); - assertEquals("1.0", 1, result.size()); - assertTrue("1.1", result.contains("red")); - } - - public void testShortCircuitWithLimit() { - List items = Arrays.asList("red", "green", "blue"); - IQuery query = new AnyStringQuery(); - IQuery limitQuery = new LimitQuery(query, 2); - Collector collector = new ShortCircuitCollector(); - limitQuery.perform(items.iterator(), collector); - Collection result = collector.toCollection(); - assertEquals("1.0", 1, result.size()); - assertTrue("1.1", result.contains("red")); // The short circuit should trump the limit - } - public void testLimitQuery() { List items = Arrays.asList("red", "green", "blue"); IQuery query = new AnyStringQuery(); diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java index 458edd027..3ef1ac2f9 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java @@ -151,13 +151,8 @@ public class SiteXMLAction extends AbstractPublisherAction { query = new PipedQuery(new IQuery[] {qualifierQuery, new LatestIUVersionQuery()}); collector = new Collector(); } else { - query = new InstallableUnitQuery(id, version); - collector = new Collector() { - public boolean accept(Object object) { - super.accept(object); - return false; //stop searching once we've found one - } - }; + query = new LimitQuery(new InstallableUnitQuery(id, version), 1); + collector = new Collector(); } } |