diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleCapability.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleCapability.java index 7cbb36009a7..bfbcbc1576b 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleCapability.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleCapability.java @@ -16,8 +16,10 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.osgi.framework.namespace.NativeNamespace; import org.osgi.framework.wiring.BundleCapability; +import org.osgi.resource.Capability; /** * An implementation of {@link BundleCapability}. @@ -30,6 +32,7 @@ public final class ModuleCapability implements BundleCapability { private final Map attributes; private final Map transientAttrs; private final ModuleRevision revision; + private transient int hashCode; ModuleCapability(String namespace, Map directives, Map attributes, ModuleRevision revision) { @@ -93,4 +96,26 @@ public ModuleRevision getResource() { public String toString() { return namespace + ModuleContainer.toString(attributes, false) + ModuleContainer.toString(directives, true); } + + @Override + public int hashCode() { + if (hashCode != 0) { + return hashCode; + } + return hashCode = Objects.hash(namespace, directives, attributes, revision); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Capability) { + Capability other = (Capability) obj; + return Objects.equals(namespace, other.getNamespace()) && Objects.equals(directives, other.getDirectives()) + && Objects.equals(attributes, other.getAttributes()) + && Objects.equals(revision, other.getResource()); + } + return false; + } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRequirement.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRequirement.java index 37151ef8f55..48b7e1516ac 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRequirement.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRequirement.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.osgi.internal.container.Capabilities; import org.eclipse.osgi.internal.framework.FilterImpl; import org.osgi.framework.InvalidSyntaxException; @@ -24,6 +25,7 @@ import org.osgi.framework.wiring.BundleCapability; import org.osgi.framework.wiring.BundleRequirement; import org.osgi.resource.Namespace; +import org.osgi.resource.Requirement; /** * An implementation of {@link BundleRequirement}. This requirement implements @@ -38,6 +40,7 @@ public class ModuleRequirement implements BundleRequirement { private final Map directives; private final Map attributes; private final ModuleRevision revision; + private transient int hashCode; ModuleRequirement(String namespace, Map directives, Map attributes, ModuleRevision revision) { @@ -153,4 +156,26 @@ ModuleRequirement getOriginal() { } } + @Override + public int hashCode() { + if (hashCode != 0) { + return hashCode; + } + return hashCode = Objects.hash(namespace, directives, attributes, revision); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Requirement) { + Requirement other = (Requirement) obj; + return Objects.equals(namespace, other.getNamespace()) && Objects.equals(directives, other.getDirectives()) + && Objects.equals(attributes, other.getAttributes()) + && Objects.equals(revision, other.getResource()); + } + return false; + } + }