-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
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;
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<UnknownSchemaNode> unknownNodes;
- 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());
}
@Override
@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
@Override
public List<UnknownSchemaNode> 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<TypeDefinition<?>> getTypeDefinitions() {
- return Collections.emptySet();
+ return ImmutableSet.of();
}
@Override
public Collection<DataSchemaNode> getChildNodes() {
- return Arrays.asList(caseShorthandNode);
+ return ImmutableList.of(caseShorthandNode);
}
@Override
public Set<GroupingDefinition> 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;
@Override
public DataSchemaNode getDataChildByName(final String name) {
- if (qName.getLocalName().equals(name)) {
+ if (getQName().getLocalName().equals(name)) {
return caseShorthandNode;
} else {
return null;
@Override
public Set<UsesNode> getUses() {
- return Collections.emptySet();
+ return ImmutableSet.of();
}
@Override
public Set<AugmentationSchema> getAvailableAugmentations() {
- return Collections.emptySet();
+ return ImmutableSet.of();
}
@Override
public Optional<? extends SchemaNode> getOriginal() {
- return Optional.absent();
+ return Optional.fromNullable(original);
}
@Override
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;
}
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
StringBuilder sb = new StringBuilder(CaseShorthandImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=");
- sb.append(qName);
+ sb.append(getQName());
sb.append("]");
return sb.toString();
}
+
+ private static ChoiceCaseNode getOriginalIfPresent(final SchemaNode caseShorthandNode) {
+ if (caseShorthandNode instanceof DerivableSchemaNode) {
+ final Optional<? extends SchemaNode> original = ((DerivableSchemaNode) caseShorthandNode).getOriginal();
+ if (original.isPresent()) {
+ return new CaseShorthandImpl((DataSchemaNode) original.get());
+ }
+ }
+ return null;
+ }
}