Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ModuleCapability/ModuleRequirement hashcode/equals according to API #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.function.Function;

import org.apache.felix.framework.capabilityset.SimpleFilter;
import org.apache.felix.framework.util.Util;
import org.apache.felix.framework.util.manifestparser.ManifestParser;
import org.osgi.framework.Constants;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;

public class BundleCapabilityImpl implements BundleCapability
{
Expand All @@ -45,6 +46,7 @@ public class BundleCapabilityImpl implements BundleCapability
private final Map<String, Object> m_attrs;
private final List<String> m_uses;
private final Set<String> m_mandatory;
private transient int hashCode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the formatting may use the same number of tabs as before


public static BundleCapabilityImpl createFrom(BundleCapabilityImpl capability, Function<Object, Object> cache)
{
Expand Down Expand Up @@ -114,27 +116,32 @@ public BundleCapabilityImpl(BundleRevision revision, String namespace,
m_mandatory = mandatory;
}

public BundleRevision getResource()
@Override
public BundleRevision getResource()
{
return m_revision;
}

public BundleRevision getRevision()
@Override
public BundleRevision getRevision()
{
return m_revision;
}

public String getNamespace()
@Override
public String getNamespace()
{
return m_namespace;
}

public Map<String, String> getDirectives()
@Override
public Map<String, String> getDirectives()
{
return m_dirs;
}

public Map<String, Object> getAttributes()
@Override
public Map<String, Object> getAttributes()
{
return m_attrs;
}
Expand All @@ -158,4 +165,26 @@ public String toString()
}
return "[" + m_revision + "] " + m_namespace + "; " + m_attrs;
}

@Override
public int hashCode() {
if (hashCode != 0) {
return hashCode;
}
return hashCode = Objects.hash(m_namespace, m_dirs, m_attrs, m_revision);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof Capability) {
Capability other = (Capability) obj;
return Objects.equals(m_namespace, other.getNamespace()) && Objects.equals(m_dirs, other.getDirectives())
&& Objects.equals(m_attrs, other.getAttributes())
&& Objects.equals(m_revision, other.getResource());
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

import org.apache.felix.framework.capabilityset.CapabilitySet;
Expand All @@ -30,6 +31,7 @@
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRequirement;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Requirement;

public class BundleRequirementImpl implements BundleRequirement
{
Expand All @@ -39,6 +41,7 @@ public class BundleRequirementImpl implements BundleRequirement
private final boolean m_optional;
private final Map<String, String> m_dirs;
private final Map<String, Object> m_attrs;
private transient int hashCode;

public static BundleRequirementImpl createFrom(BundleRequirementImpl requirement, Function<Object, Object> cache)
{
Expand Down Expand Up @@ -87,32 +90,38 @@ public BundleRequirementImpl(
this(revision, namespace, dirs, Collections.emptyMap(), SimpleFilter.convert(attrs));
}

public String getNamespace()
@Override
public String getNamespace()
{
return m_namespace;
}

public Map<String, String> getDirectives()
@Override
public Map<String, String> getDirectives()
{
return m_dirs;
}

public Map<String, Object> getAttributes()
@Override
public Map<String, Object> getAttributes()
{
return m_attrs;
}

public BundleRevision getResource()
@Override
public BundleRevision getResource()
{
return m_revision;
}

public BundleRevision getRevision()
@Override
public BundleRevision getRevision()
{
return m_revision;
}

public boolean matches(BundleCapability cap)
@Override
public boolean matches(BundleCapability cap)
{
return CapabilitySet.matches(cap, getFilter());
}
Expand All @@ -132,4 +141,26 @@ public String toString()
{
return "[" + m_revision + "] " + m_namespace + "; " + getFilter().toString();
}

@Override
public int hashCode() {
if (hashCode != 0) {
return hashCode;
}
return hashCode = Objects.hash(m_namespace, m_dirs, m_attrs, m_revision);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof Requirement) {
Requirement other = (Requirement) obj;
return Objects.equals(m_namespace, other.getNamespace()) && Objects.equals(m_dirs, other.getDirectives())
&& Objects.equals(m_attrs, other.getAttributes())
&& Objects.equals(m_revision, other.getResource());
}
return false;
}
}