Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2008-11-12 19:20:48 +0000
committerJohn Arthorne2008-11-12 19:20:48 +0000
commit129e7e2e57a8405cb74e5538aa8157df02691369 (patch)
tree6226dfc9ebdfece3c07aed84018da7e144593bf8 /bundles/org.eclipse.equinox.p2.core
parent6c7341c9dfed205bde1fae40ace7703b3e2dad8f (diff)
downloadrt.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/org.eclipse.equinox.p2.core')
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/query/Collector.java23
1 files changed, 16 insertions, 7 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);
}
}

Back to the top