You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2018/04/16 14:24:54 UTC
[sling-whiteboard] branch master updated: Allow null for attributes
or requirements. Throw ISE if namespace is null
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new 1712660 Allow null for attributes or requirements. Throw ISE if namespace is null
1712660 is described below
commit 1712660caf69aeab56e58d4f209d188594ebc7fd
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/featuremodel/feature/src/main/java/org/apache/sling/feature/AbstractCapabilityRequirement.java b/featuremodel/feature/src/main/java/org/apache/sling/feature/AbstractCapabilityRequirement.java
index 200cb92..8a4982f 100644
--- a/featuremodel/feature/src/main/java/org/apache/sling/feature/AbstractCapabilityRequirement.java
+++ b/featuremodel/feature/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
cziegeler@apache.org.