*/
@Deprecated
@Override
- SchemaPath getPath();
+ default SchemaPath getPath() {
+ throw new UnsupportedOperationException("Enum pairs do not have SchemaPath");
+ }
/**
*
*/
@Deprecated
@Override
- QName getQName();
+ default QName getQName() {
+ throw new UnsupportedOperationException("Enum pairs do not have QName, only name");
+ }
/**
* The name to specify each assigned name of an enumeration type.
import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
private final List<UnknownSchemaNode> unknownSchemaNodes;
private final String description;
private final String reference;
- private final SchemaPath path;
private final Status status;
private final Integer value;
private final String name;
+ /**
+ * @deprecated Use the constructor without a SchemaPath
+ */
+ @Deprecated
public EnumPairImpl(final String name, final Integer value, final SchemaPath path, final String description,
final String reference, final Status status, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
- this.path = Preconditions.checkNotNull(path);
+ this(name, value, description, reference, status, unknownSchemaNodes);
+ }
+
+ public EnumPairImpl(final String name, final Integer value, final String description, final String reference,
+ final Status status, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
this.value = Preconditions.checkNotNull(value);
this.name = Preconditions.checkNotNull(name);
this.description = description;
this.unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodes);
}
- @Override
- public QName getQName() {
- return path.getLastComponent();
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return unknownSchemaNodes;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(path.getLastComponent());
- result = prime * result + Objects.hashCode(path);
result = prime * result + Objects.hashCode(unknownSchemaNodes);
result = prime * result + Objects.hashCode(name);
result = prime * result + Objects.hashCode(value);
return false;
}
- return Objects.equals(value, other.getValue()) && Objects.equals(getPath(), other.getPath()) &&
+ return Objects.equals(value, other.getValue()) &&
Objects.equals(unknownSchemaNodes, other.getUnknownSchemaNodes());
}
final UnknownSchemaNode UNKNOWN_SCHEMA_NODE= mock(UnknownSchemaNode.class);
final Collection<UnknownSchemaNode> collection = new ArrayList<>(1);
collection.add(UNKNOWN_SCHEMA_NODE);
- final EnumPairImpl enumPair = new EnumPairImpl("enum1", 1, SCHEMA_PATH, "description", "reference",
+ final EnumPairImpl enumPair = new EnumPairImpl("enum1", 1, "description", "reference",
Status.CURRENT, collection);
final InvalidLengthConstraintException invalidLengthConstraintException = new InvalidLengthConstraintException(
final UnknownSchemaNode UNKNOWN_SCHEMA_NODE= mock(UnknownSchemaNode.class);
final Collection<UnknownSchemaNode> collection = new ArrayList<>(1);
collection.add(UNKNOWN_SCHEMA_NODE);
- final EnumPairImpl enumPair1 = new EnumPairImpl("enum1", 1, SCHEMA_PATH, "description", "reference",
+ final EnumPairImpl enumPair1 = new EnumPairImpl("enum1", 1, "description", "reference",
Status.CURRENT, collection);
- final EnumPairImpl enumPair2 = new EnumPairImpl("enum", 1, SCHEMA_PATH, "description", "reference",
+ final EnumPairImpl enumPair2 = new EnumPairImpl("enum", 1, "description", "reference",
Status.CURRENT, collection);
final EnumerationTypeBuilder enumerationTypeBuilder = BaseTypes.enumerationTypeBuilder(SCHEMA_PATH);
enumerationTypeBuilder.addEnum(enumPair1);
import java.util.Collections;
import java.util.List;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DescriptionEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ReferenceEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.StatusEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ValueEffectiveStatementImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class EnumEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, EnumStatement> implements EnumPair {
-
- private static final Logger LOG = LoggerFactory.getLogger(EnumEffectiveStatementImpl.class);
-
private final String name;
- private final SchemaPath path;
private String description;
private String reference;
private Status status = Status.CURRENT;
private Integer value;
- private final QName maybeQNameArgument;
public EnumEffectiveStatementImpl(final StmtContext<String, EnumStatement, ?> ctx) {
super(ctx);
name = ctx.rawStatementArgument();
- SchemaPath parentPath = ctx.getParentContext().getSchemaPath().get();
- QNameModule moduleQName = parentPath.getLastComponent().getModule();
- QName maybeQNameArgumentInit = null;
- try {
- maybeQNameArgumentInit = QName.create(moduleQName, argument());
- } catch (IllegalArgumentException e) {
- String localName = Utils.replaceIllegalCharsForQName(argument());
- LOG.warn("{}. Enum argument '{}' has been replaced by '{}'.", e.getMessage(), argument(), localName, e);
- maybeQNameArgumentInit = QName.create(moduleQName, localName);
- }
- this.maybeQNameArgument = maybeQNameArgumentInit;
- this.path = parentPath.createChild(this.maybeQNameArgument);
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
return value;
}
- @Override
- public QName getQName() {
- return maybeQNameArgument;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return Collections.emptyList();
"Enum '%s' must have a value statement", p);
}
- p = new EnumPairImpl(p.getName(), newValue, p.getPath(), p.getDescription(), p.getReference(),
- p.getStatus(), p.getUnknownSchemaNodes());
+ p = new EnumPairImpl(p.getName(), newValue, p.getDescription(), p.getReference(), p.getStatus(),
+ p.getUnknownSchemaNodes());
}
if (highestValue == null || highestValue < p.getValue()) {
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.stmt;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.List;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-
-public class Bug4459Test {
-
- @Test
- public void test() throws IOException, URISyntaxException, SourceException, ReactorException {
- SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug4459");
- assertNotNull(schema);
-
- DataSchemaNode dataChildByName = schema.getDataChildByName("my-leaf");
- assertTrue(dataChildByName instanceof LeafSchemaNode);
- LeafSchemaNode myLeaf = (LeafSchemaNode) dataChildByName;
-
- TypeDefinition<?> type = myLeaf.getType();
- assertTrue(type instanceof EnumTypeDefinition);
- EnumTypeDefinition myEnum = (EnumTypeDefinition) type;
-
- QName expectedEnumQName = QName.create("foo", "1970-01-01", "QuestionMark-Ampersand-LeftParenthesis-RightParenthesis-QuestionMark-QuestionMark-Ampersand");
- List<EnumPair> values = myEnum.getValues();
- for (EnumPair enumPair : values) {
- if (enumPair.getName().equals("?-&-(-)-?-?-&")) {
- assertEquals(expectedEnumQName, enumPair.getQName());
- }
- }
- }
-}
assertFalse(enumSpecEff.equals("test"));
assertTrue(enumSpecEff.equals(enumSpecEff));
- assertEquals("zero", enumEff.getQName().getLocalName());
assertEquals("zero", enumEff.getName());
- assertNotNull(enumEff.getPath());
assertNotNull(enumEff.getUnknownSchemaNodes());
assertEquals("test enum", enumEff.getDescription());
assertEquals("test enum ref", enumEff.getReference());