[utils][bundlerepository] remove support for '<' and '>' in the filter, but transform the filters when building the requirement

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@927721 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/RequirementImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/RequirementImpl.java
index d03109c..6988a14 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/RequirementImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/RequirementImpl.java
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.bundlerepository.impl;
 
+import java.util.regex.Pattern;
+
 import org.apache.felix.bundlerepository.Capability;
 import org.apache.felix.bundlerepository.Requirement;
 import org.apache.felix.utils.filter.FilterImpl;
@@ -25,6 +27,10 @@
 
 public class RequirementImpl implements Requirement
 {
+    private static final Pattern REMOVE_LT = Pattern.compile("\\(([^<>=~()]*)<([^*=]([^\\\\\\*\\(\\)]|\\\\|\\*|\\(|\\))*)\\)");
+    private static final Pattern REMOVE_GT = Pattern.compile("\\(([^<>=~()]*)>([^*=]([^\\\\\\*\\(\\)]|\\\\|\\*|\\(|\\))*)\\)");
+    private static final Pattern REMOVE_NV = Pattern.compile("\\(version>=0.0.0\\)");
+
     private String m_name = null;
     private boolean m_extend = false;
     private boolean m_multiple = false;
@@ -62,7 +68,10 @@
     {
         try
         {
-            m_filter = FilterImpl.newInstance(filter, true);
+            String nf = REMOVE_LT.matcher(filter).replaceAll("(!($1>=$2))");
+            nf = REMOVE_GT.matcher(nf).replaceAll("(!($1<=$2))");
+            nf = REMOVE_NV.matcher(nf).replaceAll("");
+            m_filter = FilterImpl.newInstance(nf, true);
         }
         catch (InvalidSyntaxException e)
         {
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java
index ab4a5b5..3953fd3 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java
@@ -52,4 +52,14 @@
 
         assertEquals(xml, xml2);
     }
+
+    public void testRequirementFilter() throws Exception
+    {
+        RequirementImpl r = new RequirementImpl();
+        r.setFilter("(&(package=foo.bar)(version>=0.0.0)(version<3.0.0))");
+        assertEquals("(&(package=foo.bar)(!(version>=3.0.0)))", r.getFilter());
+
+        r.setFilter("(&(package=javax.transaction)(partial=true)(mandatory:<*partial))");
+        assertEquals("(&(package=javax.transaction)(partial=true)(mandatory:<*partial))", r.getFilter());
+    }
 }
diff --git a/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java b/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java
index 6b7b63c..fdf158d 100644
--- a/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java
+++ b/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java
@@ -42,17 +42,15 @@
     /* filter operators */
     private static final int            EQUAL       = 1;
     private static final int            APPROX      = 2;
-    private static final int            GTEQ        = 3;
-    private static final int            LTEQ        = 4;
-    private static final int            GT          = 5;
-    private static final int            LT          = 6;
-    private static final int            PRESENT     = 7;
-    private static final int            SUBSTRING   = 8;
-    private static final int            AND         = 9;
-    private static final int            OR          = 10;
-    private static final int            NOT         = 11;
-    private static final int            SUBSET      = 12;
-    private static final int            SUPERSET    = 13;
+    private static final int            GREATER     = 3;
+    private static final int            LESS        = 4;
+    private static final int            PRESENT     = 5;
+    private static final int            SUBSTRING   = 6;
+    private static final int            AND         = 7;
+    private static final int            OR          = 8;
+    private static final int            NOT         = 9;
+    private static final int            SUBSET      = 10;
+    private static final int            SUPERSET    = 11;
 
     /** filter operation */
     private final int                   op;
@@ -265,34 +263,20 @@
 
                 break;
             }
