Author: adietish
Date: 2010-09-14 05:37:06 -0400 (Tue, 14 Sep 2010)
New Revision: 24908
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CollectionFilterUtils.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CompositeCollectionFilter.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionEntryConverter.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionFilter.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/NoopConverter.java
Removed:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/CollectionFilterUtils.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/ICollectionEntryFilter.java
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossComponents.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/ReportingEclipseEnvironment.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/BundleUtils.java
Log:
[JBIDE-7035] implemented & tested
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossComponents.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossComponents.java 2010-09-14
03:59:49 UTC (rev 24907)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossComponents.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -17,244 +17,99 @@
import org.eclipse.core.runtime.IBundleGroup;
import org.eclipse.core.runtime.IBundleGroupProvider;
-import org.jboss.tools.usage.util.BundleUtils;
-import org.jboss.tools.usage.util.CollectionFilterUtils;
-import org.jboss.tools.usage.util.ICollectionEntryFilter;
-import org.osgi.framework.Bundle;
+import org.jboss.tools.usage.util.collectionfilter.CollectionFilterUtils;
+import org.jboss.tools.usage.util.collectionfilter.CompositeCollectionFilter;
+import org.jboss.tools.usage.util.collectionfilter.ICollectionFilter;
/**
* @author Andre Dietisheim
*/
public class JBossComponents {
- public enum BundleGroup {
- ARCHIVES("org.jboss.ide.eclipse.archives.core",
- "org.jboss.ide.eclipse.archives.jdt.integration",
- "org.jboss.ide.eclipse.archives.ui"
- )
- , AS("org.jboss.ide.eclipse.archives.webtools",
- "org.jboss.ide.eclipse.as.classpath.core",
- "org.jboss.ide.eclipse.as.classpath.ui",
- "org.jboss.ide.eclipse.as.core",
- "org.jboss.ide.eclipse.as.doc.user",
- "org.jboss.ide.eclipse.as.ssh",
- "org.jboss.ide.eclipse.as.ui",
- "org.jboss.ide.eclipse.as.ui.mbeans",
- "org.jboss.ide.eclipse.as.wtp.core",
- "org.jboss.ide.eclipse.as.wtp.ui")
- , BIRT("org.jboss.tools.birt.core",
- "org.jboss.tools.birt.oda",
- "org.jboss.tools.birt.oda.ui")
- , BPEL("org.eclipse.bpel.apache.ode.deploy.model",
- "org.eclipse.bpel.apache.ode.deploy.ui",
- "org.eclipse.bpel.common.model",
- "org.eclipse.bpel.common.ui",
- "org.eclipse.bpel.model",
- "org.eclipse.bpel.ui",
- "org.eclipse.bpel.validator",
- "org.eclipse.bpel.wsil.model",
- "org.eclipse.bpel.xpath10",
- "org.jboss.tools.bpel.cheatsheet",
- "org.jboss.tools.bpel.runtimes")
- , CDI("org.jboss.tools.cdi.core",
- "org.jboss.tools.cdi.text.ext",
- "org.jboss.tools.cdi.ui",
- "org.jboss.tools.cdi.xml",
- "org.jboss.tools.cdi.xml.ui")
- , DELTACLOUD("org.jboss.tools.deltacloud.core",
- "org.jboss.tools.deltacloud.ui")
- , DROOLS("org.drools.eclipse",
- "org.drools.eclipse.task",
- "org.eclipse.webdav",
- "org.guvnor.tools",
- "org.jboss.tools.flow.ruleflow")
- , ESB("org.jboss.tools.esb.core",
- "org.jboss.tools.esb.project.core",
- "org.jboss.tools.esb.project.ui",
- "org.jboss.tools.esb.ui",
- "org.jboss.tools.esb.validator")
- , FLOW("org.jboss.tools.flow.common")
- , FREEMARKER("org.jboss.ide.eclipse.freemarker")
- , GWT("org.jboss.tools.gwt.core",
- "org.jboss.tools.gwt.ui")
- , HIBERNATETOOLS("org.hibernate.eclipse",
- "org.hibernate.eclipse.console",
- "org.hibernate.eclipse.help",
- "org.hibernate.eclipse.jdt.apt.ui",
- "org.hibernate.eclipse.jdt.ui",
- "org.hibernate.eclipse.mapper",
- "org.jboss.tools.hibernate.jpt.core",
- "org.jboss.tools.hibernate.jpt.ui",
- "org.jboss.tools.hibernate.ui",
- "org.jboss.tools.hibernate.xml",
- "org.jboss.tools.hibernate.xml.ui")
- , JBPM("org.jboss.tools.flow.jpdl4",
- "org.jboss.tools.flow.jpdl4.multipage",
- "org.jboss.tools.jbpm.common",
- "org.jboss.tools.jbpm.convert",
- "org.jbpm.gd.jpdl")
- , JMX("org.jboss.tools.jmx.core",
- "org.jboss.tools.jmx.ui")
- , JSF("org.jboss.tools.jsf",
- "org.jboss.tools.jsf.doc.user",
- "org.jboss.tools.jsf.text.ext",
- "org.jboss.tools.jsf.text.ext.facelets",
- "org.jboss.tools.jsf.text.ext.richfaces",
- "org.jboss.tools.jsf.ui",
- "org.jboss.tools.jsf.verification",
- "org.jboss.tools.jsf.vpe.ajax4jsf",
- "org.jboss.tools.jsf.vpe.facelets",
- "org.jboss.tools.jsf.vpe.jbpm",
- "org.jboss.tools.jsf.vpe.jsf",
- "org.jboss.tools.jsf.vpe.jstl",
- "org.jboss.tools.jsf.vpe.myfaces",
- "org.jboss.tools.jsf.vpe.richfaces",
- "org.jboss.tools.jsf.vpe.seam")
- , JST("org.jboss.tools.jst.css",
- "org.jboss.tools.jst.firstrun",
- "org.jboss.tools.jst.jsp",
- "org.jboss.tools.jst.text.ext",
- "org.jboss.tools.jst.web",
- "org.jboss.tools.jst.web.kb",
- "org.jboss.tools.jst.web.tiles",
- "org.jboss.tools.jst.web.tiles.ui",
- "org.jboss.tools.jst.web.ui",
- "org.jboss.tools.jst.web.verification")
- , LABS("org.jboss.tools.labs.pde.sourceprovider")
- , MAVEN("org.jboss.tools.maven.cdi",
- "org.jboss.tools.maven.core",
- "org.jboss.tools.maven.hibernate",
- "org.jboss.tools.maven.jsf",
- "org.jboss.tools.maven.portlet",
- "org.jboss.tools.maven.seam",
- "org.jboss.tools.maven.ui")
- , MODESHAPE("org.jboss.tools.modeshape.rest")
- , PORTLET("org.jboss.tools.portlet.core",
- "org.jboss.tools.portlet.ui")
- , PROFILER("org.jboss.tools.profiler.ui")
- , RUNTIME("org.jboss.tools.runtime")
- , SEAM("org.jboss.tools.seam.core",
- "org.jboss.tools.seam.doc.user",
- "org.jboss.tools.seam.pages.xml",
- "org.jboss.tools.seam.text.ext",
- "org.jboss.tools.seam.ui",
- "org.jboss.tools.seam.ui.pages",
- "org.jboss.tools.seam.xml",
- "org.jboss.tools.seam.xml.ui")
- , SMOOKS("org.jboss.tools.smooks.core",
- "org.jboss.tools.smooks.runtime",
- "org.jboss.tools.smooks.templating",
- "org.jboss.tools.smooks.ui")
- , STRUTS("org.jboss.tools.struts",
- "org.jboss.tools.struts.text.ext",
- "org.jboss.tools.struts.ui",
- "org.jboss.tools.struts.validator.ui",
- "org.jboss.tools.struts.verification",
- "org.jboss.tools.struts.vpe.struts")
- , TPTP("org.jboss.tools.eclipse.as.tptp")
- , VPE("org.jboss.tools.vpe",
- "org.jboss.tools.vpe.docbook",
- "org.jboss.tools.vpe.html",
- "org.jboss.tools.vpe.jsp",
- "org.jboss.tools.vpe.resref",
- "org.jboss.tools.vpe.spring",
- "org.jboss.tools.vpe.ui.palette",
- "org.jboss.tools.vpe.xulrunner",
- "org.jboss.tools.xulrunner",
- "org.jboss.tools.xulrunner.initializer")
- , WORKINGSET("org.jboss.tools.workingset.core",
- "org.jboss.tools.workingset.ui")
- , WS("rg.jboss.tools.ws.core",
- "org.jboss.tools.ws.creation.core",
- "org.jboss.tools.ws.creation.ui",
- "org.jboss.tools.ws.ui")
- , XULRUNNER("org.mozilla.xpcom",
- "org.mozilla.xulrunner.carbon.macosx",
- "org.mozilla.xulrunner.cocoa.macosx",
- "org.mozilla.xulrunner.gtk.linux.x86",
- "org.mozilla.xulrunner.gtk.linux.x86_64",
- "org.mozilla.xulrunner.win32.win32.x86");
+ public enum JBossToolsFeatureNames {
+ ARCHIVES("org.jboss.ide.eclipse.archives.feature"),
+ BIRT("org.jboss.tools.birt.feature"),
+ BPEL("org.jboss.tools.bpel.feature"),
+ CDI("org.jboss.tools.cdi.feature"),
+ COMMON("org.jboss.tools.common.feature"),
+ DELTACLOUD("org.jboss.tools.deltacloud.feature"),
+ DROOLS("org.drools.eclipse.feature"),
+ ESB("org.jboss.tools.esb.feature"),
+ EXAMPLES("org.jboss.tools.project.examples.feature"),
+ FLOW("org.jboss.tools.flow.common.feature"),
+ FREEMARKER("org.jboss.ide.eclipse.freemarker.feature"),
+ GWT("org.jboss.tools.gwt.feature"),
+ HIBERNATETOOLS("org.hibernate.eclipse.feature"),
+ JBPM("org.jboss.tools.jbpm.common.feature"),
+ JMX("org.jboss.tools.jmx.feature"),
+ JSF("org.jboss.tools.jsf.feature"),
+ MAVEN("org.jboss.tools.maven.feature"),
+ MODESHAPE("org.jboss.tools.modeshape.rest.feature"),
+ PORTLET("org.jboss.tools.portlet.feature"),
+ PROFILER("org.jboss.tools.profiler.feature"),
+ RUNTIME("org.jboss.tools.runtime.feature"),
+ SEAM("org.jboss.tools.seam.feature"),
+ SMOOKS("org.jboss.tools.smooks.feature"),
+ STRUTS("org.jboss.tools.struts.feature"),
+ TPTP("org.jboss.tools.tptp.feature"),
+ USAGE("org.jboss.tools.usage.feature"),
+ VPE("org.jboss.tools.vpe.feature"),
+ WORKINGSET("org.jboss.tools.workingset.feature"),
+ WS("org.jboss.tools.ws.feature"),
+ XULRUNNER("org.mozilla.xulrunner.feature");
- private String[] bundleNames;
+ private String featureName;
- BundleGroup(String... bundleNames) {
- this.bundleNames = bundleNames;
+ JBossToolsFeatureNames(String featureName) {
+ this.featureName = featureName;
}
/**
- * Returns <tt>true</tt> if the given bundle name is a member of this
- * bundle group.
+ * Returns whether the given bundle group has the same name as the this
+ * feature name.
*
* @param bundleName
* the bundle name to check whether it's a member of this
* group of bundles.
* @return <tt>true</tt>, if the given bundle
*/
- public boolean isMember(String bundleName) {
- boolean isMember = false;
- for (String name : bundleNames) {
- if (name.equals(bundleName)) {
- return true;
- }
- }
- return isMember;
+ public boolean matches(IBundleGroup bundleGroup) {
+ return featureName.equals(bundleGroup.getName());
}
- public void addGroupIdTo(Collection<String> bundleGroupIds) {
- bundleGroupIds.add(name());
+ public String getAbbreviation() {
+ return name();
}
}
private static final String JBOSS_TOOLS_BUNDLES_PREFIX =
"org\\.jboss\\.tools.+"; //$NON-NLS-1$
- private static class JBossComponentBundlesFilter implements
ICollectionEntryFilter<Bundle> {
-
- private Collection<String> componentNames;
-
- private JBossComponentBundlesFilter(Collection<String> componentNames) {
- this.componentNames = componentNames;
- }
-
- /**
- * Collects the bundle groups the bundles it gets belong to. Always
- * returns <tt>true</tt> (does match) while collecting
- */
- public boolean matches(Bundle bundle) {
- String bundleName = bundle.getSymbolicName();
- for (BundleGroup bundleGroup : BundleGroup.values()) {
- if (bundleGroup.isMember(bundleName)) {
- componentNames.add(bundleGroup.name());
- break;
- }
- }
- return true;
- }
- }
-
private JBossComponents() {
// inhibit instantiation
}
+
/**
- * Returns the jboss components that the given bundles are members of
+ * Returns the jboss components that the given bundle group provider provides
*
* @param bundles
- * the bundles to check
+ * the bundles group providers to check for jboss components
* @return
*/
- public static Collection<String> getComponentIds(Bundle[] bundles) {
- Set<String> jbossComponentNames = new TreeSet<String>();
- ICollectionEntryFilter<Bundle> jbossToolsFilter = new
BundleUtils.BundleSymbolicNameFilter(
- JBOSS_TOOLS_BUNDLES_PREFIX);
- @SuppressWarnings("unchecked")
- ICollectionEntryFilter<Bundle> compositeFilter = new
CollectionFilterUtils.CompositeCollectionFilter<Bundle>(
- jbossToolsFilter
- , new JBossComponentBundlesFilter(jbossComponentNames));
- BundleUtils.getBundles(compositeFilter, bundles);
- return jbossComponentNames;
+ @SuppressWarnings("unchecked")
+ public static Collection<String> getComponentIds(IBundleGroupProvider[]
bundleGroupProviders) {
+ Set<String> componentNames = new TreeSet<String>();
+ for (IBundleGroupProvider bundleGroupProvider : bundleGroupProviders) {
+ CollectionFilterUtils.filter(
+ new CompositeCollectionFilter<IBundleGroup>(
+ new JBossToolsNameFilter()
+ , new JBossToolsFeaturesFilter(componentNames))
+ , bundleGroupProvider.getBundleGroups(), null);
+ }
+ return componentNames;
}
- private static class JBossBundleGroupNameFilter implements
ICollectionEntryFilter<IBundleGroup> {
+ private static class JBossToolsNameFilter implements
ICollectionFilter<IBundleGroup> {
Pattern pattern = Pattern.compile(JBOSS_TOOLS_BUNDLES_PREFIX);
@@ -263,11 +118,22 @@
}
}
- public static Collection<String> getComponentIds(IBundleGroupProvider[]
bundleGroupProviders) {
- Set<String> components = new TreeSet<String>();
- for (IBundleGroupProvider bundleGroupProvider : bundleGroupProviders) {
- CollectionFilterUtils.filter(new JBossBundleGroupNameFilter(),
bundleGroupProvider.getBundleGroups());
+ private static class JBossToolsFeaturesFilter implements
ICollectionFilter<IBundleGroup> {
+
+ private Collection<String> componentNames;
+
+ private JBossToolsFeaturesFilter(Collection<String> componentNames) {
+ this.componentNames = componentNames;
}
- return components;
+
+ public boolean matches(IBundleGroup bundleGroup) {
+ for (JBossToolsFeatureNames featureName : JBossToolsFeatureNames.values()) {
+ if (featureName.matches(bundleGroup)) {
+ this.componentNames.add(featureName.getAbbreviation());
+ return true;
+ }
+ }
+ return false;
+ }
}
}
\ No newline at end of file
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/ReportingEclipseEnvironment.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/ReportingEclipseEnvironment.java 2010-09-14
03:59:49 UTC (rev 24907)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/ReportingEclipseEnvironment.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -12,17 +12,18 @@
import java.util.Collection;
+import org.eclipse.core.runtime.IBundleGroupProvider;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.jboss.tools.usage.googleanalytics.eclipse.AbstractEclipseEnvironment;
import org.jboss.tools.usage.internal.JBossToolsUsageActivator;
-import org.osgi.framework.Bundle;
/**
* @author Andre Dietisheim
*/
public class ReportingEclipseEnvironment extends AbstractEclipseEnvironment {
- private static final char BUNDLE_GROUP_DELIMITER = '-';
+ private static final char JBOSS_COMPONENTS_DELIMITER = '-';
public ReportingEclipseEnvironment(String accountName, String hostName,
IEclipsePreferences preferences) {
super(accountName, hostName, preferences);
@@ -30,15 +31,16 @@
@Override
public String getKeyword() {
- return bundleGroupsToKeywordString(JBossComponents.getComponentIds(getBundles()));
+ Collection<String> jbossComponentNames =
JBossComponents.getComponentIds(getBundleGroupProviders());
+ return bundleGroupsToKeywordString(jbossComponentNames );
}
- protected Bundle[] getBundles() {
- return
JBossToolsUsageActivator.getDefault().getBundle().getBundleContext().getBundles();
+ protected IBundleGroupProvider[] getBundleGroupProviders() {
+ return Platform.getBundleGroupProviders();
}
private String bundleGroupsToKeywordString(Collection<String> jbossComponentNames)
{
- char delimiter = BUNDLE_GROUP_DELIMITER;
+ char delimiter = JBOSS_COMPONENTS_DELIMITER;
StringBuilder builder = new StringBuilder();
for (String componentName : jbossComponentNames) {
builder.append(componentName)
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/BundleUtils.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/BundleUtils.java 2010-09-14
03:59:49 UTC (rev 24907)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/BundleUtils.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -14,6 +14,8 @@
import java.util.regex.Pattern;
import org.eclipse.core.runtime.Assert;
+import org.jboss.tools.usage.util.collectionfilter.CollectionFilterUtils;
+import org.jboss.tools.usage.util.collectionfilter.ICollectionFilter;
import org.osgi.framework.Bundle;
/**
@@ -23,30 +25,38 @@
/**
* Returns the bundles among the available ones that match the given filter.
- *
- * @param filter the filter to match the available bundles against
- * @param bundles the bundles
+ *
+ * @param filter
+ * the filter to match the available bundles against
+ * @param bundles
+ * the bundles
* @return the bundles that match the given filter
*/
- public static Collection<Bundle> getBundles(ICollectionEntryFilter<Bundle>
filter, Bundle[] bundles) {
- return CollectionFilterUtils.filter(filter, bundles);
+ public static void getBundles(ICollectionFilter<Bundle> filter,
Collection<Bundle> filteredBundleCollection,
+ Bundle[] bundles) {
+ CollectionFilterUtils.filter(filter, bundles, filteredBundleCollection);
}
/**
* Returns the bundles that have a symbolic name that match the given regex.
- *
- * @param bundleSymbolicNameRegex the symbolic name regex to match.
- * @param bundles the bundles
+ *
+ * @param bundleSymbolicNameRegex
+ * the symbolic name regex to match.
+ * @param bundles
+ * the bundles
* @return the bundles
*/
- public static Collection<Bundle> getBundles(String bundleSymbolicNameRegex,
Bundle[] bundles) {
- return getBundles(new BundleSymbolicNameFilter(bundleSymbolicNameRegex), bundles);
+ public static void getBundles(String bundleSymbolicNameRegex, Collection<Bundle>
filteredBundleCollection,
+ Bundle[] bundles) {
+ getBundles(new BundleSymbolicNameFilter(bundleSymbolicNameRegex)
+ , filteredBundleCollection
+ , bundles);
}
/**
* A filter that matches bundles against a given symbolic name regex.
*/
- public static class BundleSymbolicNameFilter implements
ICollectionEntryFilter<Bundle> {
+ public static class BundleSymbolicNameFilter implements ICollectionFilter<Bundle>
{
private Pattern pattern;
Deleted:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/CollectionFilterUtils.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/CollectionFilterUtils.java 2010-09-14
03:59:49 UTC (rev 24907)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/CollectionFilterUtils.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.usage.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-
-/**
- * @author Andre Dietisheim
- */
-public class CollectionFilterUtils {
-
- /**
- * A filter that applies several given filters
- */
- public static class CompositeCollectionFilter<E> implements
ICollectionEntryFilter<E> {
-
- private ICollectionEntryFilter<E> filters[];
-
- /**
- * Instantiates a new composite filter that applies several given
- * filters.
- *
- * @param filters
- * the filters
- */
- public CompositeCollectionFilter(ICollectionEntryFilter<E>... filters) {
- this.filters = filters;
- }
-
- /**
- * Applies the filters this composite filter has. All filters have to
- * match so that the filter says the given bundle matches.
- */
- public boolean matches(E entry) {
- for (ICollectionEntryFilter<E> filter : filters) {
- if (!filter.matches(entry)) {
- return false;
- }
- }
- return true;
- }
- }
-
- /**
- * Returns the entries that match the given filter.
- *
- * @param filter the filter to match the available entries against
- * @param entries the entries to filter
- * @return the entries that match the given filter
- */
- public static <E> Collection<E> filter(ICollectionEntryFilter<E>
filter, E[] entries) {
- List<E> filteredList = new ArrayList<E>();
- for (E entry : entries) {
- if (filter.matches(entry)) {
- filteredList.add(entry);
- }
- }
- return filteredList;
- }
-
-}
Deleted:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/ICollectionEntryFilter.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/ICollectionEntryFilter.java 2010-09-14
03:59:49 UTC (rev 24907)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/ICollectionEntryFilter.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.usage.util;
-/**
- * @authro Andre Dietisheim
- */
-public interface ICollectionEntryFilter<E> {
-
- /**
- * Matches.
- *
- * @param bundle
- * the bundle
- * @return true, if successful
- */
- public boolean matches(E entry);
-}
\ No newline at end of file
Copied:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CollectionFilterUtils.java
(from rev 24877,
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/CollectionFilterUtils.java)
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CollectionFilterUtils.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CollectionFilterUtils.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.util.collectionfilter;
+
+import java.util.Collection;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class CollectionFilterUtils {
+
+ public static <E, T> void filter(ICollectionFilter<E> filter, E[] entries,
Collection<T> targetColletion) {
+ filter(filter, new NoopConverter<E, T>(), entries, targetColletion);
+ }
+
+ /**
+ * Returns the entries that match the given filter.
+ *
+ * @param filter
+ * the filter to match the available entries against
+ * @param entries
+ * the entries to filter
+ * @return the entries that match the given filter
+ */
+ public static <E, T> void filter(ICollectionFilter<E> filter,
ICollectionEntryConverter<E, T> converter,
+ E[] entries, Collection<T> targetColletion) {
+ for (E entry : entries) {
+ if (filter.matches(entry)) {
+ if (targetColletion != null) {
+ targetColletion.add(converter.convert(entry));
+ }
+ }
+ }
+ }
+}
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CollectionFilterUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CompositeCollectionFilter.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CompositeCollectionFilter.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CompositeCollectionFilter.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.usage.util.collectionfilter;
+
+public class CompositeCollectionFilter<E> implements ICollectionFilter<E> {
+
+ private ICollectionFilter<E> filters[];
+
+ /**
+ * Instantiates a new composite filter that applies several given
+ * filters.
+ *
+ * @param filters
+ * the filters
+ */
+ public CompositeCollectionFilter(ICollectionFilter<E>... filters) {
+ this.filters = filters;
+ }
+
+ /**
+ * Applies the filters this composite filter has. All filters have to
+ * match so that the filter says the given bundle matches.
+ */
+ public boolean matches(E entry) {
+ for (ICollectionFilter<E> filter : filters) {
+ if (!filter.matches(entry)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/CompositeCollectionFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionEntryConverter.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionEntryConverter.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionEntryConverter.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.util.collectionfilter;
+
+public interface ICollectionEntryConverter<E, T> {
+ public T convert(E entry);
+}
\ No newline at end of file
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionEntryConverter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionFilter.java
(from rev 24874,
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/ICollectionEntryFilter.java)
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionFilter.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionFilter.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.util.collectionfilter;
+/**
+ * @authro Andre Dietisheim
+ */
+public interface ICollectionFilter<E> {
+
+ /**
+ * Matches.
+ *
+ * @param bundle
+ * the bundle
+ * @return true, if successful
+ */
+ public boolean matches(E entry);
+}
\ No newline at end of file
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/ICollectionFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/NoopConverter.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/NoopConverter.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/NoopConverter.java 2010-09-14
09:37:06 UTC (rev 24908)
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.util.collectionfilter;
+
+
+public class NoopConverter<E, T> implements ICollectionEntryConverter<E, T>
{
+
+ @SuppressWarnings("unchecked")
+ public T convert(E entry) {
+ return (T) entry;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/collectionfilter/NoopConverter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain