Author: adietish
Date: 2010-12-03 13:57:35 -0500 (Fri, 03 Dec 2010)
New Revision: 27160
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java
Log:
[JBIDE-7688] provide common superclass and interface to ImageFilter and InstanceFilter
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java 2010-12-03
18:57:35 UTC (rev 27160)
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.deltacloud.core;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.core.runtime.Assert;
+
+/**
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public abstract class AbstractCloudElementFilter<CLOUDELEMENT extends
IDeltaCloudElement> implements
+ ICloudElementFilter<CLOUDELEMENT> {
+
+ private IFieldMatcher nameRule;
+ private IFieldMatcher idRule;
+
+ public Collection<CLOUDELEMENT> filter(CLOUDELEMENT[] cloudElements) {
+ List<CLOUDELEMENT> filteredElements = new ArrayList<CLOUDELEMENT>();
+ for (CLOUDELEMENT cloudElement : cloudElements) {
+ if (matches(cloudElement)) {
+ filteredElements.add(cloudElement);
+ }
+ }
+ return filteredElements;
+ }
+
+ protected boolean matches(CLOUDELEMENT cloudElement) {
+ return nameRule.matches(cloudElement.getName())
+ && idRule.matches(cloudElement.getId());
+ }
+
+ public abstract void setRules(String rulesString) throws PatternSyntaxException;
+
+ protected Iterator<String> setRules(String ruleString, Iterator<String>
rulesIterator)
+ throws PatternSyntaxException {
+ this.nameRule = createRule(rulesIterator);
+ this.idRule = createRule(rulesIterator);
+ return rulesIterator;
+ }
+
+ protected Iterator<String> getRulesIterator(String ruleString) {
+ return Arrays.asList(ruleString.split(";")).iterator();
+ }
+
+ protected IFieldMatcher createRule(Iterator<String> rulesIterator) {
+ Assert.isLegal(rulesIterator.hasNext());
+ String expression = rulesIterator.next();
+ if (expression.equals(ALL_MATCHER_EXPRESSION)) { //$NON-NLS-1$
+ return new AllFieldMatcher();
+ } else {
+ return new FieldMatcher(expression);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return nameRule + ";" //$NON-NLS-1$
+ + idRule + ";"; //$NON-NLS-1$
+ }
+
+ @Override
+ public IFieldMatcher getNameRule() {
+ return nameRule;
+ }
+
+ @Override
+ public IFieldMatcher getIdRule() {
+ return idRule;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java 2010-12-03
18:47:10 UTC (rev 27159)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java 2010-12-03
18:57:35 UTC (rev 27160)
@@ -10,12 +10,21 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core;
-public class AllImageFilter implements IImageFilter {
+/**
+ * A filter for images that matches on all elements (no criteria checked)
+ *
+ * @see IImageFilter
+ * @see DeltaCloud#getImageFilter()
+ *
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public class AllImageFilter extends AbstractCloudElementFilter<DeltaCloudImage>
implements IImageFilter {
private IFieldMatcher matcher = new AllFieldMatcher();
@Override
- public boolean isVisible(DeltaCloudImage image) {
+ public boolean matches(DeltaCloudImage image) {
return true;
}
@@ -28,15 +37,7 @@
public String toString() {
return ALL_STRING;
}
-
- public IFieldMatcher getNameRule() {
- return matcher;
- }
-
- public IFieldMatcher getIdRule() {
- return matcher;
- }
-
+
public IFieldMatcher getArchRule() {
return matcher;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java 2010-12-03
18:47:10 UTC (rev 27159)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java 2010-12-03
18:57:35 UTC (rev 27160)
@@ -1,11 +1,20 @@
package org.jboss.tools.deltacloud.core;
-public class AllInstanceFilter implements IInstanceFilter {
+/**
+ * A filter for instances that matches on all elements (no criteria checked)
+ *
+ * @see IInstanceFilter
+ * @see DeltaCloud#getInstanceFilter()
+ *
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public class AllInstanceFilter extends
AbstractCloudElementFilter<DeltaCloudInstance> implements IInstanceFilter {
private IFieldMatcher matcher = new AllFieldMatcher();
-
+
@Override
- public boolean isVisible(DeltaCloudInstance instance) {
+ public boolean matches(DeltaCloudInstance instance) {
return true;
}
@@ -13,23 +22,13 @@
public void setRules(String ruleString) {
// ignore, never set the rules for this filter
}
-
+
@Override
public String toString() {
return ALL_STRING;
}
-
+
@Override
- public IFieldMatcher getNameRule() {
- return matcher; //$NON-NLS-1$
- }
-
- @Override
- public IFieldMatcher getIdRule() {
- return matcher; //$NON-NLS-1$
- }
-
- @Override
public IFieldMatcher getImageIdRule() {
return matcher;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java 2010-12-03
18:47:10 UTC (rev 27159)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java 2010-12-03
18:57:35 UTC (rev 27160)
@@ -10,27 +10,38 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core;
+import java.util.Collection;
+
+
/**
+ * A filter interface that may be applied on IDeltaCloudElement. Known implementors are
IImageFilter and IInstanceFilter
+ *
+ * @see IDeltaCloudElement
+ * @see IImageFilter
+ * @see IInstanceFilter
+ *
* @author Jeff Johnston
* @author André Dietisheim
*/
-public interface ICloudElementFilter<CLOUDCHILD> {
+public interface ICloudElementFilter<CLOUDELEMENT extends IDeltaCloudElement> {
public static final String EXPRESSION_DELIMITER = ";"; // $NON-NLS-1$
public static final String ALL_MATCHER_EXPRESSION = "*"; //$NON-NLS-1$
- public static final String ALL_STRING =
- ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // name
- + ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // id
- + ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // arch
- + ALL_MATCHER_EXPRESSION; // desc
+ public static final String ALL_STRING =
+ ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // name
+ + ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // id
+ + ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // arch
+ + ALL_MATCHER_EXPRESSION; // desc
- public boolean isVisible(CLOUDCHILD cloudChild);
+ public Collection<CLOUDELEMENT> filter(CLOUDELEMENT[] cloudElements);
+
+// public boolean matches(CLOUDELEMENT cloudElement);
+
public void setRules(String ruleString);
+
public IFieldMatcher getNameRule();
+
public IFieldMatcher getIdRule();
-
-
-
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java 2010-12-03
18:47:10 UTC (rev 27159)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java 2010-12-03
18:57:35 UTC (rev 27160)
@@ -10,19 +10,25 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core;
+import java.util.Iterator;
import java.util.regex.PatternSyntaxException;
-public class ImageFilter implements IImageFilter {
+/**
+ * A filter that may be applied on DeltaCloudImages
+ *
+ * @see DeltaCloudImage
+ *
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public class ImageFilter extends AbstractCloudElementFilter<DeltaCloudImage>
implements IImageFilter {
- private IFieldMatcher nameRule;
- private IFieldMatcher idRule;
private IFieldMatcher archRule;
private IFieldMatcher descRule;
@Override
- public boolean isVisible(DeltaCloudImage image) {
- return nameRule.matches(image.getName()) &&
- idRule.matches(image.getId()) &&
+ public boolean matches(DeltaCloudImage image) {
+ return super.matches(image) &&
archRule.matches(image.getArchitecture()) &&
descRule.matches(image.getDescription());
}
@@ -30,37 +36,18 @@
@Override
public void setRules(String ruleString) throws PatternSyntaxException {
// TODO: replace filter passing (;-delimited string) by list
- String[] tokens = ruleString.split(";");
- this.nameRule = createRule(tokens[0]);
- this.idRule = createRule(tokens[1]);
- this.archRule = createRule(tokens[2]);
- this.descRule = createRule(tokens[3]);
+ Iterator<String> rulesIterator = super.setRules(ruleString,
getRulesIterator(ruleString));
+ this.archRule = createRule(rulesIterator);
+ this.descRule = createRule(rulesIterator);
}
-
- private IFieldMatcher createRule(String token) {
- if (token.equals(ALL_MATCHER_EXPRESSION)) { //$NON-NLS-1$
- return new AllFieldMatcher();
- } else {
- return new FieldMatcher(token);
- }
- }
@Override
public String toString() {
- return nameRule + ";" //$NON-NLS-1$
- + idRule + ";" //$NON-NLS-1$
+ return super.toString() //$NON-NLS-1$
+ archRule + ";" //$NON-NLS-1$
+ descRule; //$NON-NLS-1$
}
-
- public IFieldMatcher getNameRule() {
- return nameRule;
- }
- public IFieldMatcher getIdRule() {
- return idRule;
- }
-
public IFieldMatcher getArchRule() {
return archRule;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java 2010-12-03
18:47:10 UTC (rev 27159)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java 2010-12-03
18:57:35 UTC (rev 27160)
@@ -10,15 +10,19 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core;
+import java.util.Iterator;
import java.util.regex.PatternSyntaxException;
/**
+ * A filter that may be applied on DeltaCloudInstances
+ *
+ * @see DeltaCloudInstance
+ *
* @author Jeff Johnston
+ * @author André Dietisheim
*/
-public class InstanceFilter implements IInstanceFilter {
+public class InstanceFilter extends AbstractCloudElementFilter<DeltaCloudInstance>
implements IInstanceFilter {
- private IFieldMatcher nameRule;
- private IFieldMatcher idRule;
private IFieldMatcher imageIdRule;
private IFieldMatcher realmRule;
private IFieldMatcher profileRule;
@@ -26,9 +30,8 @@
private IFieldMatcher keyNameRule;
@Override
- public boolean isVisible(DeltaCloudInstance instance) {
- return nameRule.matches(instance.getName()) &&
- idRule.matches(instance.getId()) &&
+ public boolean matches(DeltaCloudInstance instance) {
+ return super.matches(instance) &&
imageIdRule.matches(instance.getImageId()) &&
ownerIdRule.matches(instance.getOwnerId()) &&
keyNameRule.matches(instance.getKey()) &&
@@ -38,28 +41,17 @@
@Override
public void setRules(String ruleString) throws PatternSyntaxException {
- String[] tokens = ruleString.split(";");
- this.nameRule = createRule(tokens[0]);
- this.idRule = createRule(tokens[1]);
- this.imageIdRule = createRule(tokens[2]);
- this.ownerIdRule = createRule(tokens[3]);
- this.keyNameRule = createRule(tokens[4]);
- this.realmRule = createRule(tokens[5]);
- this.profileRule = createRule(tokens[6]);
+ Iterator<String> rulesIterator = super.setRules(ruleString,
getRulesIterator(ruleString));
+ this.imageIdRule = createRule(rulesIterator);
+ this.ownerIdRule = createRule(rulesIterator);
+ this.keyNameRule = createRule(rulesIterator);
+ this.realmRule = createRule(rulesIterator);
+ this.profileRule = createRule(rulesIterator);
}
-
- private IFieldMatcher createRule(String expression) {
- if (expression.equals(ALL_MATCHER_EXPRESSION)) { //$NON-NLS-1$
- return new AllFieldMatcher();
- } else {
- return new FieldMatcher(expression);
- }
- }
@Override
public String toString() {
- return nameRule + ";" //$NON-NLS-1$
- + idRule + ";" //$NON-NLS-1$
+ return super.toString()
+ imageIdRule + ";" //$NON-NLS-1$
+ ownerIdRule + ";" //$NON-NLS-1$
+ keyNameRule + ";" //$NON-NLS-1$
@@ -68,16 +60,6 @@
}
@Override
- public IFieldMatcher getNameRule() {
- return nameRule;
- }
-
- @Override
- public IFieldMatcher getIdRule() {
- return idRule;
- }
-
- @Override
public IFieldMatcher getImageIdRule() {
return imageIdRule;
}