-            case GTEQ: {
+            case GREATER: {
                 sb.append(attr);
                 sb.append(">=");
                 sb.append(encodeValue((String) value));
 
                 break;
             }
-            case LTEQ: {
+            case LESS: {
                 sb.append(attr);
                 sb.append("<=");
                 sb.append(encodeValue((String) value));
 
                 break;
             }
-            case GT: {
-                sb.append(attr);
-                sb.append(">");
-                sb.append(encodeValue((String) value));
-
-                break;
-            }
-            case LT: {
-                sb.append(attr);
-                sb.append("<");
-                sb.append(encodeValue((String) value));
-
-                break;
-            }
             case APPROX : {
                 sb.append(attr);
                 sb.append("~=");
@@ -405,10 +389,8 @@
 
             case SUBSTRING :
             case EQUAL :
-            case GTEQ:
-            case LTEQ:
-            case GT:
-            case LT:
+            case GREATER:
+            case LESS:
             case APPROX :
             case SUBSET :
             case SUPERSET : {
@@ -461,10 +443,8 @@
 
             case SUBSTRING :
             case EQUAL :
-            case GTEQ:
-            case LTEQ:
-            case GT:
-            case LT:
+            case GREATER:
+            case LESS:
             case APPROX :
             case SUBSET :
             case SUPERSET : {
@@ -597,18 +577,12 @@
                     case EQUAL : {
                         return ((Version) value1).compareTo(converted) == 0;
                     }
-                    case GTEQ: {
+                    case GREATER: {
                         return ((Version) value1).compareTo(converted) >= 0;
                     }
-                    case LTEQ: {
+                    case LESS: {
                         return ((Version) value1).compareTo(converted) <= 0;
                     }
-                    case GT: {
-                        return ((Version) value1).compareTo(converted) > 0;
-                    }
-                    case LT: {
-                        return ((Version) value1).compareTo(converted) < 0;
-                    }
                 }
             } else {
                 return compare_Comparable(operation, (Version) value1, value2);
@@ -834,18 +808,12 @@
 
                 return string.equalsIgnoreCase(string2);
             }
-            case GTEQ: {
+            case GREATER: {
                 return string.compareTo((String) value2) >= 0;
             }
-            case LTEQ: {
+            case LESS: {
                 return string.compareTo((String) value2) <= 0;
             }
-            case GT: {
-                return string.compareTo((String) value2) > 0;
-            }
-            case LT: {
-                return string.compareTo((String) value2) < 0;
-            }
         }
         return false;
     }
@@ -866,18 +834,12 @@
             case EQUAL : {
                 return intval == intval2;
             }
-            case GTEQ: {
+            case GREATER: {
                 return intval >= intval2;
             }
-            case LTEQ: {
+            case LESS: {
                 return intval <= intval2;
             }
-            case GT: {
-                return intval > intval2;
-            }
-            case LT: {
-                return intval < intval2;
-            }
         }
         return false;
     }
@@ -899,18 +861,12 @@
             case EQUAL : {
                 return longval == longval2;
             }
-            case GTEQ: {
+            case GREATER: {
                 return longval >= longval2;
             }
-            case LTEQ: {
+            case LESS: {
                 return longval <= longval2;
             }
-            case GT: {
-                return longval > longval2;
-            }
-            case LT: {
-                return longval < longval2;
-            }
         }
         return false;
     }
@@ -932,18 +888,12 @@
             case EQUAL : {
                 return byteval == byteval2;
             }
-            case GTEQ: {
+            case GREATER: {
                 return byteval >= byteval2;
             }
-            case LTEQ: {
+            case LESS: {
                 return byteval <= byteval2;
             }
-            case GT: {
-                return byteval > byteval2;
-            }
-            case LT: {
-                return byteval < byteval2;
-            }
         }
         return false;
     }
@@ -966,18 +916,12 @@
             case EQUAL : {
                 return shortval == shortval2;
             }
-            case GTEQ: {
+            case GREATER: {
                 return shortval >= shortval2;
             }
-            case LTEQ: {
+            case LESS: {
                 return shortval <= shortval2;
             }
-            case GT: {
-                return shortval > shortval2;
-            }
-            case LT: {
-                return shortval < shortval2;
-            }
         }
         return false;
     }
@@ -1006,18 +950,12 @@
                         || (Character.toLowerCase(charval) == Character
                                 .toLowerCase(charval2));
             }
-            case GTEQ: {
+            case GREATER: {
                 return charval >= charval2;
             }
-            case LTEQ: {
+            case LESS: {
                 return charval <= charval2;
             }
-            case GT: {
-                return charval > charval2;
-            }
-            case LT: {
-                return charval < charval2;
-            }
         }
         return false;
     }
@@ -1032,8 +970,8 @@
         switch (operation) {
             case APPROX :
             case EQUAL :
-            case GTEQ:
-            case LTEQ: {
+            case GREATER:
+            case LESS: {
                 return boolval == boolval2;
             }
         }
@@ -1058,18 +996,12 @@
             case EQUAL : {
                 return Float.compare(floatval, floatval2) == 0;
             }
-            case GTEQ: {
+            case GREATER: {
                 return Float.compare(floatval, floatval2) >= 0;
             }
-            case LTEQ: {
+            case LESS: {
                 return Float.compare(floatval, floatval2) <= 0;
             }
-            case GT: {
-                return Float.compare(floatval, floatval2) > 0;
-            }
-            case LT: {
-                return Float.compare(floatval, floatval2) < 0;
-            }
         }
         return false;
     }
@@ -1092,18 +1024,12 @@
             case EQUAL : {
                 return Double.compare(doubleval, doubleval2) == 0;
             }
-            case GTEQ: {
+            case GREATER: {
                 return Double.compare(doubleval, doubleval2) >= 0;
             }
-            case LTEQ: {
+            case LESS: {
                 return Double.compare(doubleval, doubleval2) <= 0;
             }
-            case GT: {
-                return Double.compare(doubleval, doubleval2) > 0;
-            }
-            case LT: {
-                return Double.compare(doubleval, doubleval2) < 0;
-            }
         }
         return false;
     }
@@ -1144,18 +1070,12 @@
             case EQUAL : {
                 return value1.compareTo(value2) == 0;
             }
-            case GTEQ: {
+            case GREATER: {
                 return value1.compareTo(value2) >= 0;
             }
-            case LTEQ: {
+            case LESS: {
                 return value1.compareTo(value2) <= 0;
             }
-            case GT: {
-                return value1.compareTo(value2) > 0;
-            }
-            case LT: {
-                return value1.compareTo(value2) < 0;
-            }
         }
         return false;
     }
@@ -1192,8 +1112,8 @@
         switch (operation) {
             case APPROX :
             case EQUAL :
-            case GTEQ:
-            case LTEQ: {
+            case GREATER:
+            case LESS: {
                 return value1.equals(value2);
             }
         }
@@ -1392,29 +1312,23 @@
                 case '>' : {
                     if (filterChars[pos + 1] == '=') {
                         pos += 2;
-                        return new FilterImpl(FilterImpl.GTEQ, attr,
+                        return new FilterImpl(FilterImpl.GREATER, attr,
                                 parse_value());
                     }
-                    else {
-                        pos += 1;
-                        return new FilterImpl(FilterImpl.GT, attr,
-                                parse_value());
-                    }
+                    break;
                 }
                 case '<' : {
                     if (filterChars[pos + 1] == '=') {
                         pos += 2;
-                        return new FilterImpl(FilterImpl.LTEQ, attr,
+                        return new FilterImpl(FilterImpl.LESS, attr,
                                 parse_value());
-                    } else if (filterChars[pos + 1] == '*') {
+                    }
+                    if (filterChars[pos + 1] == '*') {
                         pos += 2;
                         return new FilterImpl(FilterImpl.SUBSET, attr,
                                 parse_value());
-                    } else {
-                        pos += 1;
-                        return new FilterImpl(FilterImpl.LT, attr,
-                                parse_value());
                     }
+                    break;
                 }
                 case '=' : {
                     if (filterChars[pos + 1] == '*') {