From 5d72016e91fd7ec8ac526c66b4a24e373d1af74f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 16 Dec 2015 18:42:22 +0100 Subject: [PATCH] BUG-4793: Fix CaseShorthandImpl#isConfiguration() The shorthand case statement should defer to the statement which implied it for isConfiguration(). Since we're here, make this implementation-specific class package-private and final. Also eliminate all the fields which should be proxied by the statement. Finally use ImmutableSet/List for collections. Change-Id: Ie832c2d27f9e3dbdc485c68fcfa1205e45a4afbd Signed-off-by: Robert Varga --- .../rfc6020/effective/CaseShorthandImpl.java | 65 +++++++------------ 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseShorthandImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseShorthandImpl.java index a2b575133f..6f19976571 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseShorthandImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseShorthandImpl.java @@ -10,9 +10,8 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import java.util.Arrays; +import com.google.common.collect.ImmutableSet; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Set; @@ -30,34 +29,20 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.UsesNode; -public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { +final class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { private final DataSchemaNode caseShorthandNode; - private final QName qName; + private final ChoiceCaseNode original; private final SchemaPath path; - private final String description; - private final String reference; - private final Status status; private final boolean augmenting; - private final boolean addedByUses; - private final ConstraintDefinition constraints; - private final List unknownNodes; - private final ChoiceCaseNode original; - public CaseShorthandImpl(final DataSchemaNode caseShorthandNode) { - this.caseShorthandNode = caseShorthandNode; - this.qName = caseShorthandNode.getQName(); + CaseShorthandImpl(final DataSchemaNode caseShorthandNode) { + this.caseShorthandNode = Preconditions.checkNotNull(caseShorthandNode); this.path = Preconditions.checkNotNull(caseShorthandNode.getPath().getParent()); - this.description = caseShorthandNode.getDescription(); - this.reference = caseShorthandNode.getReference(); - this.status = caseShorthandNode.getStatus(); + this.original = getOriginalIfPresent(caseShorthandNode); + // We need to cache this, as it will be reset this.augmenting = caseShorthandNode.isAugmenting(); - this.addedByUses = caseShorthandNode.isAddedByUses(); - this.constraints = caseShorthandNode.getConstraints(); - this.unknownNodes = ImmutableList.copyOf(caseShorthandNode.getUnknownSchemaNodes()); - - this.original = getOriginalIfPresent(caseShorthandNode); } @Override @@ -67,22 +52,22 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { @Override public boolean isAddedByUses() { - return addedByUses; + return caseShorthandNode.isAddedByUses(); } @Override public boolean isConfiguration() { - return false; + return caseShorthandNode.isConfiguration(); } @Override public ConstraintDefinition getConstraints() { - return constraints; + return caseShorthandNode.getConstraints(); } @Override public QName getQName() { - return qName; + return caseShorthandNode.getQName(); } @Override @@ -92,42 +77,42 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { @Override public List getUnknownSchemaNodes() { - return unknownNodes; + return ImmutableList.of(); } @Override public String getDescription() { - return description; + return caseShorthandNode.getDescription(); } @Override public String getReference() { - return reference; + return caseShorthandNode.getReference(); } @Override public Status getStatus() { - return status; + return caseShorthandNode.getStatus(); } @Override public Set> getTypeDefinitions() { - return Collections.emptySet(); + return ImmutableSet.of(); } @Override public Collection getChildNodes() { - return Arrays.asList(caseShorthandNode); + return ImmutableList.of(caseShorthandNode); } @Override public Set getGroupings() { - return Collections.emptySet(); + return ImmutableSet.of(); } @Override public DataSchemaNode getDataChildByName(final QName name) { - if (qName.equals(name)) { + if (getQName().equals(name)) { return caseShorthandNode; } else { return null; @@ -136,7 +121,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { @Override public DataSchemaNode getDataChildByName(final String name) { - if (qName.getLocalName().equals(name)) { + if (getQName().getLocalName().equals(name)) { return caseShorthandNode; } else { return null; @@ -145,12 +130,12 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { @Override public Set getUses() { - return Collections.emptySet(); + return ImmutableSet.of(); } @Override public Set getAvailableAugmentations() { - return Collections.emptySet(); + return ImmutableSet.of(); } @Override @@ -162,7 +147,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + Objects.hashCode(qName); + result = prime * result + Objects.hashCode(getQName()); result = prime * result + Objects.hashCode(path); return result; } @@ -179,7 +164,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { return false; } CaseShorthandImpl other = (CaseShorthandImpl) obj; - return Objects.equals(qName, other.qName) && Objects.equals(path, other.path); + return Objects.equals(getQName(), other.getQName()) && Objects.equals(path, other.path); } @Override @@ -187,7 +172,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode { StringBuilder sb = new StringBuilder(CaseShorthandImpl.class.getSimpleName()); sb.append("["); sb.append("qname="); - sb.append(qName); + sb.append(getQName()); sb.append("]"); return sb.toString(); } -- 2.36.6