implemented meaningful toString method for filters
diff --git a/org.eclipse.rmf.reqif10.search.test/src/org/eclipse/rmf/reqif10/search/test/AbstractFilterTest.java b/org.eclipse.rmf.reqif10.search.test/src/org/eclipse/rmf/reqif10/search/test/AbstractFilterTest.java
index 01d1600..94443d2 100644
--- a/org.eclipse.rmf.reqif10.search.test/src/org/eclipse/rmf/reqif10/search/test/AbstractFilterTest.java
+++ b/org.eclipse.rmf.reqif10.search.test/src/org/eclipse/rmf/reqif10/search/test/AbstractFilterTest.java
@@ -27,6 +27,7 @@
import org.eclipse.rmf.reqif10.SpecObject;
import org.eclipse.rmf.reqif10.SpecObjectType;
import org.eclipse.rmf.reqif10.pror.testframework.AbstractItemProviderTest;
+import org.eclipse.rmf.reqif10.search.filter.AbstractAttributeFilter;
import org.eclipse.rmf.reqif10.search.filter.IFilter;
import org.eclipse.rmf.reqif10.search.filter.IFilter.Operator;
import org.junit.Test;
@@ -65,6 +66,16 @@
c = (c == null ? 1 : ++c);
operatorCounts.put(filter.getOperator(), c);
+ //System.out.println("runnging Filter:");
+ System.out.println(filter.toString());
+
+ if (filter instanceof AbstractAttributeFilter) {
+ AbstractAttributeFilter new_name = (AbstractAttributeFilter) filter;
+ //System.out.println(new_name.getFilterValue1AsString());
+
+ }
+ //System.out.println(filter.getFilterValue1());
+
assertEquals(expected, filter.match(getFixture()));
}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/AbstractAttributeFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/AbstractAttributeFilter.java
index aad0577..6f95861 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/AbstractAttributeFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/AbstractAttributeFilter.java
@@ -90,4 +90,51 @@
public ImmutableSet<Operator> getSupportedOperators() {
return SUPPORTED_OPERATORS;
}
+
+
+ public String toString(){
+ StringBuilder sb = new StringBuilder();
+
+ String attribute = null;
+ if (getAttribute() instanceof AttributeDefinition) {
+ AttributeDefinition ad = (AttributeDefinition) getAttribute();
+ attribute = ad.getLongName();
+ if (attribute == null){
+ attribute = ad.getDesc();
+ }
+ if (attribute == null){
+ attribute = "Attribute with ID="+ad.getIdentifier();
+ }
+ }else{
+ attribute = getAttribute().toString();
+ }
+
+ sb.append(attribute);
+ sb.append(" ");
+
+ sb.append(getOperator().toLocaleString());
+
+ if (getOperator() == Operator.IS_SET || getOperator() == Operator.IS_NOT_SET){
+ // we dont want any values for these operations and return;
+ return sb.toString();
+ }
+
+ sb.append(" ");
+ sb.append(getFilterValue1AsString());
+ if (getOperator().equals(Operator.BETWEEN)){
+ sb.append(" and ").append(getFilterValue2AsString());
+ }
+
+ return sb.toString();
+ }
+
+ public String getFilterValue1AsString() {
+ return getFilterValue1().toString();
+ }
+
+ public String getFilterValue2AsString() {
+ return getFilterValue2().toString();
+ }
+
+
}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/BoolFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/BoolFilter.java
index fe9e632..321266b 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/BoolFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/BoolFilter.java
@@ -108,4 +108,5 @@
return SUPPORTED_OPERATORS;
}
+
}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/DateFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/DateFilter.java
index 4f7ae08..6d200f9 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/DateFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/DateFilter.java
@@ -11,6 +11,7 @@
******************************************************************************/
package org.eclipse.rmf.reqif10.search.filter;
+import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import org.eclipse.rmf.reqif10.AttributeDefinitionDate;
@@ -59,6 +60,7 @@
if (null == attributeDefinition){
throw new IllegalArgumentException("AttributeDefinition can not be null");
}
+ System.out.println("Instatiated new Filter: " + toString());
}
/**
@@ -76,6 +78,7 @@
if (null == internalFeature){
throw new IllegalArgumentException("AttributeDefinition can not be null");
}
+ System.out.println("Instatiated new Filter: " + toString());
}
private DateFilter(Operator operator, GregorianCalendar value1, GregorianCalendar value2,
@@ -234,4 +237,16 @@
}
+ @Override
+ public String getFilterValue1AsString() {
+ SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MMM-dd");
+ return fmt.format(getFilterValue1().getTime());
+ }
+
+ @Override
+ public String getFilterValue2AsString() {
+ SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MMM-dd");
+ return fmt.format(getFilterValue2().getTime());
+ }
+
}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/EnumFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/EnumFilter.java
index 44d42e6..215b28d 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/EnumFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/EnumFilter.java
@@ -13,6 +13,7 @@
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import org.eclipse.rmf.reqif10.AttributeDefinitionEnumeration;
import org.eclipse.rmf.reqif10.AttributeValueEnumeration;
@@ -150,5 +151,41 @@
public ImmutableSet<Operator> getSupportedOperators() {
return SUPPORTED_OPERATORS;
}
-
+
+
+
+ @Override
+ public String getFilterValue1AsString() {
+ return enumValuesAsString(getFilterValue1());
+ }
+
+ @Override
+ public String getFilterValue2AsString() {
+ return null;
+ }
+
+
+ private String enumValuesAsString(Collection<EnumValue> values){
+ StringBuilder sb = new StringBuilder("[");
+ for (Iterator<EnumValue> iterator = values.iterator(); iterator
+ .hasNext();) {
+ EnumValue enumValue = (EnumValue) iterator.next();
+ String label = enumValue.getLongName();
+ if (label == null){
+ label = enumValue.getDesc();
+ }
+ if (label == null){
+ label = "ID="+enumValue.getIdentifier();
+ }
+ sb.append(label);
+
+ if (iterator.hasNext()){
+ sb.append(", ");
+ }
+ }
+ sb.append("]");
+
+ return sb.toString();
+ }
+
}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/IFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/IFilter.java
index 3fa61f9..57d447e 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/IFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/IFilter.java
@@ -12,6 +12,7 @@
******************************************************************************/
package org.eclipse.rmf.reqif10.search.filter;
+import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.rmf.reqif10.SpecElementWithAttributes;
@@ -48,16 +49,22 @@
IS_NOT_SET("operator_is_not_set");
private String label;
+
private Operator(String label) {
this.label = label;
}
+
@Override
public String toString() {
return label;
}
public String toLocaleString(){
- return ResourceBundle.getBundle("plugin").getString(label);
+ try{
+ return ResourceBundle.getBundle("plugin").getString(label);
+ }catch (MissingResourceException e){
+ return label;
+ }
}
}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/SimpleCompoundFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/SimpleCompoundFilter.java
index b9e0d07..eea0ead 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/SimpleCompoundFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/SimpleCompoundFilter.java
@@ -12,6 +12,7 @@
package org.eclipse.rmf.reqif10.search.filter;
import java.util.Collections;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -100,5 +101,17 @@
}
-
+ public String toString(){
+ StringBuilder sb = new StringBuilder();
+ String op = orFilter ? " OR " : " AND ";
+ for (Iterator<IFilter> iterator = filters.iterator(); iterator.hasNext();) {
+ IFilter filter = (IFilter) iterator.next();
+
+ sb.append(filter.toString());
+ if (iterator.hasNext()){
+ sb.append(op + System.getProperty("line.separator"));
+ }
+ }
+ return sb.toString();
+ }
}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/XhtmlFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/XhtmlFilter.java
index f905d76..a246049 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/XhtmlFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/XhtmlFilter.java
@@ -73,7 +73,7 @@
simplifiedString = ProrXhtmlSimplifiedHelper.xhtmlToSimplifiedString(theValue);
}
- System.out.println(simplifiedString);
+ //System.out.println(simplifiedString);
return matchRegexp(simplifiedString);
}else{