You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/04/27 09:51:36 UTC
[sling-org-apache-sling-feature] 16/22: Allow null for attributes
or requirements. Throw ISE if namespace is null
This is an automated email from the ASF dual-hosted git repository.
davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature.git
commit f2a36820d626b654dd68df113903710c0cb0e796
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Apr 16 16:24:47 2018 +0200
Allow null for attributes or requirements. Throw ISE if namespace is null
---
.../feature/AbstractCapabilityRequirement.java | 56 ++++++++++++++--------
1 file changed, 37 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/AbstractCapabilityRequirement.java b/src/main/java/org/apache/sling/feature/AbstractCapabilityRequirement.java
index 200cb92..8a4982f 100644
--- a/src/main/java/org/apache/sling/feature/AbstractCapabilityRequirement.java
+++ b/src/main/java/org/apache/sling/feature/AbstractCapabilityRequirement.java
@@ -23,30 +23,57 @@ import java.util.Map;
import org.osgi.resource.Resource;
abstract class AbstractCapabilityRequirement {
- private final Resource resource;
+
+ /** The namespace. Required. */
private final String namespace;
+
+ /** Optional resource. */
+ private final Resource resource;
+
+ /** Optional attributes. Never null. */
private final Map<String, Object> attributes;
+
+ /** Optional attributes. Never null. */
private final Map<String, String> directives;
- AbstractCapabilityRequirement(Resource res, String ns, Map<String, Object> attrs, Map<String, String> dirs) {
+ AbstractCapabilityRequirement(final Resource res, final String ns, final Map<String, Object> attrs, final Map<String, String> dirs) {
+ if ( ns == null ) {
+ throw new IllegalArgumentException("Namespace must not be null.");
+ }
resource = res;
namespace = ns;
- attributes = Collections.unmodifiableMap(new HashMap<>(attrs));
- directives = Collections.unmodifiableMap(new HashMap<>(dirs));
+ attributes = attrs == null ? Collections.emptyMap() : Collections.unmodifiableMap(new HashMap<>(attrs));
+ directives = dirs == null ? Collections.emptyMap() : Collections.unmodifiableMap(new HashMap<>(dirs));
}
+ /**
+ * Return the namespace.
+ * @return The namespace. This is never @{code null}.
+ */
public String getNamespace() {
return namespace;
}
+ /**
+ * Return the attributes.
+ * @return The attributes, might be empty.
+ */
public Map<String, Object> getAttributes() {
return attributes;
}
+ /**
+ * Return the directives.
+ * @return The directives, might be empty.
+ */
public Map<String, String> getDirectives() {
return directives;
}
+ /**
+ * Return the resource.
+ * @return The resource or @{code null}.
+ */
public Resource getResource() {
return resource;
}
@@ -55,9 +82,9 @@ abstract class AbstractCapabilityRequirement {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
- result = prime * result + ((directives == null) ? 0 : directives.hashCode());
- result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
+ result = prime * result + attributes.hashCode();
+ result = prime * result + directives.hashCode();
+ result = prime * result + namespace.hashCode();
return result;
}
@@ -70,20 +97,11 @@ abstract class AbstractCapabilityRequirement {
if (getClass() != obj.getClass())
return false;
AbstractCapabilityRequirement other = (AbstractCapabilityRequirement) obj;
- if (attributes == null) {
- if (other.attributes != null)
- return false;
- } else if (!attributes.equals(other.attributes))
+ if (!namespace.equals(other.namespace))
return false;
- if (directives == null) {
- if (other.directives != null)
- return false;
- } else if (!directives.equals(other.directives))
+ if (!attributes.equals(other.attributes))
return false;
- if (namespace == null) {
- if (other.namespace != null)
- return false;
- } else if (!namespace.equals(other.namespace))
+ if (!directives.equals(other.directives))
return false;
return true;
}
--
To stop receiving notification emails like this one, please contact
davidb@apache.org.