diff options
author | John Arthorne | 2008-11-12 19:20:48 +0000 |
---|---|---|
committer | John Arthorne | 2008-11-12 19:20:48 +0000 |
commit | 129e7e2e57a8405cb74e5538aa8157df02691369 (patch) | |
tree | 6226dfc9ebdfece3c07aed84018da7e144593bf8 /bundles | |
parent | 6c7341c9dfed205bde1fae40ace7703b3e2dad8f (diff) | |
download | rt.equinox.p2-129e7e2e57a8405cb74e5538aa8157df02691369.tar.gz rt.equinox.p2-129e7e2e57a8405cb74e5538aa8157df02691369.tar.xz rt.equinox.p2-129e7e2e57a8405cb74e5538aa8157df02691369.zip |
Bug 254955 Collector should handle duplicates
Diffstat (limited to 'bundles')
6 files changed, 22 insertions, 19 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/query/Collector.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/query/Collector.java index 397afc985..ffc892a17 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/query/Collector.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/query/Collector.java @@ -23,7 +23,7 @@ import java.util.*; * to perform different processing on the objects passed to it. */ public class Collector { - private ArrayList collected = null; + private Set collected = null; /** * Creates a new collector. @@ -45,17 +45,21 @@ public class Collector { * or <code>false</code> to indicate the traversal should stop. */ public boolean accept(Object object) { - getList().add(object); + getCollection().add(object); return true; } /** - * Returns the list that is being used to collect results. - * @return the list being used to collect results. + * Returns the collection that is being used to collect results. Unlike {@toCollection}, + * 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. + * + * @return the collection being used to collect results. */ - protected List getList() { + protected Collection getCollection() { if (collected == null) - collected = new ArrayList(); + collected = new HashSet(); return collected; } @@ -100,7 +104,12 @@ public class Collector { return result; } + /** + * Returns the collected objects as an immutable collection. + * + * @return An unmodifiable collection of the collected objects + */ public Collection toCollection() { - return collected == null ? Collections.EMPTY_LIST : Collections.unmodifiableList(collected); + return collected == null ? Collections.EMPTY_SET : Collections.unmodifiableSet(collected); } } diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/LatestIUVersionCollector.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/LatestIUVersionCollector.java index 209b66d8e..96281fae6 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/LatestIUVersionCollector.java +++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/LatestIUVersionCollector.java @@ -22,7 +22,7 @@ public class LatestIUVersionCollector extends Collector { Object matchElement = uniqueIds.get(iu.getId()); if (matchElement == null || iu.getVersion().compareTo(getIU(matchElement).getVersion()) > 0) { if (matchElement != null) - getList().remove(matchElement); + getCollection().remove(matchElement); matchElement = makeDefaultElement(iu); uniqueIds.put(iu.getId(), matchElement); diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/ProductQuery.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/ProductQuery.java index 8486d52b7..5e76dacf8 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/ProductQuery.java +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/ProductQuery.java @@ -41,7 +41,7 @@ public class ProductQuery extends Query { IInstallableUnit existing = (IInstallableUnit) elements.get(iu.getId()); if (existing.getVersion().compareTo(iu.getVersion()) >= 0) return true; - getList().remove(existing); + getCollection().remove(existing); } elements.put(iu.getId(), iu); return super.accept(object); diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java index e560ea048..f6aaef1c8 100644 --- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java +++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java @@ -43,12 +43,6 @@ public class ProfileSynchronizer { private static final String NO_TIMESTAMP = "-1"; //$NON-NLS-1$ private static final String PROP_FROM_DROPINS = "org.eclipse.equinox.p2.reconciler.dropins"; //$NON-NLS-1$ - public class ListCollector extends Collector { - public List getList() { - return super.getList(); - } - } - private static final String CACHE_EXTENSIONS = "org.eclipse.equinox.p2.cache.extensions"; //$NON-NLS-1$ private static final String PIPE = "|"; //$NON-NLS-1$ final IProfile profile; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/CategoryElementCollector.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/CategoryElementCollector.java index 826970ced..a66e3d210 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/CategoryElementCollector.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/CategoryElementCollector.java @@ -132,15 +132,15 @@ public class CategoryElementCollector extends QueriedElementCollector { ElementQueryDescriptor queryDescriptor = element.getQueryProvider().getQueryDescriptor(element); Collector collector = queryDescriptor.queryable.query(queryDescriptor.query, queryDescriptor.collector, null); if (!collector.isEmpty()) - getList().add(element); + getCollection().add(element); } private void removeNestedCategories() { - CategoryElement[] categoryIUs = (CategoryElement[]) getList().toArray(new CategoryElement[getList().size()]); + CategoryElement[] categoryIUs = (CategoryElement[]) getCollection().toArray(new CategoryElement[getCollection().size()]); // If any other element refers to a category element, remove it from the list for (int i = 0; i < categoryIUs.length; i++) { if (referredIUs.contains(categoryIUs[i].getIU().getId())) { - getList().remove(categoryIUs[i]); + getCollection().remove(categoryIUs[i]); } } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/LatestIUVersionCollector.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/LatestIUVersionCollector.java index 0814fd156..2b80e6c8b 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/LatestIUVersionCollector.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/LatestIUVersionCollector.java @@ -46,7 +46,7 @@ public class LatestIUVersionCollector extends AvailableIUCollector { Object matchElement = uniqueIds.get(iu.getId()); if (matchElement == null || iu.getVersion().compareTo(getIU(matchElement).getVersion()) > 0) { if (matchElement != null) - getList().remove(matchElement); + getCollection().remove(matchElement); matchElement = makeDefaultElement(iu); uniqueIds.put(iu.getId(), matchElement); return super.accept(matchElement); |