Author: rickhall
Date: Fri Jan 15 14:46:00 2010
New Revision: 899647

URL: http://svn.apache.org/viewvc?rev=899647&view=rev
Log:
Attribute value is not always comparable.

Modified:
    
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java

Modified: 
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java?rev=899647&r1=899646&r2=899647&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java
 (original)
+++ 
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/CapabilitySet.java
 Fri Jan 15 14:46:00 2010
@@ -24,19 +24,20 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
 public class CapabilitySet
 {
-    private final Map<String, Map<Comparable, Set<Capability>>> m_indices =
-        new HashMap<String, Map<Comparable, Set<Capability>>>();
+    private final Map<String, Map<Object, Set<Capability>>> m_indices =
+        new HashMap<String, Map<Object, Set<Capability>>>();
     private final Set<Capability> m_capList = new HashSet<Capability>();
 
     public CapabilitySet(List<String> indexProps)
     {
         for (int i = 0; (indexProps != null) && (i < indexProps.size()); i++)
         {
-            m_indices.put(indexProps.get(i), new HashMap<Comparable, 
Set<Capability>>());
+            m_indices.put(indexProps.get(i), new HashMap<Object, 
Set<Capability>>());
         }
     }
 
@@ -45,19 +46,17 @@
         m_capList.add(cap);
 
         // Index capability.
-        for (Iterator<Map.Entry<String, Map<Comparable, Set<Capability>>>>
-            it = m_indices.entrySet().iterator(); it.hasNext(); )
+        for (Entry<String, Map<Object, Set<Capability>>> entry : 
m_indices.entrySet())
         {
-            Map.Entry<String, Map<Comparable, Set<Capability>>> entry = 
it.next();
             if (cap.getAttribute(entry.getKey()) != null)
             {
-                Map<Comparable, Set<Capability>> index = entry.getValue();
+                Map<Object, Set<Capability>> index = entry.getValue();
                 Set<Capability> caps = index.get(
-                    (Comparable) cap.getAttribute(entry.getKey()).getValue());
+                    cap.getAttribute(entry.getKey()).getValue());
                 if (caps == null)
                 {
                     caps = new HashSet<Capability>();
-                    index.put((Comparable) 
cap.getAttribute(entry.getKey()).getValue(), caps);
+                    index.put(cap.getAttribute(entry.getKey()).getValue(), 
caps);
                 }
                 caps.add(cap);
             }
@@ -70,13 +69,13 @@
     {
         if (m_capList.remove(cap))
         {
-            for (Iterator<Map.Entry<String, Map<Comparable, Set<Capability>>>>
+            for (Iterator<Map.Entry<String, Map<Object, Set<Capability>>>>
                 it = m_indices.entrySet().iterator(); it.hasNext(); )
             {
-                Map.Entry<String, Map<Comparable, Set<Capability>>> entry = 
it.next();
+                Map.Entry<String, Map<Object, Set<Capability>>> entry = 
it.next();
                 if (cap.getAttribute(entry.getKey()) != null)
                 {
-                    Map<Comparable, Set<Capability>> index = entry.getValue();
+                    Map<Object, Set<Capability>> index = entry.getValue();
                     Set<Capability> caps = 
index.get(cap.getAttribute(entry.getKey()).getValue());
                     caps.remove(cap);
                     if (caps.size() == 0)
@@ -138,10 +137,10 @@
         }
         else
         {
-            Map<Comparable, Set<Capability>> index = 
m_indices.get(sf.getName());
+            Map<Object, Set<Capability>> index = m_indices.get(sf.getName());
             if ((sf.getOperation() == SimpleFilter.EQ) && (index != null))
             {
-                Set<Capability> existingCaps = index.get((Comparable) 
sf.getValue());
+                Set<Capability> existingCaps = index.get(sf.getValue());
                 if (existingCaps != null)
                 {
                     matches.addAll(existingCaps);
@@ -213,31 +212,11 @@
         {
             matched = false;
             Attribute attr = cap.getAttribute(sf.getName());
-            Comparable value = (Comparable)
-                ((attr == null) ? null : 
cap.getAttribute(sf.getName()).getValue());
-            if (value != null)
+            if (attr != null)
             {
-                switch (sf.getOperation())
-                {
-                    case SimpleFilter.EQ:
-                        if (value.compareTo(coerceType(value, (String) 
sf.getValue())) == 0)
-                        {
-                            matched = true;
-                        }
-                        break;
-                    case SimpleFilter.LTE:
-                        if (value.compareTo(coerceType(value, (String) 
sf.getValue())) <= 0)
-                        {
-                            matched = true;
-                        }
-                        break;
-                    case SimpleFilter.GTE:
-                        if (value.compareTo(coerceType(value, (String) 
sf.getValue())) >= 0)
-                        {
-                            matched = true;
-                        }
-                        break;
-                }
+                Object lhs = attr.getValue();
+                Object rhs = coerceType(lhs, (String) sf.getValue());
+                matched = compare(lhs, rhs, sf.getOperation());
             }
         }
 


Reply via email to