felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r926990 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
Date Wed, 24 Mar 2010 09:32:37 GMT
Author: rickhall
Date: Wed Mar 24 09:32:37 2010
New Revision: 926990

URL: http://svn.apache.org/viewvc?rev=926990&view=rev
Log:
Fix some bugs in approximate operator. (FELIX-2039)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java?rev=926990&r1=926989&r2=926990&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
Wed Mar 24 09:32:37 2010
@@ -339,19 +339,19 @@ public class CapabilitySet
             return true;
         }
 
-        // The substring operator only works on string values, so if the
-        // lhs is not a string, then do an equality comparison using the
-        // original string containing wildcards.
-        if ((op == SimpleFilter.SUBSTRING) && !(lhs instanceof String))
-        {
-            op = SimpleFilter.EQ;
-            rhsUnknown = SimpleFilter.unparseSubstring((List<String>) rhsUnknown);
-        }
-
         // If the type is comparable, then we can just return the
         // result immediately.
         if (lhs instanceof Comparable)
         {
+            // The substring operator only works on string values, so if the
+            // lhs is not a string, then do an equality comparison using the
+            // original string containing wildcards.
+            if ((op == SimpleFilter.SUBSTRING) && !(lhs instanceof String))
+            {
+                op = SimpleFilter.EQ;
+                rhsUnknown = SimpleFilter.unparseSubstring((List<String>) rhsUnknown);
+            }
+
             Object rhs;
             if (op == SimpleFilter.SUBSTRING)
             {
@@ -435,6 +435,15 @@ public class CapabilitySet
             return false;
         }
 
+        // The substring operator only works on string values, so if the
+        // lhs is not a string, then do an equality comparison using the
+        // original string containing wildcards.
+        if ((op == SimpleFilter.SUBSTRING) && !(lhs instanceof String))
+        {
+            op = SimpleFilter.EQ;
+            rhsUnknown = SimpleFilter.unparseSubstring((List<String>) rhsUnknown);
+        }
+
         // Since we cannot identify the LHS type, then we can only perform
         // equality comparison.
         try
@@ -451,17 +460,8 @@ public class CapabilitySet
     {
         if (rhs instanceof String)
         {
-            String s = (String) rhs;
-            StringBuffer sb = new StringBuffer(s.length());
-            for (int i = 0; i < s.length(); i++)
-            {
-                if (!Character.isWhitespace(s.charAt(i)))
-                {
-                    sb.append(s.charAt(i));
-                }
-            }
-            s = sb.toString();
-            return s.equalsIgnoreCase((String) lhs);
+            return removeWhitespace((String) lhs)
+                .equalsIgnoreCase(removeWhitespace((String) rhs));
         }
         else if (rhs instanceof Character)
         {
@@ -471,6 +471,19 @@ public class CapabilitySet
         return lhs.equals(rhs);
     }
 
+    private static String removeWhitespace(String s)
+    {
+        StringBuffer sb = new StringBuffer(s.length());
+        for (int i = 0; i < s.length(); i++)
+        {
+            if (!Character.isWhitespace(s.charAt(i)))
+            {
+                sb.append(s.charAt(i));
+            }
+        }
+        return sb.toString();
+    }
+
     private static Object coerceType(Object lhs, String rhsString) throws Exception
     {
         // If the LHS expects a string, then we can just return



Mime
View raw message