Fix some bugs in approximate operator. (FELIX-2039)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@926990 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
index 910cb01..626f6b1 100644
--- a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
+++ b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
@@ -339,19 +339,19 @@
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 @@
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 @@
{
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 @@
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