HibernateUserAdministrationTest now based on the component mechanism.
[utils] / system / general / src / main / java / org / wamblee / system / core / DefaultProvidedInterface.java
index 90c230dcc9bf23493fcba2dd629f14c7c880e665..10b8f6184cbbf5c5c50ce192720b8037b7132138 100644 (file)
  */ 
 package org.wamblee.system.core;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
 
 /**
  * Default implementation of a service descriptor.
@@ -36,7 +40,7 @@ public class DefaultProvidedInterface implements ProvidedInterface {
                this(aName, new Class[] { aInterface }); 
        }
        
-       public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
+       public DefaultProvidedInterface(String aName, Class[] aInterfaces) { 
                _name = aName; 
                _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
                _uniqueId = null; 
@@ -77,4 +81,32 @@ public class DefaultProvidedInterface implements ProvidedInterface {
                }
                return buf.toString();
        }
+       
+       @Override
+       public boolean equals(Object aObj) {
+           if ( !(aObj instanceof DefaultProvidedInterface)) { 
+               return false; 
+           }
+           DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj; 
+           return getEqualsRepresentation().equals(provided.getEqualsRepresentation());
+       }
+       
+       @Override
+       public int hashCode() {
+           return getEqualsRepresentation().hashCode();
+       }
+       
+       
+       private String getEqualsRepresentation() { 
+           List<String> result = new ArrayList<String>(); 
+           for (Class cls: _interfaces) { 
+               result.add(cls.getName());
+           }
+           Collections.sort(result); 
+           String value = ""; 
+           for (String str: result) { 
+               value += ":" + str; 
+           }
+           return value; 
+       }
 }