</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
</dependency>
</dependencies>
- <!--
- Maven Site Configuration
-
- The following configuration is necessary for maven-site-plugin to
- correctly identify the correct deployment path for OpenDaylight Maven
- sites.
- -->
- <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
-
- <distributionManagement>
- <site>
- <id>opendaylight-site</id>
- <url>${nexus.site.url}/${project.artifactId}/</url>
- </site>
- </distributionManagement>
+ <!--
+ Maven Site Configuration
+
+ The following configuration is necessary for maven-site-plugin to
+ correctly identify the correct deployment path for OpenDaylight Maven
+ sites.
+ -->
+ <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+
+ <distributionManagement>
+ <site>
+ <id>opendaylight-site</id>
+ <url>${nexus.site.url}/${project.artifactId}/</url>
+ </site>
+ </distributionManagement>
</project>
// For up to two characters, this is very fast
private static final CharMatcher X_MATCHER = CharMatcher.anyOf("xX");
- private static final String INCORRECT_LEXICAL_REPRESENTATION = "Incorrect lexical representation of integer value: %s."
- + "\nAn integer value can be defined as: "
- + "\n - a decimal number,"
- + "\n - a hexadecimal number (prefix 0x)," + "%n - an octal number (prefix 0)."
- + "\nSigned values are allowed. Spaces between digits are NOT allowed.";
-
+ private static final String INCORRECT_LEXICAL_REPRESENTATION =
+ "Incorrect lexical representation of integer value: %s."
+ + "\nAn integer value can be defined as: "
+ + "\n - a decimal number,"
+ + "\n - a hexadecimal number (prefix 0x)," + "%n - an octal number (prefix 0)."
+ + "\nSigned values are allowed. Spaces between digits are NOT allowed.";
private final List<Range<N>> rangeConstraints;
return deserialized;
}
+ /**
+ * Deserializes value from supplied string representation is supplied radix. See
+ * {@link Integer#parseInt(String, int)} for in-depth description about string and radix relationship.
+ *
+ * @param stringRepresentation String representation
+ * @param radix numeric base.
+ * @return Deserialized value.
+ */
+ abstract N deserialize(String stringRepresentation, int radix);
+
+ abstract N convertValue(Number value);
private void validate(final N value) {
if (rangeConstraints.isEmpty()) {
throw new IllegalArgumentException("Value '" + value + "' is not in required range " + rangeConstraints);
}
- /**
- * Deserializes value from supplied string representation
- * is supplied radix.
- *
- * See {@link Integer#parseInt(String, int)} for in-depth
- * description about string and radix relationship.
- *
- * @param stringRepresentation String representation
- * @param radix numeric base.
- * @return Deserialized value.
- */
- abstract N deserialize(String stringRepresentation, int radix);
-
- abstract N convertValue(Number value);
-
-
protected static List<RangeConstraint> extractRange(final IntegerTypeDefinition type) {
if (type == null) {
return Collections.emptyList();
}
}
- public void validate(final String s) {
- Preconditions.checkArgument(pattern.matcher(s).matches(), errorMessage, s);
+ public void validate(final String str) {
+ Preconditions.checkArgument(pattern.matcher(str).matches(), errorMessage, str);
}
-
}
\ No newline at end of file
@Override
public BigDecimal deserialize(final String stringRepresentation) {
- Preconditions.checkArgument( stringRepresentation != null , "Input cannot be null" );
+ Preconditions.checkArgument(stringRepresentation != null, "Input cannot be null");
// FIXME: run value validation
return new BigDecimal(stringRepresentation);
}
public DeserializationException() {
}
- public DeserializationException(String message) {
+ public DeserializationException(final String message) {
super(message);
}
- public DeserializationException(Throwable cause) {
+ public DeserializationException(final Throwable cause) {
super(cause);
}
- public DeserializationException(String message, Throwable cause) {
+ public DeserializationException(final String message, final Throwable cause) {
super(message, cause);
}
- public DeserializationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ public DeserializationException(final String message, final Throwable cause, final boolean enableSuppression,
+ final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
@Override
- public String deserialize(final String s) {
+ public String deserialize(final String stringRepresentation) {
if (values == null) {
- return s;
+ return stringRepresentation;
}
// Lookup the serialized string in the values. Returned string is the interned instance, which we want
// to use as the result.
- final String result = values.get(s);
+ final String result = values.get(stringRepresentation);
Preconditions.checkArgument(result != null, "Invalid value '%s' for enum type. Allowed values are: %s",
- s, values.keySet());
+ stringRepresentation, values.keySet());
return result;
}
import org.opendaylight.yangtools.yang.data.api.codec.Int16Codec;
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-final class Int16StringCodec extends AbstractIntegerStringCodec<Short, IntegerTypeDefinition> implements Int16Codec<String> {
+final class Int16StringCodec extends AbstractIntegerStringCodec<Short, IntegerTypeDefinition>
+ implements Int16Codec<String> {
Int16StringCodec(final Optional<IntegerTypeDefinition> typeDef) {
super(typeDef, extractRange(typeDef.orNull()), Short.class);
}
import org.opendaylight.yangtools.yang.data.api.codec.Int32Codec;
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-final class Int32StringCodec extends AbstractIntegerStringCodec<Integer, IntegerTypeDefinition> implements Int32Codec<String> {
+final class Int32StringCodec extends AbstractIntegerStringCodec<Integer, IntegerTypeDefinition>
+ implements Int32Codec<String> {
Int32StringCodec(final Optional<IntegerTypeDefinition> typeDef) {
super(typeDef, extractRange(typeDef.orNull()), Integer.class);
}
import org.opendaylight.yangtools.yang.data.api.codec.Int64Codec;
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-final class Int64StringCodec extends AbstractIntegerStringCodec<Long, IntegerTypeDefinition> implements Int64Codec<String> {
+final class Int64StringCodec extends AbstractIntegerStringCodec<Long, IntegerTypeDefinition>
+ implements Int64Codec<String> {
Int64StringCodec(final Optional<IntegerTypeDefinition> typeDef) {
super(typeDef, extractRange(typeDef.orNull()), Long.class);
import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec;
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-final class Int8StringCodec extends AbstractIntegerStringCodec<Byte, IntegerTypeDefinition> implements Int8Codec<String> {
+final class Int8StringCodec extends AbstractIntegerStringCodec<Byte, IntegerTypeDefinition>
+ implements Int8Codec<String> {
Int8StringCodec(final Optional<IntegerTypeDefinition> typeDef) {
super(typeDef, extractRange(typeDef.orNull()), Byte.class);
}
/**
- * Create a new writer with the specified context and rooted in the specified schema path
+ * Create a new writer with the specified context and rooted in the specified schema path.
*
* @param context Associated {@link SchemaContext}
* @param path schema path
- *
* @return A new {@link NormalizedNodeStreamWriter}
*/
public static SchemaTracker create(final SchemaContext context, final SchemaPath path) {
} else if (parent instanceof ChoiceSchemaNode) {
schema = findChildInCases((ChoiceSchemaNode) parent, qname);
} else {
- throw new IllegalStateException("Unsupported schema type "+ parent.getClass() +" on stack.");
+ throw new IllegalStateException("Unsupported schema type " + parent.getClass() + " on stack.");
}
Preconditions.checkArgument(schema != null, "Could not find schema for node %s in %s", qname, parent);
public LeafListSchemaNode startLeafSet(final NodeIdentifier name) {
final SchemaNode schema = getSchema(name);
- Preconditions.checkArgument(schema instanceof LeafListSchemaNode, "Node %s is not a leaf-list", schema.getPath());
+ Preconditions.checkArgument(schema instanceof LeafListSchemaNode, "Node %s is not a leaf-list",
+ schema.getPath());
schemaStack.push(schema);
return (LeafListSchemaNode)schema;
}
final QName name = Iterables.get(identifier.getPossibleChildNames(), 0);
parent = findCaseByChild((ChoiceSchemaNode) parent, name);
}
- Preconditions.checkArgument(parent instanceof DataNodeContainer, "Augmentation allowed only in DataNodeContainer",parent);
- final AugmentationSchema schema = SchemaUtils.findSchemaForAugment((AugmentationTarget) parent, identifier.getPossibleChildNames());
+ Preconditions.checkArgument(parent instanceof DataNodeContainer,
+ "Augmentation allowed only in DataNodeContainer", parent);
+ final AugmentationSchema schema = SchemaUtils.findSchemaForAugment((AugmentationTarget) parent,
+ identifier.getPossibleChildNames());
final HashSet<DataSchemaNode> realChildSchemas = new HashSet<>();
for (final DataSchemaNode child : schema.getChildNodes()) {
realChildSchemas.add(((DataNodeContainer) parent).getDataChildByName(child.getQName()));
public Object endNode() {
return schemaStack.pop();
}
-
}
import org.slf4j.LoggerFactory;
final class StringPatternCheckingCodec extends StringStringCodec {
-
private static final Logger LOG = LoggerFactory.getLogger(StringPatternCheckingCodec.class);
+
private final Collection<CompiledPatternContext> patterns;
StringPatternCheckingCodec(final StringTypeDefinition typeDef) {
}
@Override
- void validate(final String s) {
- super.validate(s);
+ void validate(final String str) {
+ super.validate(str);
for (final CompiledPatternContext pattern : patterns) {
- pattern.validate(s);
+ pattern.validate(str);
}
}
return Objects.toString(data, "");
}
- void validate(final String s) {
+ void validate(final String str) {
if (lengths != null) {
- Preconditions.checkArgument(lengths.contains(s.length()), "String '%s' does not match allowed lengths %s",
+ Preconditions.checkArgument(lengths.contains(str.length()), "String '%s' does not match allowed lengths %s",
lengths);
}
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- public static TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> from(final TypeDefinition typeDefinition) {
+ public static TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> from(
+ final TypeDefinition typeDefinition) {
return (TypeDefinitionAwareCodec)fromType(typeDefinition);
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class UnionStringCodec extends TypeDefinitionAwareCodec<Object, UnionTypeDefinition> implements UnionCodec<String> {
+final class UnionStringCodec extends TypeDefinitionAwareCodec<Object, UnionTypeDefinition>
+ implements UnionCodec<String> {
- private final static Logger LOG = LoggerFactory.getLogger(UnionStringCodec.class);
+ private static final Logger LOG = LoggerFactory.getLogger(UnionStringCodec.class);
private UnionStringCodec(final Optional<UnionTypeDefinition> typeDef) {
super(typeDef, Object.class);
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public Object deserialize(final String stringRepresentation) {
if (!getTypeDefinition().isPresent()) {
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-final public class LeafRefContext {
+public final class LeafRefContext {
private final QName currentNodeQName;
private final SchemaPath currentNodePath;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-class LeafRefContextBuilder {
+class LeafRefContextBuilder implements Builder<LeafRefContext> {
+
+ private final Map<QName, LeafRefContext> referencingChildren = new HashMap<>();
+ private final Map<QName, LeafRefContext> referencedByChildren = new HashMap<>();
+ private final Map<QName, LeafRefContext> referencedByLeafRefCtx = new HashMap<>();
private QName currentNodeQName;
private SchemaPath currentNodePath;
private boolean isReferencedBy = false;
private boolean isReferencing = false;
- private final Map<QName, LeafRefContext> referencingChildren = new HashMap<>();
- private final Map<QName, LeafRefContext> referencedByChildren = new HashMap<>();
- private final Map<QName, LeafRefContext> referencedByLeafRefCtx = new HashMap<>();
-
- public LeafRefContextBuilder(final QName currentNodeQName,
- final SchemaPath currentNodePath, final SchemaContext schemaContext) {
+ LeafRefContextBuilder(final QName currentNodeQName, final SchemaPath currentNodePath,
+ final SchemaContext schemaContext) {
this.currentNodeQName = currentNodeQName;
this.currentNodePath = currentNodePath;
this.schemaContext = schemaContext;
}
+ @Override
public LeafRefContext build() {
final LeafRefContext leafRefContext = new LeafRefContext(this);
public Map<QName, LeafRefContext> getAllReferencedByLeafRefCtxs() {
return referencedByLeafRefCtx;
}
-
}
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
class LeafRefContextTreeBuilder {
+ private final List<LeafRefContext> leafRefs = new LinkedList<>();
private final SchemaContext schemaContext;
- private final List<LeafRefContext> leafRefs;
- public LeafRefContextTreeBuilder(final SchemaContext schemaContext) {
+ LeafRefContextTreeBuilder(final SchemaContext schemaContext) {
this.schemaContext = schemaContext;
- this.leafRefs = new LinkedList<>();
}
public LeafRefContext buildLeafRefContextTree() throws IOException,
LeafRefYangSyntaxErrorException {
- final LeafRefContextBuilder rootBuilder = new LeafRefContextBuilder(
- schemaContext.getQName(), schemaContext.getPath(),
- schemaContext);
+ final LeafRefContextBuilder rootBuilder = new LeafRefContextBuilder(schemaContext.getQName(),
+ schemaContext.getPath(), schemaContext);
final Set<Module> modules = schemaContext.getModules();
for (final Module module : modules) {
public class LeafRefDataValidationFailedException extends Exception {
private static final long serialVersionUID = 1L;
- private int errorsCount = 1;
- public LeafRefDataValidationFailedException(String message) {
- super(message);
- }
+ private final int errorsCount;
- public LeafRefDataValidationFailedException(String message, int errorsCount) {
+ public LeafRefDataValidationFailedException(final String message, final int errorsCount) {
super(message);
this.errorsCount = errorsCount;
}
- public LeafRefDataValidationFailedException(String message,
- final Throwable cause) {
+ public LeafRefDataValidationFailedException(final String message) {
+ this(message, 1);
+ }
+
+ public LeafRefDataValidationFailedException(final String message, final Throwable cause) {
super(message, cause);
+ errorsCount = 1;
}
public int getValidationsErrorsCount() {
}
@SuppressWarnings("rawtypes")
- private static final AtomicReferenceFieldUpdater<LeafRefPath, ImmutableList> LEGACYPATH_UPDATER = AtomicReferenceFieldUpdater
- .newUpdater(LeafRefPath.class, ImmutableList.class, "legacyPath");
+ private static final AtomicReferenceFieldUpdater<LeafRefPath, ImmutableList> LEGACYPATH_UPDATER =
+ AtomicReferenceFieldUpdater.newUpdater(LeafRefPath.class, ImmutableList.class, "legacyPath");
/**
* Shared instance of the conceptual root schema node.
this.parent = parent;
this.qname = qname;
- int h = Objects.hashCode(parent);
+ int hc = Objects.hashCode(parent);
if (qname != null) {
- h = h * 31 + qname.hashCode();
+ hc = hc * 31 + qname.hashCode();
}
- hash = h;
+ hash = hc;
}
/**
public String toString() {
StringBuilder sb = new StringBuilder();
- Iterable<QNameWithPredicate> pathFromRoot = this.getPathFromRoot();
-
sb.append(isAbsolute() ? "Absolute path:" : "Relative path:");
- for (QNameWithPredicate qName : pathFromRoot) {
- sb.append('/').append(qName);
+ for (QNameWithPredicate qname : getPathFromRoot()) {
+ sb.append('/').append(qname);
}
return sb.toString();
-
}
// @Override
private final List<LeafRefPathSyntaxErrorException> exceptions = new ArrayList<>(1);
private final Module module;
- public LeafRefPathErrorListener(final Module module) {
+ LeafRefPathErrorListener(final Module module) {
this.module = module;
}
@Override
+ @SuppressWarnings("checkstyle:parameterName")
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
final int charPositionInLine, final String msg, final RecognitionException e) {
LOG.debug("Syntax error in module {} at {}:{}: {}", module.getName(), line, charPositionInLine, msg, e);
private final Module module;
private final SchemaNode node;
- public LeafRefPathParserImpl(final SchemaContext schemaContext, final Module currentModule, final SchemaNode currentNode) {
+ LeafRefPathParserImpl(final SchemaContext schemaContext, final Module currentModule, final SchemaNode currentNode) {
this.schemaContext = schemaContext;
this.module = currentModule;
this.node = currentNode;
}
- public LeafRefPath parseLeafRefPathSourceToSchemaPath(final InputStream stream) throws IOException, LeafRefYangSyntaxErrorException {
-
+ public LeafRefPath parseLeafRefPathSourceToSchemaPath(final InputStream stream) throws IOException,
+ LeafRefYangSyntaxErrorException {
final Path_argContext pathCtx = parseLeafRefPathSource(stream);
final ParseTreeWalker walker = new ParseTreeWalker();
- final LeafRefPathParserListenerImpl leafRefPathParserListenerImpl = new LeafRefPathParserListenerImpl(schemaContext, module, node);
- walker.walk(leafRefPathParserListenerImpl,pathCtx);
-
- final LeafRefPath leafRefPath = leafRefPathParserListenerImpl.getLeafRefPath();
+ final LeafRefPathParserListenerImpl leafRefPathParserListenerImpl = new LeafRefPathParserListenerImpl(
+ schemaContext, module, node);
+ walker.walk(leafRefPathParserListenerImpl, pathCtx);
- return leafRefPath;
+ return leafRefPathParserListenerImpl.getLeafRefPath();
}
-
- private Path_argContext parseLeafRefPathSource(final InputStream stream) throws IOException, LeafRefYangSyntaxErrorException {
+ private Path_argContext parseLeafRefPathSource(final InputStream stream) throws IOException,
+ LeafRefYangSyntaxErrorException {
final LeafRefPathLexer lexer = new LeafRefPathLexer(CharStreams.fromStream(stream));
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final LeafRefPathParser parser = new LeafRefPathParser(tokens);
final Path_argContext result = parser.path_arg();
errorListener.validate();
-
return result;
}
-
}
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
+final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener {
private final List<QNameWithPredicateBuilder> leafRefPathQnameList = new ArrayList<>();
private final SchemaContext schemaContext;
private final Module module;
- //FIXME use for identifier path completion
+ // FIXME: use for identifier path completion
private final SchemaNode node;
private ParsingState currentParsingState = ParsingState.LEAF_REF_PATH;
LEAF_REF_PATH, PATH_PREDICATE, PREDICATE_PATH_EQUALITY_EXPR, PATH_KEY_EXPR
}
- public LeafRefPathParserListenerImpl(final SchemaContext schemaContext, final Module currentModule, final SchemaNode currentNode) {
- this.schemaContext = schemaContext;
- this.module = currentModule;
- this.node = currentNode;
+ LeafRefPathParserListenerImpl(final SchemaContext schemaContext, final Module currentModule,
+ final SchemaNode currentNode) {
+ this.schemaContext = schemaContext;
+ this.module = currentModule;
+ this.node = currentNode;
}
@Override
public void enterPath_predicate(final Path_predicateContext ctx) {
- currentParsingState=ParsingState.PATH_PREDICATE;
+ currentParsingState = ParsingState.PATH_PREDICATE;
currentPredicate = new QNamePredicateBuilder();
}
public void exitPath_predicate(final Path_predicateContext ctx) {
currentLeafRefPathQName.addQNamePredicate(currentPredicate.build());
currentPredicate = null;
- currentParsingState=ParsingState.LEAF_REF_PATH;
+ currentParsingState = ParsingState.LEAF_REF_PATH;
}
@Override
public void enterRel_path_keyexpr(final Rel_path_keyexprContext ctx) {
- currentParsingState=ParsingState.PATH_KEY_EXPR;
+ currentParsingState = ParsingState.PATH_KEY_EXPR;
final List<TerminalNode> dots = ctx.DOTS();
predicatePathKeyQnameList = new ArrayList<>(dots.size());
QNameWithPredicateBuilder::build), false);
currentPredicate.setPathKeyExpression(pathKeyExpression);
- currentParsingState=ParsingState.PREDICATE_PATH_EQUALITY_EXPR;
+ currentParsingState = ParsingState.PREDICATE_PATH_EQUALITY_EXPR;
}
@Override
private URI getNamespaceForImportPrefix(final String prefix) {
final ModuleImport moduleImport = getModuleImport(prefix);
- final Module findedModule = schemaContext.findModuleByName(moduleImport.getModuleName(), moduleImport.getRevision());
+ final Module findedModule = schemaContext.findModuleByName(moduleImport.getModuleName(),
+ moduleImport.getRevision());
return findedModule.getNamespace();
}
*/
package org.opendaylight.yangtools.yang.data.impl.leafref;
-public class LeafRefPathSyntaxErrorException extends LeafRefYangSyntaxErrorException{
+public class LeafRefPathSyntaxErrorException extends LeafRefYangSyntaxErrorException {
private static final long serialVersionUID = 1L;
}
/**
+ * Create an absolute leafref path.
+ *
* @param leafRefPath leafRefPath
* @param contextNodeSchemaPath contextNodeSchemaPath
* @param module module
final Deque<QNameWithPredicate> absoluteLeafRefTargetPathList = schemaPathToXPathQNames(
contextNodeSchemaPath, module);
-
- final Iterable<QNameWithPredicate> leafRefTargetPathFromRoot = leafRefPath
- .getPathFromRoot();
- final Iterator<QNameWithPredicate> leafRefTgtPathFromRootIterator = leafRefTargetPathFromRoot
- .iterator();
+ final Iterator<QNameWithPredicate> leafRefTgtPathFromRootIterator = leafRefPath.getPathFromRoot().iterator();
while (leafRefTgtPathFromRootIterator.hasNext()) {
final QNameWithPredicate qname = leafRefTgtPathFromRootIterator.next();
return LeafRefPath.create(absoluteLeafRefTargetPathList, true);
}
- /**
- * @param currentNodePath
- * @param module
- * @param absoluteLeafRefTargetPathList
- */
private static Deque<QNameWithPredicate> schemaPathToXPathQNames(
final SchemaPath nodePath, final Module module) {
return xpath;
}
- public static LeafRefPath schemaPathToLeafRefPath(final SchemaPath nodePath,
- final Module module) {
- final Deque<QNameWithPredicate> xpathQNames = schemaPathToXPathQNames(
- nodePath, module);
- return LeafRefPath.create(xpathQNames, true);
+ public static LeafRefPath schemaPathToLeafRefPath(final SchemaPath nodePath, final Module module) {
+ return LeafRefPath.create(schemaPathToXPathQNames(nodePath, module), true);
}
-
}
return childReferencedByCtx;
}
- private void validateNodeData(final NormalizedNode<?, ?> node, final LeafRefContext referencedByCtx, final
- LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) {
+ private void validateNodeData(final NormalizedNode<?, ?> node, final LeafRefContext referencedByCtx,
+ final LeafRefContext referencingCtx, final ModificationType modificationType,
+ final YangInstanceIdentifier current) {
if (node instanceof LeafNode) {
final LeafNode<?> leaf = (LeafNode<?>) node;
} else if (node instanceof DataContainerNode) {
final DataContainerNode<?> dataContainerNode = (DataContainerNode<?>) node;
- for (final DataContainerChild<? extends PathArgument, ?> dataContainerChild : dataContainerNode.getValue()) {
- final QName qname = dataContainerChild.getNodeType();
+ for (final DataContainerChild<? extends PathArgument, ?> child : dataContainerNode.getValue()) {
+ final QName qname = child.getNodeType();
final LeafRefContext childReferencedByCtx;
if (referencedByCtx != null) {
if (childReferencedByCtx != null || childReferencingCtx != null) {
final YangInstanceIdentifier childYangInstanceIdentifier = current
- .node(dataContainerChild.getIdentifier());
- validateNodeData(dataContainerChild, childReferencedByCtx,
+ .node(child.getIdentifier());
+ validateNodeData(child, childReferencedByCtx,
childReferencingCtx, modificationType, childYangInstanceIdentifier);
}
}
}
if (childReferencedByCtx != null || childReferencingCtx != null) {
- final YangInstanceIdentifier mapEntryNodeYangInstanceIdentifier = mapEntryYangInstanceIdentifier
- .node(mapEntryNode.getIdentifier());
- validateNodeData(mapEntryNode, childReferencedByCtx,
- childReferencingCtx, modificationType,
- mapEntryNodeYangInstanceIdentifier);
+ validateNodeData(mapEntryNode, childReferencedByCtx, childReferencingCtx, modificationType,
+ mapEntryYangInstanceIdentifier.node(mapEntryNode.getIdentifier()));
}
}
}
final Set<?> leafRefValuesSet = entry.getValue();
for (final Object leafRefsValue : leafRefValuesSet) {
if (leafRefTargetNodeValues != null && !leafRefTargetNodeValues.contains(leafRefsValue)) {
- LOG.debug("Invalid leafref value [{}] allowed values {} by validation of leafref TARGET node:" +
- " {} path of invalid LEAFREF node: {} leafRef target path: {} {}", leafRefsValue,
+ LOG.debug("Invalid leafref value [{}] allowed values {} by validation of leafref TARGET node: "
+ + "{} path of invalid LEAFREF node: {} leafRef target path: {} {}", leafRefsValue,
leafRefTargetNodeValues, leaf.getNodeType(), leafRefContext.getCurrentNodePath(),
leafRefContext.getAbsoluteLeafRefTargetPath(), FAILED);
- errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s by validation " +
- "of leafref TARGET node: %s path of invalid LEAFREF node: %s leafRef target " +
- "path: %s %s", leafRefsValue, leafRefTargetNodeValues, leaf.getNodeType(),
+ errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s by validation "
+ + "of leafref TARGET node: %s path of invalid LEAFREF node: %s leafRef target "
+ + "path: %s %s", leafRefsValue, leafRefTargetNodeValues, leaf.getNodeType(),
leafRefContext.getCurrentNodePath(), leafRefContext.getAbsoluteLeafRefTargetPath(),
FAILED));
} else {
}
}
} else if (leafRefsValues != null) {
- LOG.debug("Operation [{}] validate data of leafref TARGET node: name[{}] = value[{}] -> SKIP: Already validated",
- modificationType, referencedByCtx.getNodeName(), leaf.getValue());
+ LOG.debug("Operation [{}] validate data of leafref TARGET node: name[{}] = value[{}] "
+ + "-> SKIP: Already validated", modificationType, referencedByCtx.getNodeName(), leaf.getValue());
}
}
modificationType, referencingCtx.getNodeName(), leaf.getValue(), FAILED);
LOG.debug("Invalid leafref value [{}] allowed values {} of LEAFREF node: {} leafRef target path: {}",
leaf.getValue(), values, leaf.getNodeType(), referencingCtx.getAbsoluteLeafRefTargetPath());
- errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s of LEAFREF node: %s " +
- "leafRef target path: %s", leaf.getValue(), values, leaf.getNodeType(), referencingCtx
+ errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s of LEAFREF node: %s "
+ + "leafRef target path: %s", leaf.getValue(), values, leaf.getNodeType(), referencingCtx
.getAbsoluteLeafRefTargetPath()));
} else {
LOG.debug("Operation [{}] validate data of LEAFREF node: name[{}] = value[{}] {}", modificationType,
}
private void addValues(final Set<Object> values, final Optional<? extends NormalizedNode<?, ?>> optDataNode,
- final Iterable<QNameWithPredicate> path, final YangInstanceIdentifier current, final QNameWithPredicate previousQName) {
+ final Iterable<QNameWithPredicate> path, final YangInstanceIdentifier current,
+ final QNameWithPredicate previousQName) {
if (!optDataNode.isPresent()) {
return;
return choiceNodes;
}
- private static boolean isMatchingPredicate(final MapEntryNode mapEntryNode, final Map<QName, Set<?>> allowedKeyValues) {
+ private static boolean isMatchingPredicate(final MapEntryNode mapEntryNode,
+ final Map<QName, Set<?>> allowedKeyValues) {
for (final Entry<QName, Object> entryKeyValue : mapEntryNode.getIdentifier().getKeyValues().entrySet()) {
final Set<?> allowedValues = allowedKeyValues.get(entryKeyValue.getKey());
if (allowedValues != null && !allowedValues.contains(entryKeyValue.getValue())) {
final YangInstanceIdentifier current) {
final Optional<NormalizedNode<?, ?>> parent = findParentNode(tree.getRootNode().getDataAfter(), current);
-
final Iterable<QNameWithPredicate> predicatePathExpr = predicatePathKeyExpression.getPathFromRoot();
final Iterable<QNameWithPredicate> predicatePath = nextLevel(predicatePathExpr);
final Set<Object> values = new HashSet<>();
+ // FIXME: this null check does not look right
if (parent != null) {
- addValues(values, parent, predicatePath, null,QNameWithPredicate.ROOT);
+ addValues(values, parent, predicatePath, null, QNameWithPredicate.ROOT);
}
return values;
private static Iterable<QNameWithPredicate> nextLevel(final Iterable<QNameWithPredicate> path) {
return Iterables.skip(path, 1);
}
-}
\ No newline at end of file
+}
*/
package org.opendaylight.yangtools.yang.data.impl.leafref;
+import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.common.QName;
-class QNamePredicateBuilder {
+class QNamePredicateBuilder implements Builder<QNamePredicate> {
private QName identifier;
private LeafRefPath pathKeyExpression;
- public QNamePredicateBuilder() {
+ QNamePredicateBuilder() {
}
- public QNamePredicateBuilder(final QName identifier, final LeafRefPath pathKeyExpression) {
+ QNamePredicateBuilder(final QName identifier, final LeafRefPath pathKeyExpression) {
this.identifier = identifier;
this.pathKeyExpression = pathKeyExpression;
}
this.pathKeyExpression = pathKeyExpression;
}
+ @Override
public QNamePredicate build() {
return new QNamePredicateImpl(identifier, pathKeyExpression);
}
sb.append(identifier);
sb.append("=current()");
- final Iterable<QNameWithPredicate> pathFromRoot = pathKeyExpression
- .getPathFromRoot();
-
- for (final QNameWithPredicate qName : pathFromRoot) {
- sb.append('/').append(qName);
+ for (final QNameWithPredicate qname : pathKeyExpression.getPathFromRoot()) {
+ sb.append('/').append(qname);
}
sb.append(']');
import org.opendaylight.yangtools.yang.common.QName;
class QNamePredicateImpl implements Immutable, Serializable, QNamePredicate {
-
private static final long serialVersionUID = 1L;
+
private final QName identifier;
private final LeafRefPath pathKeyExpression;
- public QNamePredicateImpl(final QName identifier, final LeafRefPath pathKeyExpression) {
+ QNamePredicateImpl(final QName identifier, final LeafRefPath pathKeyExpression) {
this.identifier = Preconditions.checkNotNull(identifier, "QNamePredicate: identifier should not be null");
- this.pathKeyExpression = Preconditions.checkNotNull(pathKeyExpression, "QNamePredicate: pathKeyExpression should not be null");
+ this.pathKeyExpression = Preconditions.checkNotNull(pathKeyExpression,
+ "QNamePredicate: pathKeyExpression should not be null");
}
@Override
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
- sb.append('[');
-
- sb.append(identifier);
- sb.append("=current()");
+ sb.append('[').append(identifier).append("=current()");
- final Iterable<QNameWithPredicate> pathFromRoot = pathKeyExpression
- .getPathFromRoot();
-
- for (final QNameWithPredicate qName : pathFromRoot) {
- sb.append('/').append(qName);
+ for (final QNameWithPredicate qname : pathKeyExpression.getPathFromRoot()) {
+ sb.append('/').append(qname);
}
- sb.append(']');
- return sb.toString();
+ return sb.append(']').toString();
}
-
}
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.common.QNameModule;
-class QNameWithPredicateBuilder {
+class QNameWithPredicateBuilder implements Builder<QNameWithPredicate> {
private final List<QNamePredicate> qnamePredicates = new ArrayList<>();
private QNameModule moduleQname;
private String localName;
- public static final QNameWithPredicateBuilder UP_PARENT_BUILDER = new QNameWithPredicateBuilder(
- null, "..") {
+ static final QNameWithPredicateBuilder UP_PARENT_BUILDER = new QNameWithPredicateBuilder(null, "..") {
@Override
public QNameWithPredicate build() {
return QNameWithPredicate.UP_PARENT;
}
};
- public QNameWithPredicateBuilder(final QNameModule moduleQname, final String localName) {
+ QNameWithPredicateBuilder(final QNameModule moduleQname, final String localName) {
this.moduleQname = moduleQname;
this.localName = localName;
}
+ @Override
public QNameWithPredicate build() {
final QNameWithPredicateImpl qNameWithPredicateImpl = new QNameWithPredicateImpl(
moduleQname, localName, qnamePredicates);
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-final class QNameWithPredicateImpl implements Immutable, Serializable,
- QNameWithPredicate {
+final class QNameWithPredicateImpl implements Immutable, Serializable, QNameWithPredicate {
private static final long serialVersionUID = 1L;
private final QNameModule moduleQname;
private final String localName;
- public QNameWithPredicateImpl(final QNameModule moduleQname, final String localName,
+ QNameWithPredicateImpl(final QNameModule moduleQname, final String localName,
final List<QNamePredicate> qnamePredicates) {
this.moduleQname = moduleQname;
this.localName = localName;
return sb.toString();
}
-
}
return ImmutableYangModeledAnyXmlNodeBuilder.create(schema);
}
- public static <T> ListNodeBuilder<T,LeafSetEntryNode<T>> leafSetBuilder() {
- return ImmutableLeafSetNodeBuilder.create();
- }
-
- public static <T> ListNodeBuilder<T,LeafSetEntryNode<T>> orderedLeafSetBuilder() {
+ public static <T> ListNodeBuilder<T,LeafSetEntryNode<T>> orderedLeafSetBuilder() {
return ImmutableOrderedLeafSetNodeBuilder.create();
}
return ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(schema);
}
+ public static <T> ListNodeBuilder<T,LeafSetEntryNode<T>> leafSetBuilder() {
+ return ImmutableLeafSetNodeBuilder.create();
+ }
+
public static <T> ListNodeBuilder<T,LeafSetEntryNode<T>> leafSetBuilder(final LeafSetNode<T> node) {
return ImmutableLeafSetNodeBuilder.create(node);
}
return ImmutableLeafSetNodeSchemaAwareBuilder.create(schema);
}
- public static <T> ListNodeBuilder<T,LeafSetEntryNode<T>> leafSetBuilder(final LeafListSchemaNode schema, final LeafSetNode<T> node) {
+ public static <T> ListNodeBuilder<T,LeafSetEntryNode<T>> leafSetBuilder(final LeafListSchemaNode schema,
+ final LeafSetNode<T> node) {
return ImmutableLeafSetNodeSchemaAwareBuilder.create(schema, node);
}
return ImmutableContainerNodeBuilder.create();
}
- public static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder(final ContainerNode node) {
+ public static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder(
+ final ContainerNode node) {
return ImmutableContainerNodeBuilder.create(node);
}
return ImmutableMapEntryNodeSchemaAwareBuilder.create(schema);
}
- public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder() {
- return ImmutableMapNodeBuilder.create();
- }
-
public static CollectionNodeBuilder<MapEntryNode, OrderedMapNode> orderedMapBuilder() {
return ImmutableOrderedMapNodeBuilder.create();
}
return ImmutableUnkeyedListNodeBuilder.create();
}
+ public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder() {
+ return ImmutableMapNodeBuilder.create();
+ }
+
public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder(final MapNode node) {
return ImmutableMapNodeBuilder.create(node);
}
return ImmutableMapNodeSchemaAwareBuilder.create(schema);
}
- public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder(final ListSchemaNode schema, final MapNode node) {
+ public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder(final ListSchemaNode schema,
+ final MapNode node) {
return ImmutableMapNodeSchemaAwareBuilder.create(schema, node);
}
return ImmutableAugmentationNodeBuilder.create();
}
- public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentationBuilder(final AugmentationSchema schema) {
+ public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentationBuilder(
+ final AugmentationSchema schema) {
return ImmutableAugmentationNodeSchemaAwareBuilder.create(schema);
}
public static DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> unkeyedListEntryBuilder() {
return ImmutableUnkeyedListEntryNodeBuilder.create();
}
-
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import java.util.Map;
+import java.util.Map.Entry;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
}
/**
- * Construct immutable leaf node
+ * Construct immutable leaf node.
*
* @param name Identifier of leaf node
* @param value Value of leaf node
}
/**
- * Construct immutable leaf node
+ * Construct immutable leaf node.
*
* @param name QName which will be used as node identifier
* @param value Value of leaf node.
return leafNode(NodeIdentifier.create(name), value);
}
- public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder(final QName nodeName, final QName keyName, final Object keyValue) {
+ public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder(
+ final QName nodeName, final QName keyName, final Object keyValue) {
return ImmutableMapEntryNodeBuilder.create()
.withNodeIdentifier(new NodeIdentifierWithPredicates(nodeName, keyName, keyValue))
.withChild(leafNode(keyName, keyValue));
}
- public static MapEntryNode mapEntry(final QName nodeName,final QName keyName,final Object keyValue) {
- return mapEntryBuilder(nodeName, keyName, keyValue).build();
- }
-
public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder() {
return ImmutableMapEntryNodeBuilder.create();
}
+ public static MapEntryNode mapEntry(final QName nodeName,final QName keyName,final Object keyValue) {
+ return mapEntryBuilder(nodeName, keyName, keyValue).build();
+ }
+
public static ContainerNode containerNode(final QName name) {
return ImmutableContainerNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create(name)).build();
}
}
/**
- * Convert YangInstanceIdentifier into a normalized node structure
+ * Convert YangInstanceIdentifier into a normalized node structure.
*
* @param ctx schema context to used during serialization
* @param id instance identifier to convert to node structure starting from root
}
/**
- * Convert YangInstanceIdentifier into a normalized node structure
+ * Convert YangInstanceIdentifier into a normalized node structure.
*
* @param ctx schema context to used during serialization
* @param id instance identifier to convert to node structure starting from root
- * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided instance Id
+ * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided
+ * instance identifier
* @return serialized normalized node for provided instance Id with overridden last child.
*/
- public static NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final NormalizedNode<?, ?> deepestElement) {
+ public static NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id,
+ final NormalizedNode<?, ?> deepestElement) {
return fromInstanceId(ctx, id, Optional.of(deepestElement), Optional.absent());
}
/**
- * Convert YangInstanceIdentifier into a normalized node structure
+ * Convert YangInstanceIdentifier into a normalized node structure.
*
* @param ctx schema context to used during serialization
* @param id instance identifier to convert to node structure starting from root
- * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided instance Id
- * @param operation modify operation attribute to be added to the deepest child. QName is the operation attribute key and ModifyAction is the value.
- * @return serialized normalized node for provided instance Id with (optionally) overridden last child and (optionally) marked with specific operation attribute.
+ * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided
+ * instance identifier
+ * @param operation modify operation attribute to be added to the deepest child. QName is the operation attribute
+ * key and ModifyAction is the value.
+ * @return serialized normalized node for provided instance Id with (optionally) overridden last child
+ * and (optionally) marked with specific operation attribute.
*/
- public static NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final Optional<NormalizedNode<?, ?>> deepestElement, final Optional<Map.Entry<QName, ModifyAction>> operation) {
+ public static NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id,
+ final Optional<NormalizedNode<?, ?>> deepestElement, final Optional<Entry<QName, ModifyAction>> operation) {
Preconditions.checkNotNull(ctx);
Preconditions.checkNotNull(id);
final YangInstanceIdentifier.PathArgument topLevelElement = id.getPathArguments().get(0);
final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType());
- Preconditions.checkNotNull(dataChildByName, "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement);
- final InstanceIdToNodes<?> instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType());
+ Preconditions.checkNotNull(dataChildByName,
+ "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement);
+ final InstanceIdToNodes<?> instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx,
+ topLevelElement.getNodeType());
return instanceIdToNodes.create(id, deepestElement, operation);
}
}
import org.opendaylight.yangtools.yang.model.api.YangModeledAnyXmlSchemaNode;
/**
+ * Implementation of {@link NormalizedNodeStreamWriter}, which constructs immutable instances of
+ * {@link NormalizedNode}s.
*
- * Implementation of {@link NormalizedNodeStreamWriter}, which constructs
- * immutable instances of {@link NormalizedNode}s.
* <p>
- * This writer supports two modes of behaviour one is using {@link #from(NormalizedNodeResult)}
- * where resulting NormalizedNode will be stored in supplied result object.
- *
- * Other mode of operation is using {@link #from(NormalizedNodeContainerBuilder)},
- * where all created nodes will be written to this builder.
- *
+ * This writer supports two modes of behaviour one is using {@link #from(NormalizedNodeResult)} where resulting
+ * NormalizedNode will be stored in supplied result object.
*
+ * <p>
+ * Other mode of operation is using {@link #from(NormalizedNodeContainerBuilder)}, where all created nodes will be
+ * written to this builder.
*/
public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStreamWriter {
}
/**
- * Creates a {@link NormalizedNodeStreamWriter} which creates instances of supplied
- * {@link NormalizedNode}s and writes them to supplied builder as child nodes.
+ * Creates a {@link NormalizedNodeStreamWriter} which creates instances of supplied {@link NormalizedNode}s
+ * and writes them to supplied builder as child nodes.
+ *
* <p>
- * Type of supplied {@link NormalizedNodeContainerBuilder} affects,
- * which events could be emitted in order to ensure proper construction of
- * data.
+ * Type of supplied {@link NormalizedNodeContainerBuilder} affects, which events could be emitted in order
+ * to ensure proper construction of data.
*
* @param builder Builder to which data will be written.
* @return {@link NormalizedNodeStreamWriter} which writes data
}
/**
- * Creates a {@link NormalizedNodeStreamWriter} which creates one instance of top
- * level {@link NormalizedNode} (type of NormalizedNode) is determined by first
- * start event.
+ * Creates a {@link NormalizedNodeStreamWriter} which creates one instance of top-level {@link NormalizedNode}
+ * (type of NormalizedNode) is determined by first start event.
+ *
* <p>
- * Result is built when {@link #endNode()} associated with that start event
- * is emitted.
+ * Result is built when {@link #endNode()} associated with that start event is emitted.
+ *
* <p>
- * Writer properly creates also nested {@link NormalizedNode} instances,
- * if their are supported inside the scope of first event.
+ * Writer properly creates also nested {@link NormalizedNode} instances, if their are supported inside the scope
+ * of the first event.
+ *
* <p>
- * This method is useful for clients, which knows there will be one
- * top level node written, but does not know which type of {@link NormalizedNode}
- * will be written.
+ * This method is useful for clients, which knows there will be one top-level node written, but does not know which
+ * type of {@link NormalizedNode} will be written.
*
* @param result {@link NormalizedNodeResult} object which will hold result value.
* @return {@link NormalizedNodeStreamWriter} which will write item to supplied result holder.
@Override
public void startLeafSet(final NodeIdentifier name, final int childSizeHint) {
checkDataNodeContainer();
- final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = UNKNOWN_SIZE == childSizeHint ?
- InterningLeafSetNodeBuilder.create(nextSchema) :
- InterningLeafSetNodeBuilder.create(nextSchema, childSizeHint);
+ final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = UNKNOWN_SIZE == childSizeHint
+ ? InterningLeafSetNodeBuilder.create(nextSchema)
+ : InterningLeafSetNodeBuilder.create(nextSchema, childSizeHint);
builder.withNodeIdentifier(name);
enter(builder);
}
public void leafSetEntryNode(final QName name, final Object value) {
if (getCurrent() instanceof ImmutableOrderedLeafSetNodeBuilder) {
@SuppressWarnings("unchecked")
- ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = ((ImmutableOrderedLeafSetNodeBuilder<Object>) getCurrent());
+ ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder =
+ (ImmutableOrderedLeafSetNodeBuilder<Object>) getCurrent();
builder.withChildValue(value);
} else if (getCurrent() instanceof ImmutableLeafSetNodeBuilder) {
@SuppressWarnings("unchecked")
- ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = ((ImmutableLeafSetNodeBuilder<Object>) getCurrent());
+ ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder =
+ (ImmutableLeafSetNodeBuilder<Object>) getCurrent();
builder.withChildValue(value);
} else {
throw new IllegalArgumentException("LeafSetEntryNode is not valid for parent " + getCurrent());
public void startContainerNode(final NodeIdentifier name, final int childSizeHint) {
checkDataNodeContainer();
- final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder = UNKNOWN_SIZE == childSizeHint ?
- ImmutableContainerNodeBuilder.create() : ImmutableContainerNodeBuilder.create(childSizeHint);
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder =
+ UNKNOWN_SIZE == childSizeHint ? ImmutableContainerNodeBuilder.create()
+ : ImmutableContainerNodeBuilder.create(childSizeHint);
enter(builder.withNodeIdentifier(name));
}
Preconditions.checkArgument(nextSchema instanceof YangModeledAnyXmlSchemaNode,
"Schema of this node should be instance of YangModeledAnyXmlSchemaNode");
- final DataContainerNodeAttrBuilder<NodeIdentifier, YangModeledAnyXmlNode> builder = UNKNOWN_SIZE == childSizeHint ? ImmutableYangModeledAnyXmlNodeBuilder
- .create((YangModeledAnyXmlSchemaNode) nextSchema) : ImmutableYangModeledAnyXmlNodeBuilder.create(
+ final DataContainerNodeAttrBuilder<NodeIdentifier, YangModeledAnyXmlNode> builder =
+ UNKNOWN_SIZE == childSizeHint
+ ? ImmutableYangModeledAnyXmlNodeBuilder.create((YangModeledAnyXmlSchemaNode) nextSchema)
+ : ImmutableYangModeledAnyXmlNodeBuilder.create(
(YangModeledAnyXmlSchemaNode) nextSchema, childSizeHint);
enter(builder.withNodeIdentifier(name));
}
public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) {
checkDataNodeContainer();
- final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> builder = UNKNOWN_SIZE == childSizeHint ?
- ImmutableUnkeyedListNodeBuilder.create() : ImmutableUnkeyedListNodeBuilder.create(childSizeHint);
+ final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> builder =
+ UNKNOWN_SIZE == childSizeHint ? ImmutableUnkeyedListNodeBuilder.create()
+ : ImmutableUnkeyedListNodeBuilder.create(childSizeHint);
enter(builder.withNodeIdentifier(name));
}
@Override
public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) {
- Preconditions.checkArgument((getCurrent() instanceof NormalizedNodeResultBuilder)
+ Preconditions.checkArgument(getCurrent() instanceof NormalizedNodeResultBuilder
|| getCurrent() instanceof ImmutableUnkeyedListNodeBuilder);
- final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> builder = UNKNOWN_SIZE == childSizeHint ?
- ImmutableUnkeyedListEntryNodeBuilder.create() : ImmutableUnkeyedListEntryNodeBuilder.create(childSizeHint);
+ final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> builder =
+ UNKNOWN_SIZE == childSizeHint ? ImmutableUnkeyedListEntryNodeBuilder.create()
+ : ImmutableUnkeyedListEntryNodeBuilder.create(childSizeHint);
enter(builder.withNodeIdentifier(name));
}
public void startMapNode(final NodeIdentifier name, final int childSizeHint) {
checkDataNodeContainer();
- final CollectionNodeBuilder<MapEntryNode, MapNode> builder = UNKNOWN_SIZE == childSizeHint ?
- ImmutableMapNodeBuilder.create() : ImmutableMapNodeBuilder.create(childSizeHint);
+ final CollectionNodeBuilder<MapEntryNode, MapNode> builder = UNKNOWN_SIZE == childSizeHint
+ ? ImmutableMapNodeBuilder.create() : ImmutableMapNodeBuilder.create(childSizeHint);
enter(builder.withNodeIdentifier(name));
}
@Override
public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint) {
if (!(getCurrent() instanceof NormalizedNodeResultBuilder)) {
- Preconditions.checkArgument(getCurrent() instanceof ImmutableMapNodeBuilder || getCurrent() instanceof ImmutableOrderedMapNodeBuilder);
+ Preconditions.checkArgument(getCurrent() instanceof ImmutableMapNodeBuilder
+ || getCurrent() instanceof ImmutableOrderedMapNodeBuilder);
}
- final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = UNKNOWN_SIZE == childSizeHint ?
- ImmutableMapEntryNodeBuilder.create() : ImmutableMapEntryNodeBuilder.create(childSizeHint);
+ final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder =
+ UNKNOWN_SIZE == childSizeHint ? ImmutableMapEntryNodeBuilder.create()
+ : ImmutableMapEntryNodeBuilder.create(childSizeHint);
enter(builder.withNodeIdentifier(identifier));
}
public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) {
checkDataNodeContainer();
- final CollectionNodeBuilder<MapEntryNode, OrderedMapNode> builder = UNKNOWN_SIZE == childSizeHint ?
- ImmutableOrderedMapNodeBuilder.create() : ImmutableOrderedMapNodeBuilder.create(childSizeHint);
+ final CollectionNodeBuilder<MapEntryNode, OrderedMapNode> builder = UNKNOWN_SIZE == childSizeHint
+ ? ImmutableOrderedMapNodeBuilder.create() : ImmutableOrderedMapNodeBuilder.create(childSizeHint);
enter(builder.withNodeIdentifier(name));
}
public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) {
checkDataNodeContainer();
- final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> builder = UNKNOWN_SIZE == childSizeHint ?
- ImmutableChoiceNodeBuilder.create() : ImmutableChoiceNodeBuilder.create(childSizeHint);
+ final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> builder = UNKNOWN_SIZE == childSizeHint
+ ? ImmutableChoiceNodeBuilder.create() : ImmutableChoiceNodeBuilder.create(childSizeHint);
enter(builder.withNodeIdentifier(name));
}
private void checkDataNodeContainer() {
@SuppressWarnings("rawtypes")
- final
- NormalizedNodeContainerBuilder current = getCurrent();
+ final NormalizedNodeContainerBuilder current = getCurrent();
if (!(current instanceof NormalizedNodeResultBuilder)) {
Preconditions.checkArgument(current instanceof DataContainerNodeBuilder<?, ?>, "Invalid nesting of data.");
}
}
@Override
- public NormalizedNode build() {
- throw new IllegalStateException("Can not close NormalizedNodeResult");
+ public NormalizedNodeContainerBuilder withValue(final Collection value) {
+ throw new UnsupportedOperationException();
}
@Override
- public NormalizedNodeContainerBuilder withNodeIdentifier(final PathArgument nodeIdentifier) {
- throw new UnsupportedOperationException();
+ public NormalizedNode build() {
+ throw new IllegalStateException("Can not close NormalizedNodeResult");
}
@Override
- public NormalizedNodeContainerBuilder withValue(final Collection value) {
+ public NormalizedNodeContainerBuilder withNodeIdentifier(final PathArgument nodeIdentifier) {
throw new UnsupportedOperationException();
}
public NormalizedNodeContainerBuilder removeChild(final PathArgument key) {
throw new UnsupportedOperationException();
}
-
}
@Override
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
/**
-* Base strategy for converting an instance identifier into a normalized node structure for container-like types.
-*/
+ * Base strategy for converting an instance identifier into a normalized node structure for container-like types.
+ */
abstract class InstanceIdToCompositeNodes<T extends PathArgument> extends InstanceIdToNodes<T> {
protected InstanceIdToCompositeNodes(final T identifier) {
return new AugmentationIdentifier(potentialChildren.build());
}
- private static DataNodeContainer augmentationProxy(final AugmentationSchema augmentation, final DataNodeContainer schema) {
+ private static DataNodeContainer augmentationProxy(final AugmentationSchema augmentation,
+ final DataNodeContainer schema) {
final Set<DataSchemaNode> children = new HashSet<>();
for (final DataSchemaNode augNode : augmentation.getChildNodes()) {
children.add(schema.getDataChildByName(augNode.getQName()));
@Override
@SuppressWarnings("unchecked")
- public final NormalizedNode<?, ?> create(final YangInstanceIdentifier instanceId, final Optional<NormalizedNode<?, ?>> lastChild, final Optional<Map.Entry<QName,ModifyAction>> operation) {
+ public final NormalizedNode<?, ?> create(final YangInstanceIdentifier instanceId,
+ final Optional<NormalizedNode<?, ?>> lastChild, final Optional<Entry<QName,ModifyAction>> operation) {
checkNotNull(instanceId);
final Iterator<PathArgument> iterator = instanceId.getPathArguments().iterator();
final PathArgument legacyData = iterator.next();
final PathArgument childPath = iterator.next();
final InstanceIdToNodes<?> childOp = getChildOperation(childPath);
- final YangInstanceIdentifier childId = YangInstanceIdentifier.create(Iterables.skip(instanceId.getPathArguments(), 1));
+ final YangInstanceIdentifier childId = YangInstanceIdentifier.create(
+ Iterables.skip(instanceId.getPathArguments(), 1));
builder.addChild(childOp.create(childId, lastChild, operation));
} else {
if (lastChild.isPresent()) {
}
if (operation.isPresent()) {
Preconditions.checkArgument(builder instanceof AttributesBuilder<?>);
- addModifyOpIfPresent(operation, ((AttributesBuilder<?>) builder));
+ addModifyOpIfPresent(operation, (AttributesBuilder<?>) builder);
}
}
return builder.build();
}
+ @SuppressWarnings("checkstyle:illegalCatch")
private InstanceIdToNodes<?> getChildOperation(final PathArgument childPath) {
final InstanceIdToNodes<?> childOp;
try {
return childOp;
}
- protected abstract NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode);
+ protected abstract NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(PathArgument compositeNode);
- static abstract class DataContainerNormalizationOperation<T extends PathArgument> extends
- InstanceIdToCompositeNodes<T> {
+ abstract static class DataContainerNormalizationOperation<T extends PathArgument>
+ extends InstanceIdToCompositeNodes<T> {
private final DataNodeContainer schema;
private final Map<PathArgument, InstanceIdToNodes<?>> byArg;
}
@Override
- protected DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> createBuilder(final PathArgument currentArg) {
+ protected DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> createBuilder(
+ final PathArgument currentArg) {
+ final NodeIdentifierWithPredicates arg = (NodeIdentifierWithPredicates) currentArg;
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = Builders
- .mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates) currentArg);
- for (final Map.Entry<QName, Object> keyValue : ((NodeIdentifierWithPredicates) currentArg).getKeyValues().entrySet()) {
+ .mapEntryBuilder().withNodeIdentifier(arg);
+ for (final Entry<QName, Object> keyValue : arg.getKeyValues().entrySet()) {
builder.addChild(Builders.leafBuilder()
.withNodeIdentifier(NodeIdentifier.create(keyValue.getKey())).withValue(keyValue.getValue())
.build());
}
static final class UnkeyedListItemNormalization extends DataContainerNormalizationOperation<NodeIdentifier> {
-
- protected UnkeyedListItemNormalization(final ListSchemaNode schema) {
+ UnkeyedListItemNormalization(final ListSchemaNode schema) {
super(NodeIdentifier.create(schema.getQName()), schema);
}
@Override
- protected DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> createBuilder(final PathArgument compositeNode) {
+ protected DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> createBuilder(
+ final PathArgument compositeNode) {
return Builders.unkeyedListEntryBuilder().withNodeIdentifier(getIdentifier());
}
}
static final class ContainerTransformation extends DataContainerNormalizationOperation<NodeIdentifier> {
- protected ContainerTransformation(final ContainerSchemaNode schema) {
+ ContainerTransformation(final ContainerSchemaNode schema) {
super(NodeIdentifier.create(schema.getQName()), schema);
}
@Override
- protected DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createBuilder(final PathArgument compositeNode) {
+ protected DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createBuilder(
+ final PathArgument compositeNode) {
return Builders.containerBuilder().withNodeIdentifier(getIdentifier());
}
}
static final class OrderedLeafListMixinNormalization extends UnorderedLeafListMixinNormalization {
-
-
- public OrderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
+ OrderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
super(potential);
}
}
static class UnorderedLeafListMixinNormalization extends InstanceIdToCompositeNodes<NodeIdentifier> {
-
private final InstanceIdToNodes<?> innerOp;
- public UnorderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
+ UnorderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
super(NodeIdentifier.create(potential.getQName()));
innerOp = new InstanceIdToSimpleNodes.LeafListEntryNormalization(potential);
}
}
static final class AugmentationNormalization extends DataContainerNormalizationOperation<AugmentationIdentifier> {
-
- public AugmentationNormalization(final AugmentationSchema augmentation, final DataNodeContainer schema) {
+ AugmentationNormalization(final AugmentationSchema augmentation, final DataNodeContainer schema) {
super(augmentationIdentifierFrom(augmentation), augmentationProxy(augmentation, schema));
}
@Override
- protected DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> createBuilder(final PathArgument compositeNode) {
+ protected DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> createBuilder(
+ final PathArgument compositeNode) {
return Builders.augmentationBuilder().withNodeIdentifier(getIdentifier());
}
}
static class UnorderedMapMixinNormalization extends InstanceIdToCompositeNodes<NodeIdentifier> {
-
private final ListItemNormalization innerNode;
- public UnorderedMapMixinNormalization(final ListSchemaNode list) {
+ UnorderedMapMixinNormalization(final ListSchemaNode list) {
super(NodeIdentifier.create(list.getQName()));
this.innerNode = new ListItemNormalization(new NodeIdentifierWithPredicates(list.getQName(),
Collections.emptyMap()), list);
}
@Override
- protected CollectionNodeBuilder<MapEntryNode, ? extends MapNode> createBuilder(final PathArgument compositeNode) {
+ protected CollectionNodeBuilder<MapEntryNode, ? extends MapNode> createBuilder(
+ final PathArgument compositeNode) {
return Builders.mapBuilder().withNodeIdentifier(getIdentifier());
}
}
static final class OrderedMapMixinNormalization extends UnorderedMapMixinNormalization {
-
- public OrderedMapMixinNormalization(final ListSchemaNode list) {
+ OrderedMapMixinNormalization(final ListSchemaNode list) {
super(list);
}
}
static final class ChoiceNodeNormalization extends InstanceIdToCompositeNodes<NodeIdentifier> {
-
private final ImmutableMap<PathArgument, InstanceIdToNodes<?>> byArg;
- protected ChoiceNodeNormalization(final ChoiceSchemaNode schema) {
+ ChoiceNodeNormalization(final ChoiceSchemaNode schema) {
super(NodeIdentifier.create(schema.getQName()));
final ImmutableMap.Builder<PathArgument, InstanceIdToNodes<?>> byArgBuilder = ImmutableMap.builder();
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
}
/**
- * Build a strategy for the next path argument
+ * Build a strategy for the next path argument.
*
* @param child child identifier
* @return transformation strategy for a specific child
*/
- abstract InstanceIdToNodes<?> getChild(final PathArgument child);
+ abstract InstanceIdToNodes<?> getChild(PathArgument child);
/**
- *
- * Convert instance identifier into a NormalizedNode structure
+ * Convert instance identifier into a NormalizedNode structure.
*
* @param instanceId Instance identifier to transform into NormalizedNodes
* @param deepestChild Optional normalized node to be inserted as the last child
* @param operation Optional modify operation to be set on the last child
* @return NormalizedNode structure corresponding to submitted instance ID
*/
- abstract NormalizedNode<?, ?> create(YangInstanceIdentifier instanceId, Optional<NormalizedNode<?, ?>> deepestChild, Optional<Entry<QName,ModifyAction>> operation);
+ abstract NormalizedNode<?, ?> create(YangInstanceIdentifier instanceId, Optional<NormalizedNode<?, ?>> deepestChild,
+ Optional<Entry<QName,ModifyAction>> operation);
abstract boolean isMixin();
- public void addModifyOpIfPresent(final Optional<Entry<QName,ModifyAction>> operation, final AttributesBuilder<?> builder) {
+ public void addModifyOpIfPresent(final Optional<Entry<QName,ModifyAction>> operation,
+ final AttributesBuilder<?> builder) {
if (operation.isPresent()) {
- builder.withAttributes(Collections.singletonMap(operation.get().getKey(), modifyOperationToXmlString(operation.get().getValue())));
+ builder.withAttributes(Collections.singletonMap(operation.get().getKey(),
+ modifyOperationToXmlString(operation.get().getValue())));
}
}
return operation.name().toLowerCase();
}
- private final static class UnkeyedListMixinNormalization extends InstanceIdToCompositeNodes<NodeIdentifier> {
-
+ private static final class UnkeyedListMixinNormalization extends InstanceIdToCompositeNodes<NodeIdentifier> {
private final UnkeyedListItemNormalization innerNode;
- public UnkeyedListMixinNormalization(final ListSchemaNode list) {
+ UnkeyedListMixinNormalization(final ListSchemaNode list) {
super(NodeIdentifier.create(list.getQName()));
this.innerNode = new UnkeyedListItemNormalization(list);
}
@Override
- protected CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> createBuilder(final PathArgument compositeNode) {
+ protected CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> createBuilder(
+ final PathArgument compositeNode) {
return Builders.unkeyedListBuilder().withNodeIdentifier(getIdentifier());
}
}
private static class AnyXmlNormalization extends InstanceIdToNodes<NodeIdentifier> {
-
- protected AnyXmlNormalization(final AnyXmlSchemaNode schema) {
+ AnyXmlNormalization(final AnyXmlSchemaNode schema) {
super(NodeIdentifier.create(schema.getQName()));
}
Preconditions.checkState(child instanceof AnyXmlNode);
final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder =
- Builders.anyXmlBuilder().withNodeIdentifier(getIdentifier()).withValue(((AnyXmlNode) child).getValue());
+ Builders.anyXmlBuilder().withNodeIdentifier(getIdentifier()).withValue(
+ ((AnyXmlNode) child).getValue());
addModifyOpIfPresent(operation, anyXmlBuilder);
return anyXmlBuilder.build();
}
private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) {
DataSchemaNode potential = parent.getDataChildByName(child);
if (potential == null) {
- final Iterable<ChoiceSchemaNode> choices = FluentIterable.from(parent.getChildNodes()).filter(ChoiceSchemaNode.class);
- potential = findChoice(choices, child);
+ potential = findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child);
}
return Optional.fromNullable(potential);
}
static InstanceIdToNodes<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
final Optional<DataSchemaNode> potential = findChildSchemaNode(schema, child);
Preconditions.checkArgument(potential.isPresent(),
- "Supplied QName %s is not valid according to schema %s, potential children nodes: %s", child, schema, schema.getChildNodes());
+ "Supplied QName %s is not valid according to schema %s, potential children nodes: %s", child, schema,
+ schema.getChildNodes());
final DataSchemaNode result = potential.get();
// We try to look up if this node was added by augmentation
* call for {@link #fromDataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode)}.
*/
private static InstanceIdToNodes<?> fromAugmentation(final DataNodeContainer parent,
- final AugmentationTarget parentAug, final DataSchemaNode child) {
+ final AugmentationTarget parentAug, final DataSchemaNode child) {
AugmentationSchema augmentation = null;
for (final AugmentationSchema aug : parentAug.getAvailableAugmentations()) {
final DataSchemaNode potential = aug.getDataChildByName(child.getQName());
}
return new InstanceIdToCompositeNodes.UnorderedLeafListMixinNormalization(potential);
}
-
-
}
package org.opendaylight.yangtools.yang.data.impl.schema;
import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import java.util.Map;
+import java.util.Map.Entry;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
}
@Override
- public NormalizedNode<?, ?> create(final YangInstanceIdentifier instanceId, final Optional<NormalizedNode<?, ?>> deepestChild, final Optional<Map.Entry<QName,ModifyAction>> operation) {
+ public NormalizedNode<?, ?> create(final YangInstanceIdentifier instanceId,
+ final Optional<NormalizedNode<?, ?>> deepestChild, final Optional<Entry<QName, ModifyAction>> operation) {
checkNotNull(instanceId);
final PathArgument pathArgument = instanceId.getPathArguments().get(0);
- final NormalizedNodeAttrBuilder<? extends PathArgument, Object, ? extends NormalizedNode<? extends PathArgument, Object>> builder = getBuilder(pathArgument);
+ final NormalizedNodeAttrBuilder<? extends PathArgument, Object,
+ ? extends NormalizedNode<? extends PathArgument, Object>> builder = getBuilder(pathArgument);
if (deepestChild.isPresent()) {
builder.withValue(deepestChild.get().getValue());
return builder.build();
}
- protected abstract NormalizedNodeAttrBuilder<? extends PathArgument, Object, ? extends NormalizedNode<? extends PathArgument, Object>> getBuilder(PathArgument node);
+ protected abstract NormalizedNodeAttrBuilder<? extends PathArgument, Object,
+ ? extends NormalizedNode<? extends PathArgument, Object>> getBuilder(PathArgument node);
@Override
public InstanceIdToNodes<?> getChild(final PathArgument child) {
}
static final class LeafNormalization extends InstanceIdToSimpleNodes<NodeIdentifier> {
-
- protected LeafNormalization(final LeafSchemaNode potential) {
+ LeafNormalization(final LeafSchemaNode potential) {
super(new NodeIdentifier(potential.getQName()));
}
@Override
- protected NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> getBuilder(final PathArgument node) {
+ protected NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> getBuilder(
+ final PathArgument node) {
return Builders.leafBuilder().withNodeIdentifier(getIdentifier());
}
}
static final class LeafListEntryNormalization extends InstanceIdToSimpleNodes<NodeWithValue> {
-
- public LeafListEntryNormalization(final LeafListSchemaNode potential) {
- super(new YangInstanceIdentifier.NodeWithValue<>(potential.getQName(), null));
+ LeafListEntryNormalization(final LeafListSchemaNode potential) {
+ super(new NodeWithValue<>(potential.getQName(), null));
}
@Override
- protected NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> getBuilder(final YangInstanceIdentifier.PathArgument node) {
- Preconditions.checkArgument(node instanceof YangInstanceIdentifier.NodeWithValue);
- return Builders.leafSetEntryBuilder().withNodeIdentifier((YangInstanceIdentifier.NodeWithValue<?>) node).withValue(((YangInstanceIdentifier.NodeWithValue<?>) node).getValue());
+ protected NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> getBuilder(
+ final PathArgument node) {
+ Preconditions.checkArgument(node instanceof NodeWithValue);
+ return Builders.leafSetEntryBuilder().withNodeIdentifier((NodeWithValue<?>) node)
+ .withValue(((NodeWithValue<?>) node).getValue());
}
@Override
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
/**
- * Client allocated result holder for {@link ImmutableNormalizedNodeStreamWriter}.
- * which produces instance of NormalizedNode.
+ * Client allocated result holder for {@link ImmutableNormalizedNodeStreamWriter} which produces instance
+ * of NormalizedNode.
*
- * Client may supply result holder to {@link ImmutableNormalizedNodeStreamWriter}
- * which will be once updated, when result is available.
- *
- * This is intended for using {@link ImmutableNormalizedNodeStreamWriter}
- * without supplying builder, so instantiated writer will select
- * correct builder based on first event and sets resulting
- * {@link NormalizedNode} when end event is invoked for node.
+ * <p>
+ * Client may supply result holder to {@link ImmutableNormalizedNodeStreamWriter} which will be once updated when
+ * the result is available.
*
+ * <p>
+ * This is intended for using {@link ImmutableNormalizedNodeStreamWriter} without supplying builder, so instantiated
+ * writer will select correct builder based on first event and sets resulting {@link NormalizedNode} when end event is
+ * invoked for node.
*/
public class NormalizedNodeResult {
-
private boolean finished = false;
private NormalizedNode<?,?> result;
public boolean isFinished() {
return finished;
}
-
}
public class ResultAlreadySetException extends IllegalStateException {
private static final long serialVersionUID = 1L;
+
private final NormalizedNode<?, ?> resultData;
public ResultAlreadySetException(final String message, final NormalizedNode<?, ?> resultData) {
this(message, resultData, null);
}
- public ResultAlreadySetException(final String message, final NormalizedNode<?, ?> resultData, final Throwable cause) {
+ public ResultAlreadySetException(final String message, final NormalizedNode<?, ?> resultData,
+ final Throwable cause) {
super(message, cause);
this.resultData = resultData;
}
import org.slf4j.LoggerFactory;
/**
- * This is an iterator over a {@link NormalizedNode}. Unlike {@link NormalizedNodeWriter},
- * this iterates over elements in order as they are defined in .yang file.
+ * This is an iterator over a {@link NormalizedNode}. Unlike {@link NormalizedNodeWriter}, this iterates over elements
+ * in the order as they are defined in YANG file.
*/
public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
private static final Logger LOG = LoggerFactory.getLogger(SchemaOrderedNormalizedNodeWriter.class);
currentSchemaNode = root;
}
return write(node, currentSchemaNode);
-
}
/**
}
throw new IllegalStateException("It wasn't possible to serialize nodes " + nodes);
-
}
- private SchemaOrderedNormalizedNodeWriter write(final NormalizedNode<?, ?> node, final SchemaNode dataSchemaNode) throws IOException {
+ private SchemaOrderedNormalizedNodeWriter write(final NormalizedNode<?, ?> node, final SchemaNode dataSchemaNode)
+ throws IOException {
//Set current schemaNode
try (SchemaNodeSetter sns = new SchemaNodeSetter(dataSchemaNode)) {
return writeChildren(children, currentSchemaNode, true);
}
- private boolean writeChildren(final Iterable<? extends NormalizedNode<?, ?>> children, final SchemaNode parentSchemaNode, final boolean endParent) throws IOException {
+ private boolean writeChildren(final Iterable<? extends NormalizedNode<?, ?>> children,
+ final SchemaNode parentSchemaNode, final boolean endParent) throws IOException {
//Augmentations cannot be gotten with node.getChild so create our own structure with augmentations resolved
final ArrayListMultimap<QName, NormalizedNode<?, ?>> qNameToNodes = ArrayListMultimap.create();
for (final NormalizedNode<?, ?> child : children) {
return resolvedAugs;
}
-
- private class SchemaNodeSetter implements AutoCloseable {
+ private final class SchemaNodeSetter implements AutoCloseable {
private final SchemaNode previousSchemaNode;
/**
- * Sets current schema node new value and store old value for later restore
+ * Sets current schema node new value and store old value for later restore.
*/
- public SchemaNodeSetter(final SchemaNode schemaNode) {
+ SchemaNodeSetter(final SchemaNode schemaNode) {
previousSchemaNode = SchemaOrderedNormalizedNodeWriter.this.currentSchemaNode;
SchemaOrderedNormalizedNodeWriter.this.currentSchemaNode = schemaNode;
}
/**
- * Restore previous schema node
+ * Restore previous schema node.
*/
@Override
public void close() {
SchemaOrderedNormalizedNodeWriter.this.currentSchemaNode = previousSchemaNode;
}
}
-
}
\ No newline at end of file
}
/**
- * @param qname - schema node to find
- * @param dataSchemaNode - iterable of schemaNodes to look through
- * @return - schema node with newest revision or absent if no schema node with matching qname is found
+ * Find the first schema with specified QName.
+ *
+ * @param qname schema node to find
+ * @param dataSchemaNode Iterable of schemaNodes to look through
+ * @return schema node with newest revision or absent if no schema node with matching qname is found
*/
- public static Optional<DataSchemaNode> findFirstSchema(final QName qname, final Iterable<DataSchemaNode> dataSchemaNode) {
- DataSchemaNode sNode = null;
+ public static Optional<DataSchemaNode> findFirstSchema(final QName qname,
+ final Iterable<DataSchemaNode> dataSchemaNode) {
+ DataSchemaNode schema = null;
if (dataSchemaNode != null && qname != null) {
for (final DataSchemaNode dsn : dataSchemaNode) {
if (qname.isEqualWithoutRevision(dsn.getQName())) {
- if (sNode == null || sNode.getQName().getRevision().compareTo(dsn.getQName().getRevision()) < 0) {
- sNode = dsn;
+ if (schema == null || schema.getQName().getRevision().compareTo(dsn.getQName().getRevision()) < 0) {
+ schema = dsn;
}
} else if (dsn instanceof ChoiceSchemaNode) {
for (final ChoiceCaseNode choiceCase : ((ChoiceSchemaNode) dsn).getCases()) {
}
}
}
- return Optional.fromNullable(sNode);
+ return Optional.fromNullable(schema);
}
/**
- *
- * Find child schema node identified by its QName within a provided schema node
+ * Find child schema node identified by its QName within a provided schema node.
*
* @param schema schema for parent node - search root
* @param qname qname(with or without a revision) of a child node to be found in the parent schema
* @throws java.lang.IllegalStateException if the child was not found in parent schema node
*/
public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname) {
- // Try to find child schema node directly, but use a fallback that compares QNames without revisions and auto-expands choices
+ // Try to find child schema node directly, but use a fallback that compares QNames without revisions
+ // and auto-expands choices
final DataSchemaNode dataChildByName = schema.getDataChildByName(qname);
return dataChildByName == null ? findSchemaForChild(schema, qname, schema.getChildNodes()) : dataChildByName;
}
@Nullable
- public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final boolean strictMode) {
+ public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname,
+ final boolean strictMode) {
if (strictMode) {
return findSchemaForChild(schema, qname);
}
return childSchemaOptional.get();
}
- public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final Iterable<DataSchemaNode> childNodes) {
+ public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname,
+ final Iterable<DataSchemaNode> childNodes) {
final Optional<DataSchemaNode> childSchema = findFirstSchema(qname, childNodes);
Preconditions.checkState(childSchema.isPresent(),
"Unknown child(ren) node(s) detected, identified by: %s, in: %s", qname, schema);
return childSchema.get();
}
- public static AugmentationSchema findSchemaForAugment(final AugmentationTarget schema, final Set<QName> qNames) {
- final Optional<AugmentationSchema> schemaForAugment = findAugment(schema, qNames);
- Preconditions.checkState(schemaForAugment.isPresent(), "Unknown augmentation node detected, identified by: %s, in: %s",
- qNames, schema);
+ public static DataSchemaNode findSchemaForChild(final ChoiceSchemaNode schema, final QName childPartialQName) {
+ for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
+ final Optional<DataSchemaNode> childSchema = findFirstSchema(childPartialQName,
+ choiceCaseNode.getChildNodes());
+ if (childSchema.isPresent()) {
+ return childSchema.get();
+ }
+ }
+
+
+ throw new IllegalStateException(String.format("Unknown child(ren) node(s) detected, identified by: %s, in: %s",
+ childPartialQName, schema));
+ }
+
+ public static AugmentationSchema findSchemaForAugment(final AugmentationTarget schema, final Set<QName> qnames) {
+ final Optional<AugmentationSchema> schemaForAugment = findAugment(schema, qnames);
+ Preconditions.checkState(schemaForAugment.isPresent(),
+ "Unknown augmentation node detected, identified by: %s, in: %s", qnames, schema);
return schemaForAugment.get();
}
- public static AugmentationSchema findSchemaForAugment(final ChoiceSchemaNode schema, final Set<QName> qNames) {
+ public static AugmentationSchema findSchemaForAugment(final ChoiceSchemaNode schema, final Set<QName> qnames) {
Optional<AugmentationSchema> schemaForAugment = Optional.absent();
for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
- schemaForAugment = findAugment(choiceCaseNode, qNames);
+ schemaForAugment = findAugment(choiceCaseNode, qnames);
if (schemaForAugment.isPresent()) {
break;
}
}
- Preconditions.checkState(schemaForAugment.isPresent(), "Unknown augmentation node detected, identified by: %s, in: %s",
- qNames, schema);
+ Preconditions.checkState(schemaForAugment.isPresent(),
+ "Unknown augmentation node detected, identified by: %s, in: %s", qnames, schema);
return schemaForAugment.get();
}
- private static Optional<AugmentationSchema> findAugment(final AugmentationTarget schema, final Set<QName> qNames) {
+ private static Optional<AugmentationSchema> findAugment(final AugmentationTarget schema, final Set<QName> qnames) {
for (final AugmentationSchema augment : schema.getAvailableAugmentations()) {
final HashSet<QName> qNamesFromAugment = Sets.newHashSet(Collections2.transform(augment.getChildNodes(),
DataSchemaNode::getQName));
- if (qNamesFromAugment.equals(qNames)) {
+ if (qNamesFromAugment.equals(qnames)) {
return Optional.of(augment);
}
}
return Optional.absent();
}
- public static DataSchemaNode findSchemaForChild(final ChoiceSchemaNode schema, final QName childPartialQName) {
- for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
- final Optional<DataSchemaNode> childSchema = findFirstSchema(childPartialQName, choiceCaseNode.getChildNodes());
- if (childSchema.isPresent()) {
- return childSchema.get();
- }
- }
-
-
- throw new IllegalStateException(String.format("Unknown child(ren) node(s) detected, identified by: %s, in: %s",
- childPartialQName, schema));
- }
-
/**
* Recursively find all child nodes that come from choices.
*
return mapChildElementsFromChoices(schema, schema.getChildNodes());
}
- private static Map<QName, ChoiceSchemaNode> mapChildElementsFromChoices(final DataNodeContainer schema, final Iterable<DataSchemaNode> childNodes) {
+ private static Map<QName, ChoiceSchemaNode> mapChildElementsFromChoices(final DataNodeContainer schema,
+ final Iterable<DataSchemaNode> childNodes) {
final Map<QName, ChoiceSchemaNode> mappedChoices = Maps.newLinkedHashMap();
for (final DataSchemaNode childSchema : childNodes) {
}
for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) {
-
- for (final QName qName : getChildNodesRecursive(choiceCaseNode)) {
- mappedChoices.put(qName, (ChoiceSchemaNode) childSchema);
+ for (final QName qname : getChildNodesRecursive(choiceCaseNode)) {
+ mappedChoices.put(qname, (ChoiceSchemaNode) childSchema);
}
}
}
for (final DataSchemaNode child : ((DataNodeContainer) schema).getChildNodes()) {
// If is not augmented child, continue
- if (!(augments.containsKey(child.getQName()))) {
+ if (!augments.containsKey(child.getQName())) {
continue;
}
// recursively add all child nodes in case of augment, case and choice
if (child instanceof AugmentationSchema || child instanceof ChoiceCaseNode) {
- for (final QName qName : getChildNodesRecursive((DataNodeContainer) child)) {
- childNodesToAugmentation.put(qName, mostTopAugmentation);
+ for (final QName qname : getChildNodesRecursive((DataNodeContainer) child)) {
+ childNodesToAugmentation.put(qname, mostTopAugmentation);
}
} else if (child instanceof ChoiceSchemaNode) {
for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) child).getCases()) {
- for (final QName qName : getChildNodesRecursive(choiceCaseNode)) {
- childNodesToAugmentation.put(qName, mostTopAugmentation);
+ for (final QName qname : getChildNodesRecursive(choiceCaseNode)) {
+ childNodesToAugmentation.put(qname, mostTopAugmentation);
}
}
} else {
// Choice Node has to map child nodes from all its cases
if (schema instanceof ChoiceSchemaNode) {
for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) schema).getCases()) {
- if (!(augments.containsKey(choiceCaseNode.getQName()))) {
+ if (!augments.containsKey(choiceCaseNode.getQName())) {
continue;
}
- for (final QName qName : getChildNodesRecursive(choiceCaseNode)) {
- childNodesToAugmentation.put(qName, augments.get(choiceCaseNode.getQName()));
+ for (final QName qname : getChildNodesRecursive(choiceCaseNode)) {
+ childNodesToAugmentation.put(qname, augments.get(choiceCaseNode.getQName()));
}
}
}
}
/**
- * Recursively list all child nodes.
- *
- * In case of choice, augment and cases, step in.
+ * Recursively list all child nodes. In case of choice, augment and cases, step in.
*
* @param nodeContainer node container
* @return set of QNames
}
} else if (childSchema instanceof AugmentationSchema || childSchema instanceof ChoiceCaseNode) {
allChildNodes.addAll(getChildNodesRecursive((DataNodeContainer) childSchema));
- }
- else {
+ } else {
allChildNodes.add(childSchema.getQName());
}
}
/**
* Retrieves real schemas for augmented child node.
*
+ * <p>
* Schema of the same child node from augment, and directly from target is not the same.
* Schema of child node from augment is incomplete, therefore its useless for XML/NormalizedNode translation.
*
* @param augmentSchema augment schema
* @return set of nodes
*/
- public static Set<DataSchemaNode> getRealSchemasForAugment(final AugmentationTarget targetSchema, final AugmentationSchema augmentSchema) {
- if (!(targetSchema.getAvailableAugmentations().contains(augmentSchema))) {
+ public static Set<DataSchemaNode> getRealSchemasForAugment(final AugmentationTarget targetSchema,
+ final AugmentationSchema augmentSchema) {
+ if (!targetSchema.getAvailableAugmentations().contains(augmentSchema)) {
return Collections.emptySet();
}
return realChildNodes;
}
- public static Optional<ChoiceCaseNode> detectCase(final ChoiceSchemaNode schema, final DataContainerChild<?, ?> child) {
+ public static Optional<ChoiceCaseNode> detectCase(final ChoiceSchemaNode schema,
+ final DataContainerChild<?, ?> child) {
for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
if (child instanceof AugmentationNode
&& belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())) {
return Optional.absent();
}
- public static boolean belongsToCaseAugment(final ChoiceCaseNode caseNode, final AugmentationIdentifier childToProcess) {
+ public static boolean belongsToCaseAugment(final ChoiceCaseNode caseNode,
+ final AugmentationIdentifier childToProcess) {
for (final AugmentationSchema augmentationSchema : caseNode.getAvailableAugmentations()) {
final Set<QName> currentAugmentChildNodes = Sets.newHashSet();
currentAugmentChildNodes.add(dataSchemaNode.getQName());
}
- if (childToProcess.getPossibleChildNames().equals(currentAugmentChildNodes)){
+ if (childToProcess.getPossibleChildNames().equals(currentAugmentChildNodes)) {
return true;
}
}
}
/**
- * Finds schema node for given path in schema context. This method performs
- * lookup in both the namespace of groupings and the namespace of all leafs,
- * leaf-lists, lists, containers, choices, rpcs, actions, notifications,
- * anydatas, and anyxmls according to Rfc6050/Rfc7950 section 6.2.1.
+ * Finds schema node for given path in schema context. This method performs lookup in both the namespace
+ * of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions,
+ * notifications, anydatas and anyxmls according to Rfc6050/Rfc7950 section 6.2.1.
*
- * This method is deprecated, because name conflicts can occur between the
- * namespace of groupings and namespace of data nodes and in consequence
- * lookup could be ambiguous.
+ * <p>
+ * This method is deprecated, because name conflicts can occur between the namespace of groupings and namespace
+ * of data nodes and in consequence lookup could be ambiguous.
*
* @param schemaContext
* schema context
* path
* @return schema node on path
*
- * @deprecated use
- * {@link #findParentSchemaNodesOnPath(SchemaContext, SchemaPath)}
- * instead.
+ * @deprecated Use {@link #findParentSchemaNodesOnPath(SchemaContext, SchemaPath)} instead.
*/
@Deprecated
public static SchemaNode findParentSchemaOnPath(final SchemaContext schemaContext, final SchemaPath path) {
}
/**
- * Find child data schema node identified by its QName within a provided
- * schema node. This method performs lookup in the namespace of all leafs,
- * leaf-lists, lists, containers, choices, rpcs, actions, notifications,
- * anydatas, and anyxmls according to Rfc6050/Rfc7950 section 6.2.1.
+ * Find child data schema node identified by its QName within a provided schema node. This method performs lookup
+ * in the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions, notifications, anydatas
+ * and anyxmls according to Rfc6050/Rfc7950 section 6.2.1.
*
* @param node
* schema node
* @param qname
* QName
* @return data child schema node
- * @throws java.lang.IllegalArgumentException
+ * @throws IllegalArgumentException
* if the schema node does not allow children
*/
@Nullable
child = ((ChoiceSchemaNode) node).getCaseNodeByName(qname);
} else if (node instanceof RpcDefinition) {
switch (qname.getLocalName()) {
- case "input":
- child = ((RpcDefinition) node).getInput();
- break;
- case "output":
- child = ((RpcDefinition) node).getOutput();
- break;
- default:
- child = null;
- break;
+ case "input":
+ child = ((RpcDefinition) node).getInput();
+ break;
+ case "output":
+ child = ((RpcDefinition) node).getOutput();
+ break;
+ default:
+ child = null;
+ break;
}
} else {
throw new IllegalArgumentException(String.format("Schema node %s does not allow children.", node));
}
/**
- * Find child schema node identified by its QName within a provided schema
- * node. This method performs lookup in both the namespace of groupings and
- * the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs,
- * actions, notifications, anydatas, and anyxmls according to
- * Rfc6050/Rfc7950 section 6.2.1.
+ * Find child schema node identified by its QName within a provided schema node. This method performs lookup
+ * in both the namespace of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs,
+ * actions, notifications, anydatas and anyxmls according to RFC6050/RFC7950 section 6.2.1.
*
- * This method is deprecated, because name conflicts can occur between the
- * namespace of groupings and namespace of data nodes and in consequence
- * lookup could be ambiguous.
+ * <p>
+ * This method is deprecated, because name conflicts can occur between the namespace of groupings and namespace
+ * of data nodes and in consequence lookup could be ambiguous.
*
* @param node
* schema node
* @param qname
* QName
* @return child schema node
- * @throws java.lang.IllegalArgumentException
+ * @throws IllegalArgumentException
* if the schema node does not allow children
*
- * @deprecated use
- * {@link #findChildSchemaNodesByQName(SchemaNode, QName)}
- * instead.
+ * @deprecated Use {@link #findChildSchemaNodesByQName(SchemaNode, QName)} instead.
*/
@Deprecated
public static SchemaNode findChildSchemaByQName(final SchemaNode node, final QName qname) {
}
/**
- * Finds schema node for given path in schema context. This method performs
- * lookup in both the namespace of groupings and the namespace of all leafs,
- * leaf-lists, lists, containers, choices, rpcs, actions, notifications,
- * anydatas, and anyxmls according to Rfc6050/Rfc7950 section 6.2.1.
+ * Finds schema node for given path in schema context. This method performs lookup in both the namespace
+ * of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions,
+ * notifications, anydatas and anyxmls according to Rfc6050/Rfc7950 section 6.2.1.
*
- * This method returns collection of SchemaNodes, because name conflicts can
- * occur between the namespace of groupings and namespace of data nodes.
- * This method finds and collects all schema nodes that matches supplied
+ * <p>
+ * This method returns collection of SchemaNodes, because name conflicts can occur between the namespace
+ * of groupings and namespace of data nodes. This method finds and collects all schema nodes that matches supplied
* SchemaPath and returns them all as collection of schema nodes.
*
* @param schemaContext
* @param path
* path
* @return collection of schema nodes on path
- *
*/
public static Collection<SchemaNode> findParentSchemaNodesOnPath(final SchemaContext schemaContext,
final SchemaPath path) {
}
/**
- * Find child schema node identified by its QName within a provided schema
- * node. This method performs lookup in both the namespace of groupings and
- * the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs,
- * actions, notifications, anydatas, and anyxmls according to
- * Rfc6050/Rfc7950 section 6.2.1.
+ * Find child schema node identified by its QName within a provided schema node. This method performs lookup in both
+ * the namespace of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs,
+ * actions, notifications, anydatas and anyxmls according to RFC6050/RFC7950 section 6.2.1.
*
- * This method returns collection of SchemaNodes, because name conflicts can
- * occur between the namespace of groupings and namespace of data nodes.
- * This method finds and collects all schema nodes with supplied QName and
- * returns them all as collection of schema nodes.
+ * <p>
+ * This method returns collection of SchemaNodes, because name conflicts can occur between the namespace
+ * of groupings and namespace of data nodes. This method finds and collects all schema nodes with supplied QName
+ * and returns them all as collection of schema nodes.
*
* @param node
* schema node
* @param qname
* QName
* @return collection of child schema nodes
- * @throws java.lang.IllegalArgumentException
+ * @throws IllegalArgumentException
* if the schema node does not allow children
- *
*/
public static Collection<SchemaNode> findChildSchemaNodesByQName(final SchemaNode node, final QName qname) {
final List<SchemaNode> childNodes = new ArrayList<>();
}
private static Optional<SchemaNode> tryFindAction(final ActionNodeContainer actionContanier, final QName qname) {
- return Optional.fromNullable(Iterables.find(actionContanier.getActions(), new SchemaNodePredicate(qname), null));
+ return Optional.fromNullable(Iterables.find(actionContanier.getActions(), new SchemaNodePredicate(qname),
+ null));
}
private static final class SchemaNodePredicate implements Predicate<SchemaNode> {
private final QName qname;
- public SchemaNodePredicate(final QName qname) {
+ SchemaNodePredicate(final QName qname) {
this.qname = qname;
}
return input.getQName().equals(qname);
}
}
-
}
CollectionNodeBuilder<V, R> withNodeIdentifier(NodeIdentifier nodeIdentifier);
CollectionNodeBuilder<V, R> withChild(V child);
+
CollectionNodeBuilder<V, R> withoutChild(PathArgument key);
}
DataContainerNodeBuilder<I, R> withNodeIdentifier(I nodeIdentifier);
DataContainerNodeBuilder<I, R> withChild(DataContainerChild<?, ?> child);
+
DataContainerNodeBuilder<I, R> withoutChild(PathArgument key);
}
\ No newline at end of file
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-public interface NormalizedNodeContainerBuilder<K extends PathArgument,CK extends PathArgument,CV extends NormalizedNode<? extends CK, ?>,P extends NormalizedNode<K, ?>> extends NormalizedNodeBuilder<K,Collection<CV>,P>{
+public interface NormalizedNodeContainerBuilder<K extends PathArgument, CK extends PathArgument,
+ CV extends NormalizedNode<? extends CK, ?>, P extends NormalizedNode<K, ?>>
+ extends NormalizedNodeBuilder<K, Collection<CV>, P> {
@Override
NormalizedNodeContainerBuilder<K,CK,CV,P> withNodeIdentifier(K nodeIdentifier);
NormalizedNodeContainerBuilder<K,CK,CV,P> withValue(Collection<CV> value);
NormalizedNodeContainerBuilder<K,CK,CV,P> addChild(CV child);
+
NormalizedNodeContainerBuilder<K,CK,CV,P> removeChild(CK key);
}
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerAttrNode;
-abstract class AbstractImmutableDataContainerNodeAttrBuilder<I extends PathArgument, R extends DataContainerNode<I>> extends AbstractImmutableDataContainerNodeBuilder<I, R> implements DataContainerNodeAttrBuilder<I, R> {
+abstract class AbstractImmutableDataContainerNodeAttrBuilder<I extends PathArgument, R extends DataContainerNode<I>>
+ extends AbstractImmutableDataContainerNodeBuilder<I, R> implements DataContainerNodeAttrBuilder<I, R> {
private Map<QName, String> attributes;
- protected AbstractImmutableDataContainerNodeAttrBuilder() {
+ AbstractImmutableDataContainerNodeAttrBuilder() {
this.attributes = Collections.emptyMap();
}
- protected AbstractImmutableDataContainerNodeAttrBuilder(final int sizeHint) {
+ AbstractImmutableDataContainerNodeAttrBuilder(final int sizeHint) {
super(sizeHint);
this.attributes = Collections.emptyMap();
}
- protected AbstractImmutableDataContainerNodeAttrBuilder(final AbstractImmutableDataContainerAttrNode<I> node) {
+ AbstractImmutableDataContainerNodeAttrBuilder(final AbstractImmutableDataContainerAttrNode<I> node) {
super(node);
this.attributes = node.getAttributes();
}
}
@Override
- public DataContainerNodeAttrBuilder<I, R> withAttributes(final Map<QName, String> attributes){
+ public DataContainerNodeAttrBuilder<I, R> withAttributes(final Map<QName, String> attributes) {
this.attributes = attributes;
return this;
}
@Override
- public DataContainerNodeAttrBuilder<I, R> withValue(final Collection<DataContainerChild<? extends PathArgument, ?>> value) {
+ public DataContainerNodeAttrBuilder<I, R> withValue(
+ final Collection<DataContainerChild<? extends PathArgument, ?>> value) {
return (DataContainerNodeAttrBuilder<I, R>) super.withValue(value);
}
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.CloneableMap;
-abstract class AbstractImmutableDataContainerNodeBuilder<I extends PathArgument, R extends DataContainerNode<I>> implements DataContainerNodeBuilder<I, R> {
+abstract class AbstractImmutableDataContainerNodeBuilder<I extends PathArgument, R extends DataContainerNode<I>>
+ implements DataContainerNodeBuilder<I, R> {
private static final int DEFAULT_CAPACITY = 4;
private Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> value;
private I nodeIdentifier;
protected final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> buildValue() {
if (value instanceof ModifiableMapPhase) {
- return ((ModifiableMapPhase<PathArgument, DataContainerChild<? extends PathArgument, ?>>)value).toUnmodifiableMap();
+ return ((ModifiableMapPhase<PathArgument, DataContainerChild<? extends PathArgument, ?>>)value)
+ .toUnmodifiableMap();
}
dirty = true;
private void checkDirty() {
if (dirty) {
if (value instanceof UnmodifiableMapPhase) {
- value = ((UnmodifiableMapPhase<PathArgument, DataContainerChild<? extends PathArgument, ?>>) value).toModifiableMap();
+ value = ((UnmodifiableMapPhase<PathArgument, DataContainerChild<? extends PathArgument, ?>>) value)
+ .toModifiableMap();
} else if (value instanceof CloneableMap) {
- value = ((CloneableMap<PathArgument, DataContainerChild<? extends PathArgument, ?>>) value).createMutableClone();
+ value = ((CloneableMap<PathArgument, DataContainerChild<? extends PathArgument, ?>>) value)
+ .createMutableClone();
} else {
value = new HashMap<>(value);
}
}
@Override
- public DataContainerNodeBuilder<I, R> withValue(final Collection<DataContainerChild<? extends PathArgument, ?>> value) {
+ public DataContainerNodeBuilder<I, R> withValue(
+ final Collection<DataContainerChild<? extends PathArgument, ?>> value) {
// TODO Replace or putAll ?
for (final DataContainerChild<? extends PathArgument, ?> dataContainerChild : value) {
withChild(dataContainerChild);
}
@Override
- public NormalizedNodeContainerBuilder<I, PathArgument, DataContainerChild<? extends PathArgument, ?>, R> removeChild(final PathArgument key) {
+ public NormalizedNodeContainerBuilder<I, PathArgument, DataContainerChild<? extends PathArgument, ?>, R>
+ removeChild(final PathArgument key) {
return withoutChild(key);
}
}
}
@Override
- public NormalizedNodeAttrBuilder<I,V,R> withAttributes(final Map<QName, String> attributes){
+ public NormalizedNodeAttrBuilder<I,V,R> withAttributes(final Map<QName, String> attributes) {
this.attributes = attributes;
return this;
}
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
-public class ImmutableAnyXmlNodeBuilder extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, DOMSource, AnyXmlNode> {
+public class ImmutableAnyXmlNodeBuilder
+ extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, DOMSource, AnyXmlNode> {
public static NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> create() {
return new ImmutableAnyXmlNodeBuilder();
return new ImmutableXmlNode(getNodeIdentifier(), getValue(), getAttributes());
}
- private static final class ImmutableXmlNode extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, DOMSource> implements AnyXmlNode {
+ private static final class ImmutableXmlNode
+ extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, DOMSource> implements AnyXmlNode {
- ImmutableXmlNode(final NodeIdentifier nodeIdentifier, final DOMSource value, final Map<QName, String> attributes) {
+ ImmutableXmlNode(final NodeIdentifier nodeIdentifier, final DOMSource value,
+ final Map<QName, String> attributes) {
super(nodeIdentifier, value, attributes);
}
}
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
}
- public static NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> create(final AnyXmlSchemaNode schema) {
+ public static NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> create(
+ final AnyXmlSchemaNode schema) {
return new ImmutableAnyXmlNodeSchemaAwareBuilder(schema);
}
}
@Override
- public NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
+ public NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> withNodeIdentifier(
+ final NodeIdentifier nodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
-public class ImmutableAugmentationNodeBuilder extends AbstractImmutableDataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> {
+public class ImmutableAugmentationNodeBuilder
+ extends AbstractImmutableDataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> {
protected ImmutableAugmentationNodeBuilder() {
super();
return new ImmutableAugmentationNodeBuilder(sizeHint);
}
- public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(final AugmentationNode node) {
+ public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(
+ final AugmentationNode node) {
if (!(node instanceof ImmutableAugmentationNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
return new ImmutableAugmentationNode(getNodeIdentifier(), buildValue());
}
- private static final class ImmutableAugmentationNode extends AbstractImmutableDataContainerNode<AugmentationIdentifier> implements AugmentationNode {
+ private static final class ImmutableAugmentationNode
+ extends AbstractImmutableDataContainerNode<AugmentationIdentifier> implements AugmentationNode {
- ImmutableAugmentationNode(final AugmentationIdentifier nodeIdentifier, final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children) {
+ ImmutableAugmentationNode(final AugmentationIdentifier nodeIdentifier,
+ final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children) {
super(children, nodeIdentifier);
}
}
-
}
}
@Override
- public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withNodeIdentifier(final AugmentationIdentifier nodeIdentifier) {
+ public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withNodeIdentifier(
+ final AugmentationIdentifier nodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
@Override
- public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(final DataContainerChild<?, ?> child) {
+ public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(
+ final DataContainerChild<?, ?> child) {
return super.withChild(validator.validateChild(child));
}
- public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(final AugmentationSchema schema) {
+ public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(
+ final AugmentationSchema schema) {
return new ImmutableAugmentationNodeSchemaAwareBuilder(schema);
}
-
-
}
public class ImmutableChoiceNodeBuilder extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, ChoiceNode> {
protected ImmutableChoiceNodeBuilder() {
- super();
+
}
protected ImmutableChoiceNodeBuilder(final int sizeHint) {
return new ImmutableChoiceNode(getNodeIdentifier(), buildValue());
}
- private static final class ImmutableChoiceNode extends AbstractImmutableDataContainerNode<NodeIdentifier> implements ChoiceNode {
+ private static final class ImmutableChoiceNode extends AbstractImmutableDataContainerNode<NodeIdentifier>
+ implements ChoiceNode {
ImmutableChoiceNode(final NodeIdentifier nodeIdentifier,
final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children) {
}
@Override
- public DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
+ public DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> withNodeIdentifier(
+ final NodeIdentifier nodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerAttrNode;
-public class ImmutableContainerNodeBuilder extends AbstractImmutableDataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> {
+public class ImmutableContainerNodeBuilder
+ extends AbstractImmutableDataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> {
protected ImmutableContainerNodeBuilder() {
- super();
+
}
protected ImmutableContainerNodeBuilder(final int sizeHint) {
return new ImmutableContainerNode(getNodeIdentifier(), buildValue(), getAttributes());
}
- protected static final class ImmutableContainerNode extends AbstractImmutableDataContainerAttrNode<NodeIdentifier> implements ContainerNode {
+ protected static final class ImmutableContainerNode extends AbstractImmutableDataContainerAttrNode<NodeIdentifier>
+ implements ContainerNode {
- ImmutableContainerNode(
- final NodeIdentifier nodeIdentifier,
+ ImmutableContainerNode(final NodeIdentifier nodeIdentifier,
final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children,
final Map<QName, String> attributes) {
super(children, nodeIdentifier, attributes);
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
}
- private ImmutableContainerNodeSchemaAwareBuilder(final ContainerSchemaNode schema, final ImmutableContainerNode node) {
+ private ImmutableContainerNodeSchemaAwareBuilder(final ContainerSchemaNode schema,
+ final ImmutableContainerNode node) {
super(node);
this.validator = new DataNodeContainerValidator(schema);
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
return new ImmutableContainerNodeSchemaAwareBuilder(schema);
}
- public static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> create(final ContainerSchemaNode schema, final ContainerNode node) {
+ public static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> create(final ContainerSchemaNode schema,
+ final ContainerNode node) {
if (!(node instanceof ImmutableContainerNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
}
@Override
- public DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
+ public DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> withNodeIdentifier(
+ final NodeIdentifier nodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
-public class ImmutableLeafNodeBuilder<T> extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> {
+public class ImmutableLeafNodeBuilder<T>
+ extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> {
public static <T> NormalizedNodeAttrBuilder<NodeIdentifier, T, LeafNode<T>> create() {
return new ImmutableLeafNodeBuilder<>();
@Override
public NormalizedNodeAttrBuilder<NodeIdentifier, T, LeafNode<T>> withValue(final T value) {
-// TODO check value type
+ // TODO: check value type
return super.withValue(value);
}
@Override
- public NormalizedNodeAttrBuilder<NodeIdentifier, T, LeafNode<T>> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
+ public NormalizedNodeAttrBuilder<NodeIdentifier, T, LeafNode<T>> withNodeIdentifier(
+ final NodeIdentifier nodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
-public class ImmutableLeafSetEntryNodeBuilder<T> extends AbstractImmutableNormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> {
+public class ImmutableLeafSetEntryNodeBuilder<T>
+ extends AbstractImmutableNormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> {
public static <T> ImmutableLeafSetEntryNodeBuilder<T> create() {
return new ImmutableLeafSetEntryNodeBuilder<>();
return new ImmutableLeafSetEntryNode<>(getNodeIdentifier(), getValue(), getAttributes());
}
- private static final class ImmutableLeafSetEntryNode<T> extends AbstractImmutableNormalizedValueAttrNode<NodeWithValue, T> implements LeafSetEntryNode<T> {
+ private static final class ImmutableLeafSetEntryNode<T>
+ extends AbstractImmutableNormalizedValueAttrNode<NodeWithValue, T> implements LeafSetEntryNode<T> {
- ImmutableLeafSetEntryNode(final NodeWithValue nodeIdentifier, final T value, final Map<QName, String> attributes) {
+ ImmutableLeafSetEntryNode(final NodeWithValue nodeIdentifier, final T value,
+ final Map<QName, String> attributes) {
super(nodeIdentifier, value, attributes);
Preconditions.checkArgument(Objects.deepEquals(nodeIdentifier.getValue(), value),
"Node identifier contains different value: %s than value itself: %s", nodeIdentifier, value);
this.schema = Preconditions.checkNotNull(schema);
}
- public static <T> NormalizedNodeAttrBuilder<NodeWithValue, T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema) {
+ public static <T> NormalizedNodeAttrBuilder<NodeWithValue, T, LeafSetEntryNode<T>> create(
+ final LeafListSchemaNode schema) {
return new ImmutableLeafSetEntryNodeSchemaAwareBuilder<>(schema);
}
}
@Override
- public NormalizedNodeAttrBuilder<NodeWithValue, T, LeafSetEntryNode<T>> withNodeIdentifier(final NodeWithValue nodeIdentifier) {
+ public NormalizedNodeAttrBuilder<NodeWithValue, T, LeafSetEntryNode<T>> withNodeIdentifier(
+ final NodeWithValue nodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, LeafSetEntryNode<T>> {
private static final int DEFAULT_CAPACITY = 4;
+
private final Map<NodeWithValue, LeafSetEntryNode<T>> value;
private NodeIdentifier nodeIdentifier;
return withChildValue(value, Collections.emptyMap());
}
- protected final static class ImmutableLeafSetNode<T> extends
+ protected static final class ImmutableLeafSetNode<T> extends
AbstractImmutableNormalizedValueNode<NodeIdentifier, Collection<LeafSetEntryNode<T>>> implements
Immutable, LeafSetNode<T> {
private final Map<NodeWithValue, LeafSetEntryNode<T>> children;
- ImmutableLeafSetNode(final NodeIdentifier nodeIdentifier, final Map<NodeWithValue, LeafSetEntryNode<T>> children) {
+ ImmutableLeafSetNode(final NodeIdentifier nodeIdentifier,
+ final Map<NodeWithValue, LeafSetEntryNode<T>> children) {
super(nodeIdentifier, UnmodifiableCollection.create(children.values()));
this.children = children;
}
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>> removeChild(
- final PathArgument key) {
+ public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>>
+ removeChild(final PathArgument key) {
return withoutChild(key);
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-import com.google.common.collect.Sets;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import com.google.common.base.Preconditions;
+import java.util.Collections;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import com.google.common.base.Preconditions;
-
public final class ImmutableLeafSetNodeSchemaAwareBuilder<T> extends ImmutableLeafSetNodeBuilder<T> {
private final LeafListSchemaNode schema;
private ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
this.schema = Preconditions.checkNotNull(schema);
- super.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
+ super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
}
public ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema, final ImmutableLeafSetNode<T> node) {
super(node);
this.schema = Preconditions.checkNotNull(schema);
// FIXME: Preconditions.checkArgument(schema.getQName().equals(node.getIdentifier()));
- super.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
+ super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
}
public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema) {
return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema);
}
- public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema, final LeafSetNode<T> node) {
+ public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema,
+ final LeafSetNode<T> node) {
if (!(node instanceof ImmutableLeafSetNode<?>)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
Preconditions.checkArgument(schema.getQName().equals(child.getNodeType()),
"Incompatible node type, should be: %s, is: %s", schema.getQName(), child.getNodeType());
// TODO check value type using TypeProvider ?
- DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(), schema, Sets.newHashSet(schema.getQName()));
+ DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
+ schema, Collections.singleton(schema.getQName()));
return super.withChild(child);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final YangInstanceIdentifier.NodeIdentifier nodeIdentifier) {
+ public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ImmutableMapEntryNodeBuilder extends AbstractImmutableDataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> {
+public class ImmutableMapEntryNodeBuilder
+ extends AbstractImmutableDataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> {
private static final Logger LOG = LoggerFactory.getLogger(ImmutableMapEntryNodeBuilder.class);
protected final Map<QName, PathArgument> childrenQNamesToPaths;
return new ImmutableMapEntryNodeBuilder(sizeHint);
}
- public static DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> create(final MapEntryNode node) {
+ public static DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> create(
+ final MapEntryNode node) {
if (!(node instanceof ImmutableMapEntryNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
return new ImmutableMapEntryNodeBuilder((ImmutableMapEntryNode)node);
}
- private static void fillQnames(final Iterable<DataContainerChild<? extends PathArgument, ?>> iterable, final Map<QName, PathArgument> out) {
+ private static void fillQnames(final Iterable<DataContainerChild<? extends PathArgument, ?>> iterable,
+ final Map<QName, PathArgument> out) {
for (final DataContainerChild<? extends PathArgument, ?> childId : iterable) {
final PathArgument identifier = childId.getIdentifier();
@Override
- public DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> withValue(final Collection<DataContainerChild<? extends PathArgument, ?>> value) {
+ public DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> withValue(
+ final Collection<DataContainerChild<? extends PathArgument, ?>> value) {
fillQnames(value, childrenQNamesToPaths);
return super.withValue(value);
}
}
@Override
- public DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> withChild(final DataContainerChild<?, ?> child) {
+ public DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> withChild(
+ final DataContainerChild<?, ?> child) {
// Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
if (!isAugment(child.getIdentifier())) {
childrenQNamesToPaths.put(child.getNodeType(), child.getIdentifier());
LOG.debug("Adding leaf {} implied by key {}", leaf, key);
withChild(leaf);
} else {
- DataValidationException.checkListKey(getNodeIdentifier(), key.getKey(), key.getValue(), childNode.getValue());
+ DataValidationException.checkListKey(getNodeIdentifier(), key.getKey(), key.getValue(),
+ childNode.getValue());
}
}
return new ImmutableMapEntryNode(getNodeIdentifier(), buildValue(), getAttributes());
}
- private static final class ImmutableMapEntryNode extends AbstractImmutableDataContainerAttrNode<NodeIdentifierWithPredicates> implements MapEntryNode {
+ private static final class ImmutableMapEntryNode
+ extends AbstractImmutableDataContainerAttrNode<NodeIdentifierWithPredicates> implements MapEntryNode {
ImmutableMapEntryNode(final NodeIdentifierWithPredicates nodeIdentifier,
- final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children, final Map<QName, String> attributes) {
+ final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children,
+ final Map<QName, String> attributes) {
super(children, nodeIdentifier, attributes);
}
}
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-public final class ImmutableMapEntryNodeSchemaAwareBuilder extends ImmutableMapEntryNodeBuilder{
+public final class ImmutableMapEntryNodeSchemaAwareBuilder extends ImmutableMapEntryNodeBuilder {
private final ListSchemaNode schema;
private final DataNodeContainerValidator validator;
- protected ImmutableMapEntryNodeSchemaAwareBuilder(final ListSchemaNode schema) {
+ ImmutableMapEntryNodeSchemaAwareBuilder(final ListSchemaNode schema) {
this.schema = Preconditions.checkNotNull(schema);
this.validator = new DataNodeContainerValidator(schema);
}
}
@Override
- public DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> withChild(final DataContainerChild<?, ?> child) {
+ public DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> withChild(
+ final DataContainerChild<?, ?> child) {
validator.validateChild(child.getIdentifier());
return super.withChild(child);
}
}
/**
- * Build map entry node identifier from schema, and provided children
+ * Build map entry node identifier from schema and provided children.
*/
private NodeIdentifierWithPredicates constructNodeIdentifier() {
Collection<QName> keys = schema.getKeyDefinition();
return new NodeIdentifierWithPredicates(schema.getQName(), keysToValues);
}
- public static DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> create(final ListSchemaNode schema) {
+ public static DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> create(
+ final ListSchemaNode schema) {
return new ImmutableMapEntryNodeSchemaAwareBuilder(schema);
}
-
}
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.util.MapAdaptor;
import org.opendaylight.yangtools.util.UnmodifiableCollection;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
public class ImmutableMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, MapNode> {
private static final int DEFAULT_CAPACITY = 4;
+
private final Map<NodeIdentifierWithPredicates, MapEntryNode> value;
private NodeIdentifier nodeIdentifier;
return withoutChild(key);
}
- protected static final class ImmutableMapNode extends AbstractImmutableNormalizedNode<YangInstanceIdentifier.NodeIdentifier, Collection<MapEntryNode>> implements Immutable,MapNode {
+ protected static final class ImmutableMapNode
+ extends AbstractImmutableNormalizedNode<NodeIdentifier, Collection<MapEntryNode>>
+ implements Immutable, MapNode {
- private final Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> children;
+ private final Map<NodeIdentifierWithPredicates, MapEntryNode> children;
- ImmutableMapNode(final YangInstanceIdentifier.NodeIdentifier nodeIdentifier,
- final Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> children) {
+ ImmutableMapNode(final NodeIdentifier nodeIdentifier,
+ final Map<NodeIdentifierWithPredicates, MapEntryNode> children) {
super(nodeIdentifier);
this.children = children;
}
@Override
- public Optional<MapEntryNode> getChild(final YangInstanceIdentifier.NodeIdentifierWithPredicates child) {
+ public Optional<MapEntryNode> getChild(final NodeIdentifierWithPredicates child) {
return Optional.fromNullable(children.get(child));
}
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
+import java.util.Collections;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
@Override
public CollectionNodeBuilder<MapEntryNode, MapNode> withChild(final MapEntryNode child) {
- DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(), schema, Sets.newHashSet(schema.getQName()));
+ DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
+ schema, Collections.singleton(schema.getQName()));
return super.withChild(child);
}
return Optional.fromNullable(children.get(child));
}
+ @Override
+ public LeafSetEntryNode<T> getChild(final int position) {
+ return Iterables.get(children.values(), position);
+ }
+
@Override
protected int valueHashCode() {
return children.hashCode();
return children.equals(((ImmutableOrderedLeafSetNode<?>) other).children);
}
- @Override
- public LeafSetEntryNode<T> getChild(final int position) {
- return Iterables.get(children.values(), position);
- }
-
@Override
public int getSize() {
return children.size();
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>> removeChild(
- final PathArgument key) {
+ public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>>
+ removeChild(final PathArgument key) {
return withoutChild(key);
}
-
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import com.google.common.base.Preconditions;
-
public final class ImmutableOrderedLeafSetNodeSchemaAwareBuilder<T> extends ImmutableOrderedLeafSetNodeBuilder<T> {
private final LeafListSchemaNode schema;
private ImmutableOrderedLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
this.schema = Preconditions.checkNotNull(schema);
- super.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
+ super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
}
- public ImmutableOrderedLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema, final ImmutableOrderedLeafSetNode<T> node) {
+ public ImmutableOrderedLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema,
+ final ImmutableOrderedLeafSetNode<T> node) {
super(node);
this.schema = Preconditions.checkNotNull(schema);
// FIXME: Preconditions.checkArgument(schema.getQName().equals(node.getIdentifier()));
- super.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
+ super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
}
public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema) {
return new ImmutableOrderedLeafSetNodeSchemaAwareBuilder<>(schema);
}
- public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema, final LeafSetNode<T> node) {
+ public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema,
+ final LeafSetNode<T> node) {
if (!(node instanceof ImmutableOrderedLeafSetNode<?>)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
Preconditions.checkArgument(schema.getQName().equals(child.getNodeType()),
"Incompatible node type, should be: %s, is: %s", schema.getQName(), child.getNodeType());
// TODO check value type using TypeProvider ?
- DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(), schema, Sets.newHashSet(schema.getQName()));
+ DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
+ schema, Sets.newHashSet(schema.getQName()));
return super.withChild(child);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final YangInstanceIdentifier.NodeIdentifier nodeIdentifier) {
+ public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
public class ImmutableOrderedMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, OrderedMapNode> {
private static final int DEFAULT_CAPACITY = 4;
+
private Map<NodeIdentifierWithPredicates, MapEntryNode> value;
private NodeIdentifier nodeIdentifier;
private boolean dirty;
return withoutChild(key);
}
- protected static final class ImmutableOrderedMapNode extends AbstractImmutableNormalizedNode<NodeIdentifier, Collection<MapEntryNode>> implements Immutable, OrderedMapNode {
+ protected static final class ImmutableOrderedMapNode
+ extends AbstractImmutableNormalizedNode<NodeIdentifier, Collection<MapEntryNode>>
+ implements Immutable, OrderedMapNode {
private final Map<NodeIdentifierWithPredicates, MapEntryNode> children;
return Optional.fromNullable(children.get(child));
}
+ @Override
+ public MapEntryNode getChild(final int position) {
+ return Iterables.get(children.values(), position);
+ }
+
@Override
protected int valueHashCode() {
return children.hashCode();
return children.equals(((ImmutableOrderedMapNode) other).children);
}
- @Override
- public MapEntryNode getChild(final int position) {
- return Iterables.get(children.values(), position);
- }
-
@Override
public int getSize() {
return children.size();
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
+import java.util.Collections;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
}
- protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema, final ImmutableOrderedMapNode node) {
+ protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema,
+ final ImmutableOrderedMapNode node) {
super(node);
this.schema = Preconditions.checkNotNull(schema);
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
@Override
public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withChild(final MapEntryNode child) {
- DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(), schema, Sets.newHashSet(schema.getQName()));
+ DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
+ schema, Collections.singleton(schema.getQName()));
return super.withChild(child);
}
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerAttrNode;
-public class ImmutableUnkeyedListEntryNodeBuilder extends AbstractImmutableDataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> {
+public class ImmutableUnkeyedListEntryNodeBuilder
+ extends AbstractImmutableDataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> {
protected ImmutableUnkeyedListEntryNodeBuilder() {
- super();
+
}
protected ImmutableUnkeyedListEntryNodeBuilder(final int sizeHint) {
return new ImmutableUnkeyedListEntryNodeBuilder(sizeHint);
}
- public static DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> create(final UnkeyedListEntryNode node) {
+ public static DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> create(
+ final UnkeyedListEntryNode node) {
if (!(node instanceof ImmutableUnkeyedListEntryNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
return new ImmutableUnkeyedListEntryNode(getNodeIdentifier(), buildValue(), getAttributes());
}
- protected static final class ImmutableUnkeyedListEntryNode extends AbstractImmutableDataContainerAttrNode<NodeIdentifier> implements UnkeyedListEntryNode {
+ protected static final class ImmutableUnkeyedListEntryNode
+ extends AbstractImmutableDataContainerAttrNode<NodeIdentifier> implements UnkeyedListEntryNode {
- ImmutableUnkeyedListEntryNode(
- final NodeIdentifier nodeIdentifier,
+ ImmutableUnkeyedListEntryNode(final NodeIdentifier nodeIdentifier,
final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children,
final Map<QName, String> attributes) {
super(children, nodeIdentifier, attributes);
protected ImmutableUnkeyedListNodeBuilder(final ImmutableUnkeyedListNode node) {
this.nodeIdentifier = node.getIdentifier();
+ // FIXME: clean this up, notably reuse unmodified lists
this.value = new LinkedList<>();
Iterables.addAll(value, node.getValue());
this.dirty = true;
}
@Override
- public CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> withValue(final Collection<UnkeyedListEntryNode> value) {
+ public CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> withValue(
+ final Collection<UnkeyedListEntryNode> value) {
// TODO replace or putAll ?
- for (final UnkeyedListEntryNode UnkeyedListEntryNode : value) {
- withChild(UnkeyedListEntryNode);
+ for (final UnkeyedListEntryNode node : value) {
+ withChild(node);
}
return this;
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, UnkeyedListEntryNode, UnkeyedListNode> removeChild(
- final PathArgument key) {
+ public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, UnkeyedListEntryNode, UnkeyedListNode>
+ removeChild(final PathArgument key) {
return withoutChild(key);
}
this.contentSchema = yangModeledAnyXMLSchemaNode.getSchemaOfAnyXmlData();
}
- private ImmutableYangModeledAnyXmlNodeBuilder(final YangModeledAnyXmlSchemaNode yangModeledAnyXMLSchemaNode, final int sizeHint) {
+ private ImmutableYangModeledAnyXmlNodeBuilder(final YangModeledAnyXmlSchemaNode yangModeledAnyXMLSchemaNode,
+ final int sizeHint) {
super(sizeHint);
Preconditions.checkNotNull(yangModeledAnyXMLSchemaNode, "Yang modeled any xml node must not be null.");
super.withNodeIdentifier(NodeIdentifier.create(yangModeledAnyXMLSchemaNode.getQName()));
final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> value,
final Map<QName, String> attributes, final ContainerSchemaNode contentSchema) {
super(value, nodeIdentifier, attributes);
- this.contentSchema = Preconditions.checkNotNull(contentSchema, "Schema of yang modeled anyXml content cannot be null.");
+ this.contentSchema = Preconditions.checkNotNull(contentSchema,
+ "Schema of yang modeled anyXml content cannot be null.");
}
@Nonnull
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
import java.util.HashSet;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
* General validator for container like statements, e.g. container, list-entry, choice, augment
*/
public class DataNodeContainerValidator {
-
+ private final Set<AugmentationIdentifier> augments = new HashSet<>();
private final DataNodeContainer schema;
private final Set<QName> childNodes;
- private final Set<AugmentationIdentifier> augments = new HashSet<>();
public DataNodeContainerValidator(final DataNodeContainer schema) {
this.schema = Preconditions.checkNotNull(schema, "Schema was null");
}
/**
- * Map all direct child nodes. Skip augments since they have no qname. List cases since cases do not exist in NormalizedNode API.
+ * Map all direct child nodes. Skip augments since they have no qname. List cases since cases do not exist in
+ * NormalizedNode API.
*/
private static Set<QName> getChildNodes(final DataNodeContainer nodeContainer) {
- Set<QName> allChildNodes = Sets.newHashSet();
+ Set<QName> allChildNodes = new HashSet<>();
for (DataSchemaNode childSchema : nodeContainer.getChildNodes()) {
if (childSchema instanceof ChoiceCaseNode) {
return allChildNodes;
}
-
}
}
}
- public static void checkLegalData(final boolean isLegal, final String messageTemplate, final Object... messageAttrs) {
+ public static void checkLegalData(final boolean isLegal, final String messageTemplate,
+ final Object... messageAttrs) {
if (!isLegal) {
throw new DataValidationException(String.format(messageTemplate, messageAttrs));
}
}
- public static void checkListKey(final NodeIdentifierWithPredicates nodeId, final QName keyQName, final Object expected, final Object actual) {
+ public static void checkListKey(final NodeIdentifierWithPredicates nodeId, final QName keyQName,
+ final Object expected, final Object actual) {
// Objects.equals() does not deal with arrays, but is faster
if (!Objects.equals(expected, actual) && !Objects.deepEquals(expected, actual)) {
throw new IllegalListKeyException(keyQName, nodeId, actual, expected);
}
}
- public static void checkListKey(final DataContainerChild<?, ?> childNode, final Map<QName, Object> keyValues, final QName keyQName,
- final NodeIdentifierWithPredicates nodeId) {
+ public static void checkListKey(final DataContainerChild<?, ?> childNode, final Map<QName, Object> keyValues,
+ final QName keyQName, final NodeIdentifierWithPredicates nodeId) {
checkListKey(childNode, keyQName, nodeId);
final Object expected = keyValues.get(keyQName);
checkListKey(nodeId, keyQName, expected, actual);
}
- public static void checkListKey(final DataContainerChild<?, ?> childNode, final QName keyQName, final NodeIdentifierWithPredicates nodeId) {
+ public static void checkListKey(final DataContainerChild<?, ?> childNode, final QName keyQName,
+ final NodeIdentifierWithPredicates nodeId) {
if (childNode == null) {
throw new IllegalListKeyException(keyQName, nodeId);
}
super(String.format("Unknown child node: %s, not detected in choice: %s", child, schema));
}
- private IllegalChildException(final PathArgument child, final DataSchemaNode schema, final Set<QName> childNodes) {
- super(String.format("Unknown child node: %s, does not belong to: %s as a child. "
- + "Child nodes: %s", child, schema, childNodes));
+ private IllegalChildException(final PathArgument child, final DataSchemaNode schema,
+ final Set<QName> childNodes) {
+ super(String.format("Unknown child node: %s, does not belong to: %s as a child. Child nodes: %s", child,
+ schema, childNodes));
}
}
private static final class IllegalListKeyException extends DataValidationException {
private static final long serialVersionUID = 1L;
- private IllegalListKeyException(final QName keyQName, final NodeIdentifierWithPredicates id) {
+ IllegalListKeyException(final QName keyQName, final NodeIdentifierWithPredicates id) {
super(String.format("Key value not present for key: %s, in: %s", keyQName, id));
}
- private IllegalListKeyException(final QName keyQName, final NodeIdentifierWithPredicates id, final Object actualValue, final Object expectedValue) {
- super(String.format("Illegal value for key: %s, in: %s, actual value: %s, expected value from key: %s", keyQName, id, actualValue, expectedValue));
+ IllegalListKeyException(final QName keyQName, final NodeIdentifierWithPredicates id, final Object actualValue,
+ final Object expectedValue) {
+ super(String.format("Illegal value for key: %s, in: %s, actual value: %s, expected value from key: %s",
+ keyQName, id, actualValue, expectedValue));
}
}
}
/**
* DO NOT USE THIS METHOD.
*
+ * <p>
* This is an implementation-internal API and no outside users should use it. If you do,
* you are asking for trouble, as the returned object is not guaranteed to conform to
* java.util.Map interface.
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-public abstract class AbstractImmutableNormalizedNode<K extends PathArgument,V> implements NormalizedNode<K, V>, Immutable {
+public abstract class AbstractImmutableNormalizedNode<K extends PathArgument,V> implements NormalizedNode<K, V>,
+ Immutable {
private final K nodeIdentifier;
protected AbstractImmutableNormalizedNode(final K nodeIdentifier) {
}
protected abstract boolean valueEquals(AbstractImmutableNormalizedNode<?, ?> other);
+
protected abstract int valueHashCode();
@Override
private final Map<QName, String> attributes;
- protected AbstractImmutableNormalizedValueAttrNode(final K nodeIdentifier, final V value, final Map<QName, String> attributes) {
+ protected AbstractImmutableNormalizedValueAttrNode(final K nodeIdentifier, final V value,
+ final Map<QName, String> attributes) {
super(nodeIdentifier, value);
this.attributes = ImmutableMap.copyOf(attributes);
}
* Internal equivalent of {@link Collections}' unmodifiable Map. It does not retain
* keySet/entrySet references, thus lowering the memory overhead.
*/
-final class UnmodifiableChildrenMap implements CloneableMap<PathArgument, DataContainerChild<? extends PathArgument, ?>>, Serializable {
+final class UnmodifiableChildrenMap
+ implements CloneableMap<PathArgument, DataContainerChild<? extends PathArgument, ?>>, Serializable {
private static final long serialVersionUID = 1L;
/*
* Do not wrap maps which are smaller than this and instead copy them into
* @param map Backing map
* @return Unmodifiable view
*/
- static Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> create(final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> map) {
+ static Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> create(
+ final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> map) {
if (map instanceof UnmodifiableChildrenMap) {
return map;
}
}
@Override
- public void putAll(@Nonnull final Map<? extends PathArgument, ? extends DataContainerChild<? extends PathArgument, ?>> m) {
+ @SuppressWarnings("checkstyle:parameterName")
+ public void putAll(final Map<? extends PathArgument, ? extends DataContainerChild<? extends PathArgument, ?>> m) {
throw new UnsupportedOperationException();
}
}
@Override
- public boolean equals(final Object o) {
- return this == o || delegate.equals(o);
+ public boolean equals(final Object obj) {
+ return this == obj || delegate.equals(obj);
}
@Override
@SuppressWarnings("unchecked")
public Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> createMutableClone() {
if (delegate instanceof HashMap) {
- return (Map<PathArgument, DataContainerChild<? extends PathArgument, ?>>) ((HashMap<?, ?>) delegate).clone();
+ return (Map<PathArgument, DataContainerChild<? extends PathArgument, ?>>)
+ ((HashMap<?, ?>) delegate).clone();
}
return new HashMap<>(delegate);
protected <T extends AbstractCursor<?>> T openCursor(final T cursor) {
final boolean success = CURSOR_UPDATER.compareAndSet(this, null, cursor);
- Preconditions.checkState(success, "Modification %s has cursor attached at path %s", this, this.cursor.getRootPath());
+ Preconditions.checkState(success, "Modification %s has cursor attached at path %s", this,
+ this.cursor.getRootPath());
return cursor;
}
*
* @param <T> Type of the container node
*/
-abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeContainer> extends AbstractNodeContainerModificationStrategy {
+abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeContainer>
+ extends AbstractNodeContainerModificationStrategy {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDataNodeContainerModificationStrategy.class);
private final LoadingCache<PathArgument, ModificationApplyOperation> childCache = CacheBuilder.newBuilder()
.build(new CacheLoader<PathArgument, ModificationApplyOperation>() {
@Override
public ModificationApplyOperation load(@Nonnull final PathArgument key) {
if (key instanceof AugmentationIdentifier && schema instanceof AugmentationTarget) {
- return SchemaAwareApplyOperation.from(schema, (AugmentationTarget) schema, (AugmentationIdentifier) key, treeConfig);
+ return SchemaAwareApplyOperation.from(schema, (AugmentationTarget) schema,
+ (AugmentationIdentifier) key, treeConfig);
}
final DataSchemaNode child = schema.getDataChildByName(key.getNodeType());
- Preconditions.checkArgument(child != null, "Schema %s does not have a node for child %s", schema, key.getNodeType());
+ Preconditions.checkArgument(child != null, "Schema %s does not have a node for child %s", schema,
+ key.getNodeType());
return SchemaAwareApplyOperation.from(child, treeConfig);
}
});
private final T schema;
private final DataTreeConfiguration treeConfig;
- protected AbstractDataNodeContainerModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass, final DataTreeConfiguration treeConfig) {
+ protected AbstractDataNodeContainerModificationStrategy(final T schema,
+ final Class<? extends NormalizedNode<?, ?>> nodeClass, final DataTreeConfiguration treeConfig) {
super(nodeClass, treeConfig);
this.schema = Preconditions.checkNotNull(schema,"schema");
this.treeConfig = Preconditions.checkNotNull(treeConfig,"treeConfig");
try {
return Optional.fromNullable(childCache.get(identifier));
} catch (ExecutionException | UncheckedExecutionException e) {
- LOG.trace("Child {} not present in container schema {} children {}", identifier, this, schema.getChildNodes(), e.getCause());
+ LOG.trace("Child {} not present in container schema {} children {}", identifier, this,
+ schema.getChildNodes(), e.getCause());
return Optional.absent();
}
}
static DataTreeCandidateNode deltaChild(
final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
- final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData, final PathArgument identifier) {
+ final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData,
+ final PathArgument identifier) {
final Optional<NormalizedNode<?, ?>> maybeNewChild = getChild(newData, identifier);
final Optional<NormalizedNode<?, ?>> maybeOldChild = getChild(oldData, identifier);
final Optional<TreeNode> newRoot = m.getStrategy().apply(m.getRootModification(),
Optional.of(currentRoot), m.getVersion());
- Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node for modification %s", modification);
+ Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node for modification %s",
+ modification);
return new InMemoryDataTreeCandidate(YangInstanceIdentifier.EMPTY, root, currentRoot, newRoot.get());
}
}
}
@SuppressWarnings("unchecked")
- private static NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> getContainer(@Nullable final TreeNode meta) {
- return (meta == null ? null : (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>)meta.getData());
+ private static NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> getContainer(
+ @Nullable final TreeNode meta) {
+ return meta == null ? null : (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>)meta.getData();
}
private ChildNode childNode(final ModifiedNode childMod) {
@Nonnull
public Collection<DataTreeCandidateNode> getChildNodes() {
switch (mod.getModificationType()) {
- case APPEARED:
- case DISAPPEARED:
- case SUBTREE_MODIFIED:
- return Collections2.transform(mod.getChildren(), this::childNode);
- case UNMODIFIED:
- // Unmodified node, but we still need to resolve potential children. canHaveChildren returns
- // false if both arguments are null.
- if (!canHaveChildren(oldMeta, newMeta)) {
- return ImmutableList.of();
- }
-
- return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(),
- AbstractRecursiveCandidateNode::unmodifiedNode);
- case DELETE:
- case WRITE:
- // This is unusual, the user is requesting we follow into an otherwise-terminal node.
- // We need to fudge things based on before/after data to correctly fake the expectations.
- if (!canHaveChildren(oldMeta, newMeta)) {
- return ImmutableList.of();
- }
- return AbstractDataTreeCandidateNode.deltaChildren(getContainer(oldMeta), getContainer(newMeta));
- default:
- throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
+ case APPEARED:
+ case DISAPPEARED:
+ case SUBTREE_MODIFIED:
+ return Collections2.transform(mod.getChildren(), this::childNode);
+ case UNMODIFIED:
+ // Unmodified node, but we still need to resolve potential children. canHaveChildren returns
+ // false if both arguments are null.
+ if (!canHaveChildren(oldMeta, newMeta)) {
+ return ImmutableList.of();
+ }
+
+ return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(),
+ AbstractRecursiveCandidateNode::unmodifiedNode);
+ case DELETE:
+ case WRITE:
+ // This is unusual, the user is requesting we follow into an otherwise-terminal node.
+ // We need to fudge things based on before/after data to correctly fake the expectations.
+ if (!canHaveChildren(oldMeta, newMeta)) {
+ return ImmutableList.of();
+ }
+ return AbstractDataTreeCandidateNode.deltaChildren(getContainer(oldMeta), getContainer(newMeta));
+ default:
+ throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
}
}
@Override
public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
switch (mod.getModificationType()) {
- case APPEARED:
- case DISAPPEARED:
- case SUBTREE_MODIFIED:
- final Optional<ModifiedNode> childMod = mod.getChild(identifier);
- if (childMod.isPresent()) {
- return childNode(childMod.get());
- }
- return null;
- case UNMODIFIED:
- if (!canHaveChildren(oldMeta, newMeta)) {
+ case APPEARED:
+ case DISAPPEARED:
+ case SUBTREE_MODIFIED:
+ final Optional<ModifiedNode> childMod = mod.getChild(identifier);
+ if (childMod.isPresent()) {
+ return childNode(childMod.get());
+ }
return null;
- }
- final Optional<NormalizedNode<?, ?>> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta)
- .getChild(identifier);
- return maybeChild.isPresent() ? AbstractRecursiveCandidateNode.unmodifiedNode(maybeChild.get()) : null;
- case DELETE:
- case WRITE:
- if (!canHaveChildren(oldMeta, newMeta)) {
- return null;
- }
- return AbstractDataTreeCandidateNode.deltaChild(getContainer(oldMeta), getContainer(newMeta), identifier);
- default:
- throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
+ case UNMODIFIED:
+ if (!canHaveChildren(oldMeta, newMeta)) {
+ return null;
+ }
+ final Optional<NormalizedNode<?, ?>> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta)
+ .getChild(identifier);
+ return maybeChild.isPresent() ? AbstractRecursiveCandidateNode.unmodifiedNode(maybeChild.get()) : null;
+ case DELETE:
+ case WRITE:
+ if (!canHaveChildren(oldMeta, newMeta)) {
+ return null;
+ }
+ return AbstractDataTreeCandidateNode.deltaChild(getContainer(oldMeta), getContainer(newMeta),
+ identifier);
+ default:
+ throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
}
}
@Override
public String toString() {
- return this.getClass().getSimpleName() + "{mod = " + this.mod + ", oldMeta = " + this.oldMeta + ", newMeta = " +
- this.newMeta + "}";
+ return this.getClass().getSimpleName() + "{mod = " + this.mod + ", oldMeta = " + this.oldMeta + ", newMeta = "
+ + this.newMeta + "}";
}
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MutableTreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
protected AbstractNodeContainerModificationStrategy(final Class<? extends NormalizedNode<?, ?>> nodeClass,
final DataTreeConfiguration treeConfig) {
this.nodeClass = Preconditions.checkNotNull(nodeClass , "nodeClass");
- this.verifyChildrenStructure = (treeConfig.getTreeType() == TreeType.CONFIGURATION);
+ this.verifyChildrenStructure = treeConfig.getTreeType() == TreeType.CONFIGURATION;
}
@SuppressWarnings("rawtypes")
@Override
protected void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
- final NormalizedNodeContainer container = (NormalizedNodeContainer) value;
+ final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) value;
for (final Object child : container.getValue()) {
checkArgument(child instanceof NormalizedNode);
final NormalizedNode<?, ?> castedChild = (NormalizedNode<?, ?>) child;
childOp.get().recursivelyVerifyStructure(castedChild);
} else {
throw new SchemaValidationFailedException(
- String.format("Node %s is not a valid child of %s according to the schema.",
- castedChild.getIdentifier(), container.getIdentifier()));
+ String.format("Node %s is not a valid child of %s according to the schema.",
+ castedChild.getIdentifier(), container.getIdentifier()));
}
}
}
final Collection<NormalizedNode<?, ?>> children = ((NormalizedNodeContainer)value).getValue();
switch (modification.getOperation()) {
- case NONE:
- // Fresh node, just record a MERGE with a value
+ case NONE:
+ // Fresh node, just record a MERGE with a value
recursivelyVerifyStructure(value);
- modification.updateValue(LogicalOperation.MERGE, value);
- return;
- case TOUCH:
+ modification.updateValue(LogicalOperation.MERGE, value);
+ return;
+ case TOUCH:
mergeChildrenIntoModification(modification, children, version);
// We record empty merge value, since real children merges
// before.
modification.updateValue(LogicalOperation.MERGE, createEmptyValue(value));
return;
- case MERGE:
- // Merging into an existing node. Merge data children modifications (maybe recursively) and mark as MERGE,
- // invalidating cached snapshot
- mergeChildrenIntoModification(modification, children, version);
+ case MERGE:
+ // Merging into an existing node. Merge data children modifications (maybe recursively) and mark
+ // as MERGE, invalidating cached snapshot
+ mergeChildrenIntoModification(modification, children, version);
modification.updateOperationType(LogicalOperation.MERGE);
- return;
- case DELETE:
- // Delete performs a data dependency check on existence of the node. Performing a merge on DELETE means we
- // are really performing a write. One thing that ruins that are any child modifications. If there are any,
- // we will perform a read() to get the current state of affairs, turn this into into a WRITE and then
- // append any child entries.
- if (!modification.getChildren().isEmpty()) {
- // Version does not matter here as we'll throw it out
- final Optional<TreeNode> current = apply(modification, modification.getOriginal(), Version.initial());
- if (current.isPresent()) {
- modification.updateValue(LogicalOperation.WRITE, current.get().getData());
- mergeChildrenIntoModification(modification, children, version);
- return;
+ return;
+ case DELETE:
+ // Delete performs a data dependency check on existence of the node. Performing a merge on DELETE means
+ // we are really performing a write. One thing that ruins that are any child modifications. If there
+ // are any, we will perform a read() to get the current state of affairs, turn this into into a WRITE
+ // and then append any child entries.
+ if (!modification.getChildren().isEmpty()) {
+ // Version does not matter here as we'll throw it out
+ final Optional<TreeNode> current = apply(modification, modification.getOriginal(),
+ Version.initial());
+ if (current.isPresent()) {
+ modification.updateValue(LogicalOperation.WRITE, current.get().getData());
+ mergeChildrenIntoModification(modification, children, version);
+ return;
+ }
}
- }
- modification.updateValue(LogicalOperation.WRITE, value);
- return;
- case WRITE:
- // We are augmenting a previous write. We'll just walk value's children, get the corresponding ModifiedNode
- // and run recursively on it
- mergeChildrenIntoModification(modification, children, version);
- modification.updateOperationType(LogicalOperation.WRITE);
- return;
+ modification.updateValue(LogicalOperation.WRITE, value);
+ return;
+ case WRITE:
+ // We are augmenting a previous write. We'll just walk value's children, get the corresponding
+ // ModifiedNode and run recursively on it
+ mergeChildrenIntoModification(modification, children, version);
+ modification.updateOperationType(LogicalOperation.WRITE);
+ return;
+ default:
+ throw new IllegalArgumentException("Unsupported operation " + modification.getOperation());
}
-
- throw new IllegalArgumentException("Unsupported operation " + modification.getOperation());
}
@Override
protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
if (!modification.getOriginal().isPresent() && !current.isPresent()) {
- throw new ModifiedNodeDoesNotExistException(path, String.format("Node %s does not exist. Cannot apply modification to its children.", path));
+ throw new ModifiedNodeDoesNotExistException(path,
+ String.format("Node %s does not exist. Cannot apply modification to its children.", path));
}
if (!current.isPresent()) {
}
abstract AbstractReadyIterator getParent();
+
abstract void removeFromParent();
private static final class NestedReadyIterator extends AbstractReadyIterator {
// No-op, since root node cannot be removed
}
}
-
}
\ No newline at end of file
abstract class AbstractRecursiveCandidateNode extends AbstractDataTreeCandidateNode {
- protected AbstractRecursiveCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
+ protected AbstractRecursiveCandidateNode(
+ final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
super(data);
}
@SuppressWarnings("unchecked")
static DataTreeCandidateNode deleteNode(final NormalizedNode<?, ?> data) {
if (data instanceof NormalizedNodeContainer) {
- return new RecursiveDeleteCandidateNode((NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data);
+ return new RecursiveDeleteCandidateNode(
+ (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data);
}
return new DeleteLeafCandidateNode(data);
}
@SuppressWarnings("unchecked")
static DataTreeCandidateNode replaceNode(final NormalizedNode<?, ?> oldData, final NormalizedNode<?, ?> newData) {
if (isContainer(oldData)) {
- return new RecursiveReplaceCandidateNode((NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) oldData,
+ return new RecursiveReplaceCandidateNode(
+ (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) oldData,
(NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) newData);
}
return new ReplaceLeafCandidateNode(oldData, newData);
@SuppressWarnings("unchecked")
static DataTreeCandidateNode unmodifiedNode(final NormalizedNode<?, ?> data) {
if (data instanceof NormalizedNodeContainer) {
- return new RecursiveUnmodifiedCandidateNode((NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data);
+ return new RecursiveUnmodifiedCandidateNode(
+ (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data);
}
return new UnmodifiedLeafCandidateNode(data);
}
@SuppressWarnings("unchecked")
static DataTreeCandidateNode writeNode(final NormalizedNode<?, ?> data) {
if (data instanceof NormalizedNodeContainer) {
- return new RecursiveWriteCandidateNode((NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data);
+ return new RecursiveWriteCandidateNode(
+ (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data);
}
return new WriteLeafCandidateNode(data);
}
return createLeaf(childData);
}
- protected abstract DataTreeCandidateNode createContainer(NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData);
+ abstract DataTreeCandidateNode createContainer(
+ NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData);
- protected abstract DataTreeCandidateNode createLeaf(NormalizedNode<?,?> childData);
+ abstract DataTreeCandidateNode createLeaf(NormalizedNode<?,?> childData);
}
\ No newline at end of file
private final Class<? extends NormalizedNode<?, ?>> nodeClass;
private final T schema;
- protected AbstractValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
+ protected AbstractValueNodeModificationStrategy(final T schema,
+ final Class<? extends NormalizedNode<?, ?>> nodeClass) {
this.nodeClass = Preconditions.checkNotNull(nodeClass);
this.schema = schema;
}
import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
final class AugmentationModificationStrategy extends AbstractDataNodeContainerModificationStrategy<AugmentationSchema> {
- AugmentationModificationStrategy(final AugmentationSchema schema, final DataNodeContainer resolved, final DataTreeConfiguration treeConfig) {
+ AugmentationModificationStrategy(final AugmentationSchema schema, final DataNodeContainer resolved,
+ final DataTreeConfiguration treeConfig) {
super(createAugmentProxy(schema,resolved), AugmentationNode.class, treeConfig);
}
.withNodeIdentifier(((AugmentationNode) original).getIdentifier()).build();
}
- private static AugmentationSchema createAugmentProxy(final AugmentationSchema schema, final DataNodeContainer resolved) {
+ private static AugmentationSchema createAugmentProxy(final AugmentationSchema schema,
+ final DataNodeContainer resolved) {
final Set<DataSchemaNode> realChildSchemas = new HashSet<>();
for (final DataSchemaNode augChild : schema.getChildNodes()) {
realChildSchemas.add(resolved.getDataChildByName(augChild.getQName()));
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
final Collection<DataContainerChild<?, ?>> children = ((ChoiceNode) normalizedNode).getValue();
if (!children.isEmpty()) {
final DataContainerChild<?, ?> firstChild = children.iterator().next();
- final CaseEnforcer enforcer = caseEnforcers.get(firstChild.getIdentifier());
- Verify.verifyNotNull(enforcer, "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier());
+ final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()),
+ "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong "
+ + "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier());
// Make sure no leaves from other cases are present
for (final CaseEnforcer other : exclusions.get(enforcer)) {
for (final PathArgument id : other.getAllChildIdentifiers()) {
- final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode, id);
+ final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode,
+ id);
Preconditions.checkArgument(!maybeChild.isPresent(),
"Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s",
firstChild.getIdentifier(), enforcer, id, other, maybeChild.orNull());
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import javax.annotation.Nonnull;
import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
}
}
- InMemoryDataTree(final TreeNode rootNode, final DataTreeConfiguration treeConfig, final SchemaContext schemaContext,
- final DataSchemaNode rootSchemaNode, final boolean maskMandatory) {
+ InMemoryDataTree(final TreeNode rootNode, final DataTreeConfiguration treeConfig,
+ final SchemaContext schemaContext, final DataSchemaNode rootSchemaNode, final boolean maskMandatory) {
this.treeConfig = Preconditions.checkNotNull(treeConfig, "treeConfig");
this.maskMandatory = maskMandatory;
}
final ModificationApplyOperation rootNode = getOperation(rootSchemaNode);
- DataTreeState currentState, newState;
+ DataTreeState currentState;
+ DataTreeState newState;
do {
currentState = state;
newState = currentState.withSchemaContext(newSchemaContext, rootNode);
if (candidate instanceof NoopDataTreeCandidate) {
return;
}
- Preconditions.checkArgument(candidate instanceof InMemoryDataTreeCandidate, "Invalid candidate class %s", candidate.getClass());
+ Preconditions.checkArgument(candidate instanceof InMemoryDataTreeCandidate, "Invalid candidate class %s",
+ candidate.getClass());
final InMemoryDataTreeCandidate c = (InMemoryDataTreeCandidate)candidate;
if (LOG.isTraceEnabled()) {
}
final TreeNode newRoot = c.getTipRoot();
- DataTreeState currentState, newState;
+ DataTreeState currentState;
+ DataTreeState newState;
do {
currentState = state;
final TreeNode currentRoot = currentState.getRoot();
if (oldRoot != currentRoot) {
final String oldStr = simpleToString(oldRoot);
final String currentStr = simpleToString(currentRoot);
- throw new IllegalStateException("Store tree " + currentStr + " and candidate base " + oldStr + " differ.");
+ throw new IllegalStateException("Store tree " + currentStr + " and candidate base " + oldStr
+ + " differ.");
}
newState = currentState.withRoot(newRoot);
} while (!STATE_UPDATER.compareAndSet(this, currentState, newState));
}
- private static String simpleToString(final Object o) {
- return o.getClass().getName() + "@" + Integer.toHexString(o.hashCode());
+ private static String simpleToString(final Object obj) {
+ return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode());
}
@Override
@Override
public String toString() {
- return MoreObjects.toStringHelper(this).
- add("object", super.toString()).
- add("config", treeConfig).
- add("state", state).
- toString();
+ return MoreObjects.toStringHelper(this)
+ .add("object", super.toString())
+ .add("config", treeConfig)
+ .add("state", state)
+ .toString();
}
@Override
final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
private static final class RootNode extends AbstractModifiedNodeBasedCandidateNode {
- public RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) {
+ RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) {
super(mod, oldMeta, newMeta);
}
@Override
public String toString() {
- return MoreObjects.toStringHelper(this).add("rootPath", getRootPath()).add("rootNode", getRootNode()).toString();
+ return MoreObjects.toStringHelper(this).add("rootPath", getRootPath())
+ .add("rootNode", getRootNode()).toString();
}
}
initialSchemaContext, rootSchemaNode, maskMandatory);
}
+ private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
+ final YangInstanceIdentifier rootPath) {
+ final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
+ final DataSchemaContextNode<?> rootContextNode = contextTree.getChild(rootPath);
+ Preconditions.checkArgument(rootContextNode != null, "Failed to find root %s in schema context", rootPath);
+
+ final DataSchemaNode rootSchemaNode = rootContextNode.getDataSchemaNode();
+ Preconditions.checkArgument(rootSchemaNode instanceof DataNodeContainer,
+ "Root %s resolves to non-container type %s", rootPath, rootSchemaNode);
+ return rootSchemaNode;
+ }
+
private static NormalizedNode<?, ?> createRoot(final DataNodeContainer schemaNode,
final YangInstanceIdentifier path) {
if (path.isEmpty()) {
}
}
- private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
- final YangInstanceIdentifier rootPath) {
- final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
- final DataSchemaContextNode<?> rootContextNode = contextTree.getChild(rootPath);
- Preconditions.checkArgument(rootContextNode != null, "Failed to find root %s in schema context", rootPath);
-
- final DataSchemaNode rootSchemaNode = rootContextNode.getDataSchemaNode();
- Preconditions.checkArgument(rootSchemaNode instanceof DataNodeContainer,
- "Root %s resolves to non-container type %s", rootPath, rootSchemaNode);
- return rootSchemaNode;
- }
-
private static NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) {
if (path.isEmpty()) {
return ROOT_CONTAINER;
return Optional.absent();
}
+ @SuppressWarnings("checkstyle:illegalCatch")
private Optional<TreeNode> resolveSnapshot(final YangInstanceIdentifier path, final ModifiedNode modification) {
final Optional<TreeNode> potentialSnapshot = modification.getSnapshot();
if (potentialSnapshot != null) {
ModificationApplyOperation operation = strategyTree;
ModifiedNode modification = rootNode;
- int i = 1;
+ int depth = 1;
for (final PathArgument pathArg : path.getPathArguments()) {
final Optional<ModificationApplyOperation> potential = operation.getChild(pathArg);
if (!potential.isPresent()) {
throw new SchemaValidationFailedException(String.format("Child %s is not present in schema tree.",
- path.getAncestor(i)));
+ path.getAncestor(depth)));
}
operation = potential.get();
- ++i;
+ ++depth;
modification = modification.modifyChild(pathArg, operation, version);
}
private static void applyNode(final DataTreeModificationCursor cursor, final ModifiedNode node) {
switch (node.getOperation()) {
- case NONE:
- break;
- case DELETE:
- cursor.delete(node.getIdentifier());
- break;
- case MERGE:
- cursor.merge(node.getIdentifier(), node.getWrittenValue());
- applyChildren(cursor, node);
- break;
- case TOUCH:
- // TODO: we could improve efficiency of cursor use if we could understand
- // nested TOUCH operations. One way of achieving that would be a proxy
- // cursor, which would keep track of consecutive enter and exit calls
- // and coalesce them.
- applyChildren(cursor, node);
- break;
- case WRITE:
- cursor.write(node.getIdentifier(), node.getWrittenValue());
- applyChildren(cursor, node);
- break;
- default:
- throw new IllegalArgumentException("Unhandled node operation " + node.getOperation());
+ case NONE:
+ break;
+ case DELETE:
+ cursor.delete(node.getIdentifier());
+ break;
+ case MERGE:
+ cursor.merge(node.getIdentifier(), node.getWrittenValue());
+ applyChildren(cursor, node);
+ break;
+ case TOUCH:
+ // TODO: we could improve efficiency of cursor use if we could understand
+ // nested TOUCH operations. One way of achieving that would be a proxy
+ // cursor, which would keep track of consecutive enter and exit calls
+ // and coalesce them.
+ applyChildren(cursor, node);
+ break;
+ case WRITE:
+ cursor.write(node.getIdentifier(), node.getWrittenValue());
+ applyChildren(cursor, node);
+ break;
+ default:
+ throw new IllegalArgumentException("Unhandled node operation " + node.getOperation());
}
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
-final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDataTreeModification> implements DataTreeModificationCursor {
+final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDataTreeModification>
+ implements DataTreeModificationCursor {
private final Deque<OperationWithModification> stack = new ArrayDeque<>();
- InMemoryDataTreeModificationCursor(final InMemoryDataTreeModification parent, final YangInstanceIdentifier rootPath, final OperationWithModification rootOp) {
+ InMemoryDataTreeModificationCursor(final InMemoryDataTreeModification parent, final YangInstanceIdentifier rootPath,
+ final OperationWithModification rootOp) {
super(parent, rootPath);
stack.push(rootOp);
}
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public void enter(@Nonnull final Iterable<PathArgument> path) {
int depth = 0;
for (PathArgument child : path) {
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import javax.annotation.Nonnull;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
final class InMemoryDataTreeSnapshotCursor extends AbstractCursor<InMemoryDataTreeSnapshot> {
private final Deque<NormalizedNodeContainer<?, ?, ?>> stack = new ArrayDeque<>();
- InMemoryDataTreeSnapshotCursor(final InMemoryDataTreeSnapshot parent, final YangInstanceIdentifier rootPath, final NormalizedNodeContainer<?, ?, ?> normalizedNode) {
+ InMemoryDataTreeSnapshotCursor(final InMemoryDataTreeSnapshot parent, final YangInstanceIdentifier rootPath,
+ final NormalizedNodeContainer<?, ?, ?> normalizedNode) {
super(parent, rootPath);
stack.push(normalizedNode);
}
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public void enter(@Nonnull final Iterable<PathArgument> path) {
final Optional<NormalizedNode<?, ?>> maybeChildNode = NormalizedNodes.findNode(stack.peek(), path);
Preconditions.checkArgument(maybeChildNode.isPresent(), "Child %s not found", path);
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
/**
- * Holder and factory for upgradable root modifications
+ * Holder and factory for upgradable root modifications.
*
- * This class is factory for upgradable root modifications and provides an
- * access to set latest backing implementation.
+ * <p>
+ * This class is factory for upgradable root modifications and provides an access to set latest backing implementation.
*/
final class LatestOperationHolder {
private ModificationApplyOperation current = AlwaysFailOperation.INSTANCE;
/**
- * Return latest backing implemenation
+ * Return latest backing implementation.
*
- * @return
+ * @return latest backing implementation
*/
ModificationApplyOperation getCurrent() {
return current;
}
/**
- * Sets latest backing implementation of associated
- * {@link RootModificationApplyOperation}.
+ * Sets latest backing implementation of associated {@link RootModificationApplyOperation}.
+ *
* <p>
- * Note: This does not result in upgrading implementation of already
- * existing {@link RootModificationApplyOperation}. Users, which
- * obtained instances using {@link #newSnapshot()}, deriving
- * {@link RootModificationApplyOperation} from this modification must
- * explicitly invoke
- * {@link RootModificationApplyOperation#upgradeIfPossible()} on their
- * instance to be updated to latest backing implementation.
+ * Note: This does not result in upgrading implementation of already existing
+ * {@link RootModificationApplyOperation}. Users, who obtained instances using {@link #newSnapshot()}, deriving
+ * {@link RootModificationApplyOperation} from this modification must explicitly invoke
+ * {@link RootModificationApplyOperation#upgradeIfPossible()} on their instance to be updated to latest backing
+ * implementation.
*
- * @param newApplyOper
- * New backing implementation
+ * @param newApplyOper New backing implementation
*/
void setCurrent(final ModificationApplyOperation newApplyOper) {
current = newApplyOper;
}
/**
+ * Creates new upgradable {@link RootModificationApplyOperation} associated with holder.
*
- * Creates new upgradable {@link RootModificationApplyOperation}
- * associated with holder.
- *
- * @return New upgradable {@link RootModificationApplyOperation} with
- * {@link #getCurrent()} used as backing implementation.
+ * @return New upgradable {@link RootModificationApplyOperation} with {@link #getCurrent()} used
+ * as the backing implementation.
*/
RootModificationApplyOperation newSnapshot() {
return new UpgradableModificationApplyOperation(this, current);
enforceOnData(tree.getData());
}
- abstract void enforceOnData(final NormalizedNode<?, ?> normalizedNode);
+ abstract void enforceOnData(NormalizedNode<?, ?> normalizedNode);
private static void findMandatoryNodes(final Builder<YangInstanceIdentifier> builder,
final YangInstanceIdentifier id, final DataNodeContainer schema, final TreeType type) {
} else {
final ConstraintDefinition constraints = child.getConstraints();
final Integer minElements = constraints.getMinElements();
- if (constraints.isMandatory() || (minElements != null && minElements.intValue() > 0)) {
+ if (constraints.isMandatory() || minElements != null && minElements.intValue() > 0) {
final YangInstanceIdentifier childId = id.node(NodeIdentifier.create(child.getQName()));
LOG.debug("Adding mandatory child {}", childId);
builder.add(childId.toOptimized());
/**
* Operation responsible for applying {@link ModifiedNode} on tree.
*
+ * <p>
* Operation is composite - operation on top level node consists of
* suboperations on child nodes. This allows to walk operation hierarchy and
* invoke suboperations independently.
*
+ * <p>
* <b>Implementation notes</b>
* <ul>
* <li>
* nodes expose via {@link #getChild(PathArgument)} method.
* <li>Same suboperations SHOULD be used when invoked via
* {@link #apply(ModifiedNode, Optional, Version)} if applicable.
+ * </ul>
*
- *
+ * <p>
* Hierarchical composite operation which is responsible for applying
* modification on particular subtree and creating updated subtree
*/
abstract class ModificationApplyOperation implements StoreTreeNode<ModificationApplyOperation> {
/**
- *
- * Implementation of this operation must be stateless and must not change
- * state of this object.
+ * Implementation of this operation must be stateless and must not change state of this object.
*
* @param modification
* NodeModification to be applied
* Store Metadata Node on which NodeModification should be
* applied
* @param version New subtree version of parent node
- * @throws IllegalArgumentException
- * If it is not possible to apply Operation on provided Metadata
- * node
* @return new {@link TreeNode} if operation resulted in updating
* node, {@link Optional#absent()} if {@link ModifiedNode}
* resulted in deletion of this node.
+ * @throws IllegalArgumentException
+ * If it is not possible to apply Operation on provided Metadata
+ * node
*/
abstract Optional<TreeNode> apply(ModifiedNode modification, Optional<TreeNode> storeMeta, Version version);
*
* @param modification Modification
* @param current Metadata Node to which modification should be applied
- * @param version
+ * @param version Metadata version
* @throws DataValidationFailedException if the modification is not applicable
*/
- abstract void checkApplicable(YangInstanceIdentifier path, NodeModification modification, Optional<TreeNode> current, Version version) throws DataValidationFailedException;
+ abstract void checkApplicable(YangInstanceIdentifier path, NodeModification modification,
+ Optional<TreeNode> current, Version version) throws DataValidationFailedException;
/**
- *
* Performs structural verification of NodeModification, such as writen values / types uses
* right structural elements.
*
* @throws IllegalArgumentException If provided NodeModification does not adhere to the
* structure.
*/
- abstract void verifyStructure(NormalizedNode<?, ?> modification, boolean verifyChildren)
- throws IllegalArgumentException;
+ abstract void verifyStructure(NormalizedNode<?, ?> modification, boolean verifyChildren);
/**
* Return the tracking policy for this node's children.
abstract void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode<?, ?> value, Version version);
/**
- * Returns a suboperation for specified tree node
+ * Returns a suboperation for specified tree node.
*
* @return Reference to suboperation for specified tree node, {@link Optional#absent()}
- * if suboperation is not supported for specified tree node.
+ * if suboperation is not supported for specified tree node.
*/
@Override
public abstract Optional<ModificationApplyOperation> getChild(PathArgument child);
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
/**
- * Node Modification Node and Tree
+ * Node Modification Node and Tree.
*
+ * <p>
* Tree which structurally resembles data tree and captures client modifications to the data store tree. This tree is
* lazily created and populated via {@link #modifyChild(PathArgument, ModificationApplyOperation, Version)} and
* {@link TreeNode} which represents original state as tracked by {@link #getOriginal()}.
*
+ * <p>
* The contract is that the state information exposed here preserves the temporal ordering of whatever modifications
* were executed. A child's effects pertain to data node as modified by its ancestors. This means that in order to
* reconstruct the effective data node presentation, it is sufficient to perform a depth-first pre-order traversal of
case TOUCH:
case NONE:
return false;
+ default:
+ throw new IllegalArgumentException("Unhandled modification type " + input.getOperation());
}
-
- throw new IllegalArgumentException(String.format("Unhandled modification type %s", input.getOperation()));
};
private final Map<PathArgument, ModifiedNode> children;
private Optional<TreeNode> validatedCurrent;
private TreeNode validatedNode;
- private ModifiedNode(final PathArgument identifier, final Optional<TreeNode> original, final ChildTrackingPolicy childPolicy) {
+ private ModifiedNode(final PathArgument identifier, final Optional<TreeNode> original,
+ final ChildTrackingPolicy childPolicy) {
this.identifier = identifier;
this.original = original;
this.children = childPolicy.createMap();
}
/**
+ * Returns child modification if child was modified.
*
- * Returns child modification if child was modified
- *
- * @return Child modification if direct child or it's subtree
- * was modified.
- *
+ * @return Child modification if direct child or it's subtree was modified.
*/
@Override
public Optional<ModifiedNode> getChild(final PathArgument child) {
*/
private Optional<TreeNode> findOriginalMetadata(@Nonnull final PathArgument child, final Version modVersion) {
switch (operation) {
- case DELETE:
- // DELETE implies non-presence
- return Optional.absent();
- case NONE:
- case TOUCH:
- case MERGE:
- return metadataFromSnapshot(child);
- case WRITE:
- // WRITE implies presence based on written data
- return metadataFromData(child, modVersion);
+ case DELETE:
+ // DELETE implies non-presence
+ return Optional.absent();
+ case NONE:
+ case TOUCH:
+ case MERGE:
+ return metadataFromSnapshot(child);
+ case WRITE:
+ // WRITE implies presence based on written data
+ return metadataFromData(child, modVersion);
+ default:
+ throw new IllegalStateException("Unhandled node operation " + operation);
}
-
- throw new IllegalStateException("Unhandled node operation " + operation);
}
/**
- *
* Returns child modification if child was modified, creates {@link ModifiedNode}
- * for child otherwise.
- *
- * If this node's {@link ModificationType} is {@link ModificationType#UNMODIFIED}
- * changes modification type to {@link ModificationType#SUBTREE_MODIFIED}
+ * for child otherwise. If this node's {@link ModificationType} is {@link ModificationType#UNMODIFIED}
+ * changes modification type to {@link ModificationType#SUBTREE_MODIFIED}.
*
* @param child child identifier, may not be null
* @param childOper Child operation
}
/**
- * Returns all recorded direct child modification
+ * Returns all recorded direct child modifications.
*
* @return all recorded direct child modifications
*/
final LogicalOperation newType;
switch (operation) {
- case DELETE:
- case NONE:
- // We need to record this delete.
- newType = LogicalOperation.DELETE;
- break;
- case MERGE:
- // In case of merge - delete needs to be recored and must not to be changed into
- // NONE, because lazy expansion of parent MERGE node would reintroduce it
- // again.
+ case DELETE:
+ case NONE:
+ // We need to record this delete.
newType = LogicalOperation.DELETE;
break;
- case TOUCH:
- case WRITE:
- /*
- * We are canceling a previous modification. This is a bit tricky,
- * as the original write may have just introduced the data, or it
- * may have modified it.
- *
- * As documented in BUG-2470, a delete of data introduced in this
- * transaction needs to be turned into a no-op.
- */
- newType = original.isPresent() ? LogicalOperation.DELETE : LogicalOperation.NONE;
- break;
- default:
- throw new IllegalStateException("Unhandled deletion of node with " + operation);
+ case MERGE:
+ // In case of merge - delete needs to be recored and must not to be changed into NONE, because lazy
+ // expansion of parent MERGE node would reintroduce it again.
+ newType = LogicalOperation.DELETE;
+ break;
+ case TOUCH:
+ case WRITE:
+ /*
+ * We are canceling a previous modification. This is a bit tricky, as the original write may have just
+ * introduced the data, or it may have modified it.
+ *
+ * As documented in BUG-2470, a delete of data introduced in this transaction needs to be turned into
+ * a no-op.
+ */
+ newType = original.isPresent() ? LogicalOperation.DELETE : LogicalOperation.NONE;
+ break;
+ default:
+ throw new IllegalStateException("Unhandled deletion of node with " + operation);
}
clearSnapshot();
/**
* Records a write for associated node.
*
- * @param value
+ * @param value new value
*/
void write(final NormalizedNode<?, ?> value) {
updateValue(LogicalOperation.WRITE, value);
/**
* Seal the modification node and prune any children which has not been modified.
*
- * @param schema
+ * @param schema associated apply operation
+ * @param version target version
*/
void seal(final ModificationApplyOperation schema, final Version version) {
clearSnapshot();
};
private final TreeNode afterRoot;
- protected NoopDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot, final TreeNode afterRoot) {
+ protected NoopDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot,
+ final TreeNode afterRoot) {
super(rootPath);
Preconditions.checkArgument(modificationRoot.getOperation() == LogicalOperation.NONE);
this.afterRoot = Preconditions.checkNotNull(afterRoot);
final class NotUpgradableModificationApplyOperation extends RootModificationApplyOperation {
private final ModificationApplyOperation delegate;
- public NotUpgradableModificationApplyOperation(final ModificationApplyOperation delegate) {
+ NotUpgradableModificationApplyOperation(final ModificationApplyOperation delegate) {
this.delegate = delegate;
}
/**
* Read a particular child. If the child has been modified and does not have a stable
* view, one will we instantiated with specified version.
- *
- * @param child
- * @param version
- * @return
*/
Optional<NormalizedNode<?, ?>> read(final PathArgument child, final Version version) {
final Optional<ModifiedNode> maybeChild = modification.getChild(child);
final class PresenceContainerModificationStrategy extends ContainerModificationStrategy {
private final MandatoryLeafEnforcer enforcer;
- PresenceContainerModificationStrategy(final ContainerSchemaNode schemaNode, final DataTreeConfiguration treeConfig) {
+ PresenceContainerModificationStrategy(final ContainerSchemaNode schemaNode,
+ final DataTreeConfiguration treeConfig) {
super(schemaNode, treeConfig);
enforcer = MandatoryLeafEnforcer.forContainer(schemaNode, treeConfig);
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import javax.annotation.Nonnull;
import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
}
@Override
- protected DataTreeCandidateNode createContainer(
+ DataTreeCandidateNode createContainer(
final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData) {
return new RecursiveDeleteCandidateNode(childData);
}
}
@Override
- protected DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
+ DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
return new DeleteLeafCandidateNode(childData);
}
}
\ No newline at end of file
final class RecursiveReplaceCandidateNode extends AbstractDataTreeCandidateNode {
private final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData;
- public RecursiveReplaceCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
+ RecursiveReplaceCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData) {
super(newData);
this.oldData = Preconditions.checkNotNull(oldData);
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import javax.annotation.Nonnull;
import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
final class RecursiveUnmodifiedCandidateNode extends AbstractRecursiveCandidateNode {
- protected RecursiveUnmodifiedCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
+ protected RecursiveUnmodifiedCandidateNode(
+ final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
super(data);
}
}
@Override
- protected DataTreeCandidateNode createContainer(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData) {
+ DataTreeCandidateNode createContainer(
+ final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData) {
return new RecursiveUnmodifiedCandidateNode(childData);
}
@Override
- protected DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
+ DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
return new UnmodifiedLeafCandidateNode(childData);
}
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import javax.annotation.Nonnull;
import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
}
@Override
- protected DataTreeCandidateNode createContainer(
+ DataTreeCandidateNode createContainer(
final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData) {
return new RecursiveWriteCandidateNode(childData);
}
@Override
- protected DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
+ DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
return new WriteLeafCandidateNode(childData);
}
* <li><b>Not Upgradable</b> - operation is immutable, invocation of
* {@link #upgradeIfPossible()} is no-op and method {@link #snapshot()} returns
* pointer on same object.
- *
+ * </ul>
* <h3>Upgradable Root Modification Operation</h3>
- *
* Upgradable Root Modification Operation may be created using:
* <ul>
* <li> {@link #from(ModificationApplyOperation)} with other upgradable root
* Root Modification Operations and provides an option to set latest
* implementation.
* </ul>
+ *
* <p>
* Upgradable root operation is never upgraded to latest operation
* automatically, but client code must explicitly invoke
* {@link #upgradeIfPossible()} to get latest implementation.
*
+ * <p>
* Note: This is helpful for implementing
* {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification}
* which may be derived from
* {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree} before
* update of schema and user actually writes data after schema update. During
* update user did not invoked any operation.
- *
*/
abstract class RootModificationApplyOperation extends ModificationApplyOperation {
}
@Override
- void recursivelyVerifyStructure(NormalizedNode<?, ?> value) {
+ void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
getDelegate().recursivelyVerifyStructure(value);
}
/**
* Creates a snapshot from this modification, which may have separate
- * upgrade lifecycle and is not affected by upgrades
+ * upgrade lifecycle and is not affected by upgrades.
+ *
* <p>
- * Newly created snapshot uses backing implementation of this modi
+ * Newly created snapshot uses backing implementation of this modification.
*
* @return Derived {@link RootModificationApplyOperation} with separate
* upgrade lifecycle.
/**
* Upgrades backing implementation to latest available, if possible.
+ *
* <p>
* Latest implementation of {@link RootModificationApplyOperation} is
* managed by {@link LatestOperationHolder} which was used to construct this
abstract class SchemaAwareApplyOperation extends ModificationApplyOperation {
private static final Logger LOG = LoggerFactory.getLogger(SchemaAwareApplyOperation.class);
- public static ModificationApplyOperation from(final DataSchemaNode schemaNode, final DataTreeConfiguration treeConfig) {
+ public static ModificationApplyOperation from(final DataSchemaNode schemaNode,
+ final DataTreeConfiguration treeConfig) {
if (treeConfig.getTreeType() == TreeType.CONFIGURATION) {
- Preconditions.checkArgument(schemaNode.isConfiguration(), "Supplied %s does not belongs to configuration tree.", schemaNode.getPath());
+ Preconditions.checkArgument(schemaNode.isConfiguration(),
+ "Supplied %s does not belongs to configuration tree.", schemaNode.getPath());
}
if (schemaNode instanceof ContainerSchemaNode) {
final ContainerSchemaNode containerSchema = (ContainerSchemaNode) schemaNode;
if (containerSchema.isPresenceContainer()) {
return new PresenceContainerModificationStrategy(containerSchema, treeConfig);
- } else {
- return new StructuralContainerModificationStrategy(containerSchema, treeConfig);
}
+ return new StructuralContainerModificationStrategy(containerSchema, treeConfig);
} else if (schemaNode instanceof ListSchemaNode) {
return fromListSchemaNode((ListSchemaNode) schemaNode, treeConfig);
} else if (schemaNode instanceof ChoiceSchemaNode) {
}
public static SchemaAwareApplyOperation from(final DataNodeContainer resolvedTree,
- final AugmentationTarget augSchemas, final AugmentationIdentifier identifier, final DataTreeConfiguration treeConfig) {
+ final AugmentationTarget augSchemas, final AugmentationIdentifier identifier,
+ final DataTreeConfiguration treeConfig) {
for (final AugmentationSchema potential : augSchemas.getAvailableAugmentations()) {
for (final DataSchemaNode child : potential.getChildNodes()) {
if (identifier.getPossibleChildNames().contains(child.getQName())) {
}
}
- private static SchemaAwareApplyOperation fromListSchemaNode(final ListSchemaNode schemaNode, final DataTreeConfiguration treeConfig) {
+ private static SchemaAwareApplyOperation fromListSchemaNode(final ListSchemaNode schemaNode,
+ final DataTreeConfiguration treeConfig) {
final List<QName> keyDefinition = schemaNode.getKeyDefinition();
final SchemaAwareApplyOperation op;
if (keyDefinition == null || keyDefinition.isEmpty()) {
return MinMaxElementsValidation.from(op, schemaNode);
}
- private static SchemaAwareApplyOperation fromLeafListSchemaNode(final LeafListSchemaNode schemaNode, final DataTreeConfiguration treeConfig) {
+ private static SchemaAwareApplyOperation fromLeafListSchemaNode(final LeafListSchemaNode schemaNode,
+ final DataTreeConfiguration treeConfig) {
final SchemaAwareApplyOperation op;
if (schemaNode.isUserOrdered()) {
op = new OrderedLeafSetModificationStrategy(schemaNode, treeConfig);
return MinMaxElementsValidation.from(op, schemaNode);
}
- protected static void checkNotConflicting(final YangInstanceIdentifier path, final TreeNode original, final TreeNode current) throws ConflictingModificationAppliedException {
+ protected static void checkNotConflicting(final YangInstanceIdentifier path, final TreeNode original,
+ final TreeNode current) throws ConflictingModificationAppliedException {
checkConflicting(path, original.getVersion().equals(current.getVersion()),
"Node was replaced by other transaction.");
checkConflicting(path, original.getSubtreeVersion().equals(current.getSubtreeVersion()),
}
@Override
- final void checkApplicable(final YangInstanceIdentifier path,final NodeModification modification, final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
+ final void checkApplicable(final YangInstanceIdentifier path,final NodeModification modification,
+ final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
switch (modification.getOperation()) {
- case DELETE:
- checkDeleteApplicable(modification, current);
- break;
- case TOUCH:
- checkTouchApplicable(path, modification, current, version);
- break;
- case WRITE:
- checkWriteApplicable(path, modification, current, version);
- break;
- case MERGE:
- checkMergeApplicable(path, modification, current, version);
- break;
- case NONE:
- break;
- default:
- throw new UnsupportedOperationException("Suplied modification type "+ modification.getOperation()+ " is not supported.");
+ case DELETE:
+ checkDeleteApplicable(modification, current);
+ break;
+ case TOUCH:
+ checkTouchApplicable(path, modification, current, version);
+ break;
+ case WRITE:
+ checkWriteApplicable(path, modification, current, version);
+ break;
+ case MERGE:
+ checkMergeApplicable(path, modification, current, version);
+ break;
+ case NONE:
+ break;
+ default:
+ throw new UnsupportedOperationException(
+ "Suplied modification type " + modification.getOperation() + " is not supported.");
}
}
* @param path Path from current node in TreeNode
* @param modification modification to apply
* @param current current node in TreeNode for modification to apply
- * @throws DataValidationFailedException
+ * @throws DataValidationFailedException when a data dependency conflict is detected
*/
protected void checkWriteApplicable(final YangInstanceIdentifier path, final NodeModification modification,
final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
if (original.isPresent() && current.isPresent()) {
checkNotConflicting(path, original.get(), current.get());
} else if (original.isPresent()) {
- throw new ConflictingModificationAppliedException(path,"Node was deleted by other transaction.");
+ throw new ConflictingModificationAppliedException(path, "Node was deleted by other transaction.");
} else if (current.isPresent()) {
throw new ConflictingModificationAppliedException(path, "Node was created by other transaction.");
}
}
@Override
- final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta, final Version version) {
+ final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
+ final Version version) {
switch (modification.getOperation()) {
- case DELETE:
- // Deletion of a non-existing node is a no-op, report it as such
- modification.resolveModificationType(currentMeta.isPresent() ? ModificationType.DELETE : ModificationType.UNMODIFIED);
- return modification.setSnapshot(Optional.absent());
- case TOUCH:
- Preconditions.checkArgument(currentMeta.isPresent(), "Metadata not available for modification %s",
+ case DELETE:
+ // Deletion of a non-existing node is a no-op, report it as such
+ modification.resolveModificationType(currentMeta.isPresent() ? ModificationType.DELETE
+ : ModificationType.UNMODIFIED);
+ return modification.setSnapshot(Optional.absent());
+ case TOUCH:
+ Preconditions.checkArgument(currentMeta.isPresent(), "Metadata not available for modification %s",
modification);
- return modification.setSnapshot(Optional.of(applyTouch(modification, currentMeta.get(),
+ return modification.setSnapshot(Optional.of(applyTouch(modification, currentMeta.get(),
version)));
- case MERGE:
- final TreeNode result;
+ case MERGE:
+ final TreeNode result;
- if (!currentMeta.isPresent()) {
- // This is a slight optimization: a merge on a non-existing node equals to a write. Written data
- // structure is usually verified when the transaction is sealed. To preserve correctness, we have
- // to run that validation here.
- modification.resolveModificationType(ModificationType.WRITE);
- result = applyWrite(modification, currentMeta, version);
- verifyStructure(result.getData(), true);
- } else {
- result = applyMerge(modification, currentMeta.get(), version);
- }
+ if (!currentMeta.isPresent()) {
+ // This is a slight optimization: a merge on a non-existing node equals to a write. Written data
+ // structure is usually verified when the transaction is sealed. To preserve correctness, we have
+ // to run that validation here.
+ modification.resolveModificationType(ModificationType.WRITE);
+ result = applyWrite(modification, currentMeta, version);
+ verifyStructure(result.getData(), true);
+ } else {
+ result = applyMerge(modification, currentMeta.get(), version);
+ }
- return modification.setSnapshot(Optional.of(result));
- case WRITE:
- modification.resolveModificationType(ModificationType.WRITE);
- return modification.setSnapshot(Optional.of(applyWrite(modification, currentMeta, version)));
- case NONE:
- modification.resolveModificationType(ModificationType.UNMODIFIED);
- return currentMeta;
- default:
- throw new IllegalArgumentException("Provided modification type is not supported.");
+ return modification.setSnapshot(Optional.of(result));
+ case WRITE:
+ modification.resolveModificationType(ModificationType.WRITE);
+ return modification.setSnapshot(Optional.of(applyWrite(modification, currentMeta, version)));
+ case NONE:
+ modification.resolveModificationType(ModificationType.UNMODIFIED);
+ return currentMeta;
+ default:
+ throw new IllegalArgumentException("Provided modification type is not supported.");
}
}
protected abstract TreeNode applyTouch(ModifiedNode modification, TreeNode currentMeta, Version version);
/**
- *
* Checks is supplied {@link NodeModification} is applicable for Subtree Modification.
*
* @param path Path to current node
* @param current Current state of data tree
* @throws ConflictingModificationAppliedException If subtree was changed in conflicting way
* @throws org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException If subtree
- * modification is not applicable (e.g. leaf node).
+ * modification is not applicable (e.g. leaf node).
*/
protected abstract void checkTouchApplicable(YangInstanceIdentifier path, NodeModification modification,
Optional<TreeNode> current, Version version) throws DataValidationFailedException;
/**
* SchemaValidationFailedException is thrown when an attempt is made to modify the data tree and the modification
- * does not match the schema context
+ * does not match the schema context.
*/
public class SchemaValidationFailedException extends IllegalArgumentException {
private static final long serialVersionUID = 1L;
- public SchemaValidationFailedException(String message){
+ public SchemaValidationFailedException(final String message) {
super(message);
}
- public SchemaValidationFailedException(String message, Throwable cause){
+ public SchemaValidationFailedException(final String message, final Throwable cause) {
super(message, cause);
}
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
private static final Version FAKE_VERSION = Version.initial();
private final ContainerModificationStrategy delegate;
- StructuralContainerModificationStrategy(final ContainerSchemaNode schemaNode, final DataTreeConfiguration treeConfig) {
+ StructuralContainerModificationStrategy(final ContainerSchemaNode schemaNode,
+ final DataTreeConfiguration treeConfig) {
this.delegate = new ContainerModificationStrategy(schemaNode, treeConfig);
}
}
@Override
- Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> storeMeta, final Version version) {
+ Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> storeMeta,
+ final Version version) {
final Optional<TreeNode> ret;
if (modification.getOperation() == LogicalOperation.TOUCH && !storeMeta.isPresent()) {
// Container is not present, let's take care of the 'magically appear' part of our job
}
@Override
- void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren) throws IllegalArgumentException {
+ void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren) {
delegate.verifyStructure(modification, verifyChildren);
}
}
@Override
- void mergeIntoModifiedNode(final ModifiedNode modification, final NormalizedNode<?, ?> value, final Version version) {
+ void mergeIntoModifiedNode(final ModifiedNode modification, final NormalizedNode<?, ?> value,
+ final Version version) {
delegate.mergeIntoModifiedNode(modification, value, version);
}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MutableTreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import javax.annotation.Nonnull;
import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
} else if (original instanceof MapEntryNode) {
return ImmutableMapEntryNodeBuilder.create((MapEntryNode) original);
}
- throw new IllegalArgumentException("MapModification strategy can only handle MapNode or MapEntryNode's, offending node: " + original);
+ throw new IllegalArgumentException("MapModification strategy can only handle MapNode or MapEntryNode's, "
+ + "offending node: " + original);
}
@Override
if (original instanceof MapNode) {
return ImmutableMapNodeBuilder.create().withNodeIdentifier(((MapNode) original).getIdentifier()).build();
} else if (original instanceof MapEntryNode) {
- return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(((MapEntryNode) original).getIdentifier()).build();
+ return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
+ ((MapEntryNode) original).getIdentifier()).build();
}
- throw new IllegalArgumentException("MapModification strategy can only handle MapNode or MapEntryNode's, offending node: " + original);
+ throw new IllegalArgumentException("MapModification strategy can only handle MapNode or MapEntryNode's, "
+ + "offending node: " + original);
}
@Override
/**
* Implementation of Upgradable {@link RootModificationApplyOperation}
*
+ * <p>
* This implementation is associated with {@link LatestOperationHolder}
* which holds latest available implementation, which may be used for
* upgrade.
*
+ * <p>
* Upgrading {@link LatestOperationHolder} will not affect any instance,
* unless client invoked {@link #upgradeIfPossible()} which will result in
* changing delegate to the latest one.
- *
*/
final class UpgradableModificationApplyOperation extends RootModificationApplyOperation {
private final LatestOperationHolder holder;
private ModificationApplyOperation delegate;
- UpgradableModificationApplyOperation(final LatestOperationHolder holder, final ModificationApplyOperation delegate) {
+ UpgradableModificationApplyOperation(final LatestOperationHolder holder,
+ final ModificationApplyOperation delegate) {
this.holder = holder;
this.delegate = delegate;
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import javax.annotation.Nonnull;
import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class WriteLeafCandidateNode extends AbstractWriteCandidate {
import org.custommonkey.xmlunit.DifferenceListener;
/**
- * Implementatin of {@link DifferenceListener} ignoring white characters around text elements
- * @author mirehak
+ * Implementatin of {@link DifferenceListener} ignoring white characters around text elements.
*
+ * @author mirehak
*/
public class IgnoreWhiteCharsDiffListener implements DifferenceListener {
-
+
@Override
public void skippedComparison(org.w3c.dom.Node control,
org.w3c.dom.Node test) {
- // do nothing
+ // do nothing
}
@Override
public int differenceFound(Difference diff) {
-
+
if (diff.getId() == DifferenceConstants.TEXT_VALUE.getId()) {
-
String control = diff.getControlNodeDetail().getValue();
if (control != null) {
control = control.trim();
* 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.data.impl;
/**
- * Provides memory consumption and elapsed time between 2 points
+ * Provides memory consumption and elapsed time between 2 points.
+ *
* @author mirehak
*/
public class MemoryConsumption {
-
private long memBegin;
private long tsBegin;
/**
- * record memory and timestamp
+ * Record memory and timestamp.
*/
public void startObserving() {
Runtime runtime = Runtime.getRuntime();
memBegin = getActualMemoryConsumption();
tsBegin = System.currentTimeMillis();
}
-
-
+
/**
+ * Return memory usage and elapsed time message.
+ *
* @return memory usage and time elapsed message
*/
public String finishObserving() {
long memEnd = getActualMemoryConsumption();
long tsEnd = System.currentTimeMillis();
- return String.format("Used memory: %10d B; Elapsed time: %5d ms", (memEnd - memBegin), (tsEnd - tsBegin));
+ return String.format("Used memory: %10d B; Elapsed time: %5d ms", memEnd - memBegin, tsEnd - tsBegin);
}
-
-
+
/**
+ * Return used memory.
+ *
* @return actual memory usage
*/
public static long getActualMemoryConsumption() {
long memory = runtime.totalMemory() - runtime.freeMemory();
return memory;
}
-
-
}
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
+
import com.google.common.io.BaseEncoding;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
BinaryCodec<String> codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class);
assertEquals("serialize", BaseEncoding.base64().encode(new byte[] { 1, 2, 3, 4 }),
- codec.serialize( new byte[] { 1, 2, 3, 4 }));
- assertEquals( "serialize", "", codec.serialize(null));
+ codec.serialize(new byte[] { 1, 2, 3, 4 }));
+ assertEquals("serialize", "", codec.serialize(null));
}
@SuppressWarnings("unchecked")
BinaryCodec<String> codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class);
assertArrayEquals("deserialize", new byte[] {1, 2, 3, 4 },
- codec.deserialize(BaseEncoding.base64().encode( new byte[] { 1, 2, 3, 4 })));
+ codec.deserialize(BaseEncoding.base64().encode(new byte[] { 1, 2, 3, 4 })));
assertEquals("deserialize", null, codec.deserialize(null));
}
}
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import org.junit.Test;
private static BitsTypeDefinition toBitsTypeDefinition(final String... bits) {
final BitsTypeBuilder b = BaseTypes.bitsTypeBuilder(mock(SchemaPath.class));
- long i = 0;
+ long pos = 0;
for (String bit : bits) {
BitsTypeDefinition.Bit mockBit = mock(BitsTypeDefinition.Bit.class);
when(mockBit.getName()).thenReturn(bit);
- when(mockBit.getPosition()).thenReturn(i);
+ when(mockBit.getPosition()).thenReturn(pos);
b.addBit(mockBit);
- ++i;
+ ++pos;
}
return b.build();
@Test
public void testSerialize() {
- BitsCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(
- toBitsTypeDefinition("foo"), BitsCodec.class);
+ BitsCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(toBitsTypeDefinition("foo"),
+ BitsCodec.class);
ImmutableSet<String> toSerialize = ImmutableSet.of("foo", "bar");
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
+
import java.math.BigDecimal;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.DecimalCodec;
DecimalCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(getType(), DecimalCodec.class);
assertEquals("serialize", "123.456", codec.serialize(new BigDecimal("123.456")));
- assertEquals("serialize", "", codec.serialize( null));
+ assertEquals("serialize", "", codec.serialize(null));
}
@SuppressWarnings("unchecked")
package org.opendaylight.yangtools.yang.data.impl.codecs;
import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.EnumCodec;
@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
- EnumCodec<String> codec = getCodec( toEnumTypeDefinition( "enum1", "enum2" ), EnumCodec.class);
+ EnumCodec<String> codec = getCodec(toEnumTypeDefinition("enum1", "enum2"), EnumCodec.class);
assertEquals("deserialize", "enum1", codec.deserialize("enum1"));
assertEquals("deserialize", "enum2", codec.deserialize("enum2"));
import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Int16Codec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
package org.opendaylight.yangtools.yang.data.impl.codecs;
import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Int32Codec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public void testSerialize() {
Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class);
- assertEquals("serialize", "10", codec.serialize(Integer.valueOf( 10 )));
+ assertEquals("serialize", "10", codec.serialize(Integer.valueOf(10)));
assertEquals("serialize", "", codec.serialize(null));
}
import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Int64Codec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public void testSerialize() {
Int64Codec<String> codec = getCodec(BaseTypes.int64Type(), Int64Codec.class);
- assertEquals("serialize", "12345", codec.serialize(Long.valueOf( 12345 )));
+ assertEquals("serialize", "12345", codec.serialize(Long.valueOf(12345)));
assertEquals("serialize", "", codec.serialize(null));
}
package org.opendaylight.yangtools.yang.data.impl.codecs;
import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public void testSerialize() {
Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class);
- assertEquals("serialize", "10", codec.serialize(Byte.valueOf( (byte) 10 )));
+ assertEquals("serialize", "10", codec.serialize(Byte.valueOf((byte) 10)));
assertEquals("serialize", "", codec.serialize(null));
}
package org.opendaylight.yangtools.yang.data.impl.codecs;
import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- StringCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.stringType(), StringCodec.class);
+ StringCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.stringType(),
+ StringCodec.class);
assertEquals("serialize", "foo", codec.serialize("foo"));
assertEquals("serialize", "", codec.serialize(""));
@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
- StringCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.stringType(), StringCodec.class);
+ StringCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.stringType(),
+ StringCodec.class);
assertEquals("deserialize", "bar", codec.deserialize("bar"));
assertEquals("deserialize", "", codec.deserialize(""));
@Test
public void testStringPatternCheckingCodec() throws ReactorException, ParseException, URISyntaxException,
FileNotFoundException {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/string-pattern-checking-codec-test.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
+ "/string-pattern-checking-codec-test.yang");
assertNotNull(schemaContext);
final QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"),
fail("Exception should have been thrown.");
} catch (final IllegalArgumentException ex) {
LOG.debug("IllegalArgumentException was thrown as expected: {}", ex);
- assertTrue(ex.getMessage().contains("Supplied value does not match the regular expression ^[A-Z]+$. [abcd]"));
+ assertTrue(ex.getMessage().contains(
+ "Supplied value does not match the regular expression ^[A-Z]+$. [abcd]"));
}
}
}
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
public class TypeDefinitionAwareCodecTestHelper {
@SuppressWarnings("unchecked")
- public static <T> T getCodec( final TypeDefinition<?> def, final Class<T> clazz) {
+ public static <T> T getCodec(final TypeDefinition<?> def, final Class<T> clazz) {
Object codec = TypeDefinitionAwareCodec.from(def);
assertNotNull(codec);
assertTrue(clazz.isAssignableFrom(codec.getClass()));
public static EnumTypeDefinition toEnumTypeDefinition(final String... enums) {
final EnumerationTypeBuilder b = BaseTypes.enumerationTypeBuilder(mock(SchemaPath.class));
- int i = 0;
+ int val = 0;
for (String en : enums) {
EnumTypeDefinition.EnumPair mockEnum = mock(EnumTypeDefinition.EnumPair.class);
when(mockEnum.getName()).thenReturn(en);
- when(mockEnum.getValue()).thenReturn(i);
+ when(mockEnum.getValue()).thenReturn(val);
b.addEnum(mockEnum);
- i++;
+ val++;
}
return b.build();
import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Uint16Codec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Uint32Codec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public void testSerialize() {
Uint32Codec<String> codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class);
- assertEquals("serialize", "10", codec.serialize(Long.valueOf( 10 )));
+ assertEquals("serialize", "10", codec.serialize(Long.valueOf(10)));
assertEquals("serialize", "", codec.serialize(null));
}
package org.opendaylight.yangtools.yang.data.impl.codecs;
import static org.junit.Assert.assertEquals;
+
import java.math.BigInteger;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Uint64Codec;
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(), Uint64Codec.class);
+ Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(),
+ Uint64Codec.class);
- assertEquals("serialize", "123456789", codec.serialize(BigInteger.valueOf( 123456789 )));
+ assertEquals("serialize", "123456789", codec.serialize(BigInteger.valueOf(123456789)));
assertEquals("serialize", "", codec.serialize(null));
}
final String octal = "03536670743556272";
final String integer = "129664115727546";
- Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(), Uint64Codec.class);
+ Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(),
+ Uint64Codec.class);
assertEquals("deserialize", codec.deserialize(hexa), new BigInteger("75EDC78edCBA", 16));
assertEquals("deserialize", codec.deserialize(octal), new BigInteger(octal, 8));
import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Uint8Codec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public void testSerialize() {
Uint8Codec<String> codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class);
- assertEquals("serialize", "10", codec.serialize(Short.valueOf((short) 10 )));
+ assertEquals("serialize", "10", codec.serialize(Short.valueOf((short) 10)));
assertEquals("serialize", "", codec.serialize(null));
}
* 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.data.impl.codecs;
import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.UnionCodec;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation;
}
private static void initDataTree() {
- inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(DataTreeConfiguration.DEFAULT_OPERATIONAL);
inMemoryDataTree.setSchemaContext(context);
final DataTreeModification initialDataTreeModification = inMemoryDataTree
final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
.prepare(initialDataTreeModification);
inMemoryDataTree.commit(writeContributorsCandidate);
-
}
@Test
return containerBuilder.build();
}
- private static MapEntryNode createList3Entry(final String kVal,
+ private static MapEntryNode createList3Entry(final String keyVal,
final String l3Val1, final String l3Val2, final String l3Val3) {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
.mapEntryBuilder();
mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
- list3InChoice, k, kVal));
+ list3InChoice, k, keyVal));
final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
.leafSetBuilder();
leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
- mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, kVal));
+ mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
mapEntryBuilder.addChild(leafSetBuilder.build());
return mapEntryBuilder.build();
final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(
odlProjectDesc, odlProjectDescVal);
- final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> contributorMapEntryBldr = Builders
- .mapEntryBuilder(contributorListSchemaNode);
-
- contributorMapEntryBldr.addChild(loginLeaf);
- contributorMapEntryBldr.addChild(contributorNameLeaf);
- contributorMapEntryBldr.addChild(odlProjectNameLeafRef);
- contributorMapEntryBldr.addChild(odlProjectDescLeafRef);
-
- final MapEntryNode contributorMapEntry = contributorMapEntryBldr
+ return Builders.mapEntryBuilder(contributorListSchemaNode)
+ .addChild(loginLeaf)
+ .addChild(contributorNameLeaf)
+ .addChild(odlProjectNameLeafRef)
+ .addChild(odlProjectDescLeafRef)
.build();
-
- return contributorMapEntry;
}
private static ContainerNode createOdlContainer(
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation;
LOG.debug("*************************");
LOG.debug("Before writeDevices: ");
LOG.debug("*************************");
- LOG.debug(inMemoryDataTree.toString());
+ LOG.debug("{}", inMemoryDataTree);
boolean exception = false;
try {
LOG.debug("*************************");
LOG.debug("After write: ");
LOG.debug("*************************");
- LOG.debug(inMemoryDataTree.toString());
+ LOG.debug("{}", inMemoryDataTree);
}
private static void initQnames() {
private static void initDataTree() {
- inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(DataTreeConfiguration.DEFAULT_OPERATIONAL);
inMemoryDataTree.setSchemaContext(context);
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
inMemoryDataTree.commit(writeChipsCandidate);
- System.out.println(inMemoryDataTree.toString());
+ LOG.debug("{}", inMemoryDataTree);
}
private static void initLeafRefContext() {
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation;
LOG.debug("*************************");
LOG.debug("Before writeDevices: ");
LOG.debug("*************************");
- LOG.debug(inMemoryDataTree.toString());
+ LOG.debug("{}", inMemoryDataTree);
boolean exception = false;
try {
LOG.debug("*************************");
LOG.debug("After writeDevices: ");
LOG.debug("*************************");
- LOG.debug(inMemoryDataTree.toString());
+ LOG.debug("{}", inMemoryDataTree);
}
private static void mergeDevices() {
LOG.debug("*************************");
LOG.debug("Before mergeDevices: ");
LOG.debug("*************************");
- LOG.debug(inMemoryDataTree.toString());
+ LOG.debug("{}", inMemoryDataTree);
boolean exception = false;
try {
LOG.debug("*************************");
LOG.debug("After mergeDevices: ");
LOG.debug("*************************");
- LOG.debug(inMemoryDataTree.toString());
+ LOG.debug("{}", inMemoryDataTree);
assertTrue(exception);
}
private static void initDataTree() {
- inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(DataTreeConfiguration.DEFAULT_OPERATIONAL);
inMemoryDataTree.setSchemaContext(context);
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
inMemoryDataTree.commit(writeChipsCandidate);
- System.out.println(inMemoryDataTree.toString());
+ LOG.debug("{}", inMemoryDataTree);
}
private static void initLeafRefContext() {
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class LeafRefContextTreeBuilderTest {
+ private static final Logger LOG = LoggerFactory.getLogger(LeafRefContextTreeBuilderTest.class);
private static SchemaContext context;
private static Module impMod;
assertNotNull(leafRefCtx.getAbsoluteLeafRefTargetPath());
assertTrue(leafRefCtx.getAbsoluteLeafRefTargetPath().isAbsolute());
- System.out.println();
- System.out.println("******* Test 1 ************");
- System.out.println("Original definition string:");
- System.out.println(leafRefCtx.getLeafRefTargetPathString());
- System.out.println("Parsed leafref path:");
- System.out.println(leafRefCtx.getLeafRefTargetPath().toString());
- System.out.println("Absolute leafref path:");
- System.out.println(leafRefCtx.getAbsoluteLeafRefTargetPath().toString());
+ LOG.debug("******* Test 1 ************");
+ LOG.debug("Original definition string: {}", leafRefCtx.getLeafRefTargetPathString());
+ LOG.debug("Parsed leafref path: {}", leafRefCtx.getLeafRefTargetPath());
+ LOG.debug("Absolute leafref path: {}", leafRefCtx.getAbsoluteLeafRefTargetPath());
}
@Test
assertNotNull(leafRefCtx2.getAbsoluteLeafRefTargetPath());
assertTrue(leafRefCtx2.getAbsoluteLeafRefTargetPath().isAbsolute());
- System.out.println();
- System.out.println("******* Test 2 ************");
- System.out.println("Original definition string2:");
- System.out.println(leafRefCtx2.getLeafRefTargetPathString());
- System.out.println("Parsed leafref path2:");
- System.out.println(leafRefCtx2.getLeafRefTargetPath().toString());
- System.out.println("Absolute leafref path2:");
- System.out.println(leafRefCtx2.getAbsoluteLeafRefTargetPath().toString());
- System.out.println();
-
+ LOG.debug("******* Test 2 ************");
+ LOG.debug("Original definition string2: {}", leafRefCtx2.getLeafRefTargetPathString());
+ LOG.debug("Parsed leafref path2: {}", leafRefCtx2.getLeafRefTargetPath());
+ LOG.debug("Absolute leafref path2: {}", leafRefCtx2.getAbsoluteLeafRefTargetPath());
}
@Test
assertNotNull(leafRefCtx3.getAbsoluteLeafRefTargetPath());
assertTrue(leafRefCtx3.getAbsoluteLeafRefTargetPath().isAbsolute());
- System.out.println();
- System.out.println("******* Test 3 ************");
- System.out.println("Original definition string2:");
- System.out.println(leafRefCtx3.getLeafRefTargetPathString());
- System.out.println("Parsed leafref path2:");
- System.out.println(leafRefCtx3.getLeafRefTargetPath().toString());
- System.out.println("Absolute leafref path2:");
- System.out.println(leafRefCtx3.getAbsoluteLeafRefTargetPath().toString());
- System.out.println();
+ LOG.debug("******* Test 3 ************");
+ LOG.debug("Original definition string2: {}", leafRefCtx3.getLeafRefTargetPathString());
+ LOG.debug("Parsed leafref path2: {}", leafRefCtx3.getLeafRefTargetPath());
+ LOG.debug("Absolute leafref path2: {}", leafRefCtx3.getAbsoluteLeafRefTargetPath());
}
@Test
assertNotNull(allChildsReferencedByLeafRef);
assertTrue(allChildsReferencedByLeafRef.isEmpty());
-
}
@Test(expected = IllegalArgumentException.class)
"/leafref-context-test/incorrect-modules");
LeafRefContext.create(context);
}
-
}
import org.junit.Test;
import org.opendaylight.yangtools.util.UnmodifiableCollection;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class BuilderTest {
- private static final QName ROOT_CONTAINER = QName.create("test.namespace.builder.test", "2016-01-01", "root-container");
+ private static final QName ROOT_CONTAINER = QName.create("test.namespace.builder.test", "2016-01-01",
+ "root-container");
private static final QName LIST_MAIN = QName.create(ROOT_CONTAINER, "list-ordered-by-user-with-key");
private static final QName LEAF_LIST_MAIN = QName.create(ROOT_CONTAINER, "leaf-list-ordered-by-user");
private static final QName LIST_MAIN_CHILD_QNAME_1 = QName.create(ROOT_CONTAINER, "leaf-a");
- private static final YangInstanceIdentifier.NodeIdentifier NODE_IDENTIFIER_LIST = YangInstanceIdentifier.NodeIdentifier
- .create(LIST_MAIN);
- private static final YangInstanceIdentifier.NodeIdentifier NODE_IDENTIFIER_LEAF_LIST = YangInstanceIdentifier.NodeIdentifier
- .create(LEAF_LIST_MAIN);
- private static final YangInstanceIdentifier.NodeIdentifier NODE_IDENTIFIER_LEAF = YangInstanceIdentifier
- .NodeIdentifier.create(LIST_MAIN_CHILD_QNAME_1);
- private static final MapEntryNode LIST_MAIN_CHILD_1 = ImmutableNodes.mapEntry(LIST_MAIN, LIST_MAIN_CHILD_QNAME_1, 1);
- private static final MapEntryNode LIST_MAIN_CHILD_2 = ImmutableNodes.mapEntry(LIST_MAIN, LIST_MAIN_CHILD_QNAME_1, 2);
- private static final MapEntryNode LIST_MAIN_CHILD_3 = ImmutableNodes.mapEntry(LIST_MAIN, LIST_MAIN_CHILD_QNAME_1, 3);
+ private static final NodeIdentifier NODE_IDENTIFIER_LIST = NodeIdentifier.create(LIST_MAIN);
+ private static final NodeIdentifier NODE_IDENTIFIER_LEAF_LIST = NodeIdentifier.create(LEAF_LIST_MAIN);
+ private static final NodeIdentifier NODE_IDENTIFIER_LEAF = NodeIdentifier.create(LIST_MAIN_CHILD_QNAME_1);
+ private static final MapEntryNode LIST_MAIN_CHILD_1 = ImmutableNodes.mapEntry(LIST_MAIN, LIST_MAIN_CHILD_QNAME_1,
+ 1);
+ private static final MapEntryNode LIST_MAIN_CHILD_2 = ImmutableNodes.mapEntry(LIST_MAIN, LIST_MAIN_CHILD_QNAME_1,
+ 2);
+ private static final MapEntryNode LIST_MAIN_CHILD_3 = ImmutableNodes.mapEntry(LIST_MAIN, LIST_MAIN_CHILD_QNAME_1,
+ 3);
private static final int SIZE = 3;
private static final NodeWithValue<String> BAR_PATH = new NodeWithValue<>(LEAF_LIST_MAIN, "bar");
private static final LeafSetEntryNode LEAF_SET_ENTRY_NODE = ImmutableLeafSetEntryNodeBuilder.create()
mapEntryNodeColl.add(LIST_MAIN_CHILD_3);
final Map<QName, Object> keys = new HashMap<>();
keys.put(LIST_MAIN_CHILD_QNAME_1, 1);
- final YangInstanceIdentifier.NodeIdentifierWithPredicates mapEntryPath = new YangInstanceIdentifier
- .NodeIdentifierWithPredicates(LIST_MAIN, keys);
+ final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(LIST_MAIN, keys);
final OrderedMapNode orderedMapNodeCreateNull = ImmutableOrderedMapNodeBuilder.create()
.withNodeIdentifier(NODE_IDENTIFIER_LIST)
.withChild(LIST_MAIN_CHILD_1)
final OrderedMapNode orderedMapNodeSchemaAware = ImmutableOrderedMapNodeSchemaAwareBuilder.create(list)
.withChild(LIST_MAIN_CHILD_1)
.build();
- final OrderedMapNode orderedMapNodeSchemaAwareMapNodeConst = ImmutableOrderedMapNodeSchemaAwareBuilder.create
- (list, getImmutableOrderedMapNode())
+ final OrderedMapNode orderedMapNodeSchemaAwareMapNodeConst = ImmutableOrderedMapNodeSchemaAwareBuilder.create(
+ list, getImmutableOrderedMapNode())
.build();
assertNotNull(Builders.orderedMapBuilder(list));
final LinkedList<LeafSetNode<?>> mapEntryNodeColl = new LinkedList<>();
mapEntryNodeColl.add((LeafSetNode<?>)orderedLeafSet);
final UnmodifiableCollection<?> leafSetCollection = (UnmodifiableCollection<?>)orderedLeafSet.getValue();
- final NormalizedNode<?, ?> orderedMapNodeSchemaAware = ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(leafList)
- .withChildValue("baz")
- .build();
- final UnmodifiableCollection<?> SchemaAwareleafSetCollection = (UnmodifiableCollection<?>)orderedMapNodeSchemaAware
- .getValue();
- final NormalizedNode<?, ?> orderedLeafSetShemaAware = ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(leafList,
- (LeafSetNode<?>)orderedLeafSet)
- .build();
+ final NormalizedNode<?, ?> orderedMapNodeSchemaAware = ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(
+ leafList).withChildValue("baz").build();
+ final UnmodifiableCollection<?> SchemaAwareleafSetCollection =
+ (UnmodifiableCollection<?>)orderedMapNodeSchemaAware.getValue();
+ final NormalizedNode<?, ?> orderedLeafSetShemaAware = ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(
+ leafList,(LeafSetNode<?>)orderedLeafSet).build();
assertNotNull(Builders.orderedLeafSetBuilder(leafList));
assertNotNull(Builders.anyXmlBuilder());
collectionNodeBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST);
collectionNodeBuilder.withValue(mapEntryNodeColl);
final MapNode mapNode = collectionNodeBuilder.build();
- final MapNode mapNodeSchemaAware = ImmutableMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode()).build();
+ final MapNode mapNodeSchemaAware = ImmutableMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode())
+ .build();
assertNotNull(mapNodeSchemaAware);
assertNotNull(Builders.mapBuilder(mapNode));
}
final UnkeyedListEntryNode unkeyedListEntryNodeSize = ImmutableUnkeyedListEntryNodeBuilder.create(1)
.withNodeIdentifier(NODE_IDENTIFIER_LIST)
.build();
- final UnkeyedListEntryNode unkeyedListEntryNodeNode = ImmutableUnkeyedListEntryNodeBuilder.create(unkeyedListEntryNode)
- .build();
+ final UnkeyedListEntryNode unkeyedListEntryNodeNode = ImmutableUnkeyedListEntryNodeBuilder
+ .create(unkeyedListEntryNode).build();
assertEquals(unkeyedListEntryNode.getNodeType().getLocalName(), unkeyedListEntryNodeSize.getNodeType()
.getLocalName());
assertEquals(unkeyedListEntryNodeSize.getNodeType().getLocalName(), unkeyedListEntryNodeNode.getNodeType()
.build();
final ImmutableUnkeyedListNodeBuilder immutableUnkeyedListNodeBuilder = (ImmutableUnkeyedListNodeBuilder)
ImmutableUnkeyedListNodeBuilder.create();
- final UnkeyedListNode unkeyedListNode = immutableUnkeyedListNodeBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
+ final UnkeyedListNode unkeyedListNode = immutableUnkeyedListNodeBuilder
+ .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
.addChild(unkeyedListEntryNode)
.build();
final UnkeyedListNode unkeyedListNodeSize = ImmutableUnkeyedListNodeBuilder.create(1)
try {
unkeyedListNodeSize.getChild(1);
} catch (IndexOutOfBoundsException e) {
+ // Ignored on purpose
}
assertNotNull(unkeyedListNodeSize.getValue());
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void immutableAugmentationNodeBuilderExceptionTest() {
ImmutableAugmentationNodeBuilder.create(1).build();
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void immutableContainerNodeBuilderExceptionTest() {
final ContainerNode immutableContainerNode = ImmutableContainerNodeBuilder.create(1)
.withNodeIdentifier(NODE_IDENTIFIER_LIST)
.build();
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void immutableLeafSetNodeBuilderExceptionTest() {
- final LeafSetNode<?> leafSetNode = ImmutableLeafSetNodeBuilder.create(1).withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
- .build();
+ final LeafSetNode<?> leafSetNode = ImmutableLeafSetNodeBuilder.create(1)
+ .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).build();
assertNotNull(leafSetNode);
ImmutableLeafSetNodeSchemaAwareBuilder.create(mock(LeafListSchemaNode.class), leafSetNode).build();
}
- @Test(expected=UnsupportedOperationException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void immutableLeafSetEntryNodeSchemaAwareBuilderExceptionTest() {
final LeafListSchemaNode leafListSchemaNode = mock(LeafListSchemaNode.class);
ImmutableLeafSetEntryNodeSchemaAwareBuilder.create(leafListSchemaNode).withNodeIdentifier(BAR_PATH).build();
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void immutableMapEntryNodeBuilderExceptionTest() {
ImmutableMapEntryNodeBuilder.create(1).build();
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void immutableYangModeledAnyXmlNodeBuilderExceptionTest() {
ImmutableYangModeledAnyXmlNodeBuilder.create(mock(YangModeledAnyXmlSchemaNode.class), 1);
}
- @Test(expected=UnsupportedOperationException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void immutableUnkeyedListNodeBuilderExceptionTest() {
ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF)
.removeChild(NODE_IDENTIFIER_LIST).build();
}
- @Test(expected=UnsupportedOperationException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void immutableOrderedMapNotSchemaAwareExceptionTest1() {
ImmutableOrderedMapNodeBuilder.create(getImmutableMapNode()).build();
}
- @Test(expected=UnsupportedOperationException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void immutableMapNodeSchemaAwareExceptionTest() {
- ImmutableMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode()).withNodeIdentifier(NODE_IDENTIFIER_LIST).build();
+ ImmutableMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode()).withNodeIdentifier(NODE_IDENTIFIER_LIST)
+ .build();
}
- @Test(expected=UnsupportedOperationException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void immutableOrderedMapSchemaAwareExceptionTest1() {
ImmutableOrderedMapNodeSchemaAwareBuilder.create(list).withNodeIdentifier(NODE_IDENTIFIER_LIST).build();
}
- @Test(expected=UnsupportedOperationException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void immutableOrderedMapSchemaAwareExceptionTest2() {
ImmutableOrderedMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode()).build();
}
- @Test(expected=UnsupportedOperationException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void immutableOrderedLeafSetNodeExceptionTest1() {
ImmutableOrderedLeafSetNodeBuilder.create(getImmutableLeafSetNode()).build();
}
- @Test(expected=UnsupportedOperationException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void immutableOrderedLeafSetNodeSchemaAwareExceptionTest1() {
- ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(leafList).withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).build();
+ ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(leafList).withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
+ .build();
}
private static LeafSetNode<?> getImmutableLeafSetNode() {
}
private static MapNode getImmutableMapNode() {
- return ImmutableMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST).withChild(LIST_MAIN_CHILD_1).build();
+ return ImmutableMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST).withChild(LIST_MAIN_CHILD_1)
+ .build();
}
private static MapNode getImmutableOrderedMapNode() {
- return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST).withChild(LIST_MAIN_CHILD_1)
- .build();
+ return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST)
+ .withChild(LIST_MAIN_CHILD_1).build();
}
-}
\ No newline at end of file
+}
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
public class ImmutableNormalizedNodeStreamWriterTest {
@Before
public void setup() throws URISyntaxException, ParseException {
- bazModule = QNameModule.create(new URI("baz-namespace"), SimpleDateFormatUtil.getRevisionFormat().parse
- ("1970-01-01"));
+ bazModule = QNameModule.create(new URI("baz-namespace"), SimpleDateFormatUtil.getRevisionFormat()
+ .parse("1970-01-01"));
outerContainer = QName.create(bazModule, "outer-container");
.withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2))
.withValue("listleafvalue22").build()).build()).build();
- OrderedMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(myOrderedList))
+ OrderedMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ new NodeIdentifier(myOrderedList))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
new NodeIdentifierWithPredicates(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue1"))
.withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList1))
YangInstanceIdentifier.create(rootContainer, leafList, leafListWithValue));
assertEquals(expectedFilter, filter);
}
-}
\ No newline at end of file
+}
.containerBuilder().withNodeIdentifier(getNodeIdentifier("container"));
// leaf
- LeafNode<String> leafChild = Builders.<String> leafBuilder().withNodeIdentifier(getNodeIdentifier("leaf"))
+ LeafNode<String> leafChild = Builders.<String>leafBuilder().withNodeIdentifier(getNodeIdentifier("leaf"))
.withValue("String").build();
builder.withChild(leafChild);
// leafList
- LeafSetNode<Integer> leafList = Builders
- .<Integer> leafSetBuilder()
+ LeafSetNode<Integer> leafList = Builders.<Integer>leafSetBuilder()
.withNodeIdentifier(getNodeIdentifier("leaf"))
.withChildValue(1)
.withChild(
- Builders.<Integer> leafSetEntryBuilder()
+ Builders.<Integer>leafSetEntryBuilder()
.withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
.build();
builder.withChild(leafList);
MapEntryNode listChild1 = Builders
.mapEntryBuilder()
.withChild(
- Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList"))
+ Builders.<Integer>leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList"))
.withValue(1).build())
.withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build())
.withNodeIdentifier(
// This works without schema (adding child from augment as a direct
// child)
- builder.withChild(Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
+ builder.withChild(Builders.<Integer>leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
.withValue(11).build());
}
@Test
public void testSchemaAware() {
- DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = Builders
- .containerBuilder(containerNode);
+ DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = Builders.containerBuilder(containerNode);
LeafSchemaNode schemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "uint32");
- LeafNode<String> leafChild = Builders.<String> leafBuilder(schemaNode).withValue("String").build();
+ LeafNode<String> leafChild = Builders.<String>leafBuilder(schemaNode).withValue("String").build();
builder.withChild(leafChild);
LeafListSchemaNode leafListSchemaNode = (LeafListSchemaNode) getSchemaNode(schema, "test", "leafList");
- LeafSetNode<Integer> leafList = Builders.<Integer> leafSetBuilder(leafListSchemaNode).withChildValue(1)
- .withChild(Builders.<Integer> leafSetEntryBuilder(leafListSchemaNode).withValue(3).build()).build();
+ LeafSetNode<Integer> leafList = Builders.<Integer>leafSetBuilder(leafListSchemaNode).withChildValue(1)
+ .withChild(Builders.<Integer>leafSetEntryBuilder(leafListSchemaNode).withValue(3).build()).build();
builder.withChild(leafList);
ListSchemaNode listSchema = (ListSchemaNode) getSchemaNode(schema, "test", "list");
"containerInList");
MapEntryNode listChild1 = Builders.mapEntryBuilder(listSchema)
- .withChild(Builders.<Integer> leafBuilder(uint32InListSchemaNode).withValue(1).build())
+ .withChild(Builders.<Integer>leafBuilder(uint32InListSchemaNode).withValue(1).build())
.withChild(Builders.containerBuilder(containerInListSchemaNode).build()).build();
MapNode list = ImmutableMapNodeSchemaAwareBuilder.create(listSchema).withChild(listChild1).build();
augmentUint32SchemaNode.getQName());
AugmentationNode augmentation = Builders.augmentationBuilder(augmentationSchema)
- .withChild(Builders.<Integer> leafBuilder(augmentUint32SchemaNode).withValue(11).build()).build();
+ .withChild(Builders.<Integer>leafBuilder(augmentUint32SchemaNode).withValue(11).build()).build();
builder.withChild(augmentation);
// This should fail with schema, since the leaf comes from augmentation
- // builder.withChild(ImmutableLeafNodeSchemaAwareBuilder.<Integer>get(augmentUint32SchemaNode).withValue(11).build());
+ // builder.withChild(ImmutableLeafNodeSchemaAwareBuilder.<Integer>get(augmentUint32SchemaNode).withValue(11)
+ // .build());
LeafSchemaNode augumentString1SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentString1");
LeafSchemaNode augumentString2SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentString2");
ChoiceSchemaNode choice1SchemaNode = (ChoiceSchemaNode) getSchemaNode(schema, "test", "choice");
ChoiceNode choice = ImmutableChoiceNodeSchemaAwareBuilder.create(choice1SchemaNode)
- .withChild(Builders.<String> leafBuilder(augumentString1SchemaNode).withValue("case1").build())
+ .withChild(Builders.<String>leafBuilder(augumentString1SchemaNode).withValue("case1").build())
// This should fail, since child node belongs to different case
// .withChild(Builders.<String>leafBuilder(augumentString2SchemaNode).withValue("case2")
// .build())
}
private static AugmentationSchema getAugmentationSchemaForChild(final ContainerSchemaNode containerNode,
- final QName qName) {
+ final QName qname) {
for (AugmentationSchema augmentationSchema : containerNode.getAvailableAugmentations()) {
- if (augmentationSchema.getDataChildByName(qName) != null) {
+ if (augmentationSchema.getDataChildByName(qname) != null) {
return augmentationSchema;
}
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-/**
- *
- * Schema structure of document is
+/*
+ * Schema structure of document is:
*
- * <pre>
* container root {Â
* list list-a {
* key leaf-a;
* }
* }
* }
- * </pre>
- *
*/
public class NormalizedNodeUtilsTest {
.build();
/**
- * Returns a test document
+ * Returns a test document.
*
* <pre>
* root
*
* @return A test document
*/
- public NormalizedNode<?, ?> createDocumentOne() {
+ private static NormalizedNode<?, ?> createDocumentOne() {
return ImmutableContainerNodeBuilder
.create()
.withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
Optional<NormalizedNode<?, ?>> listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH);
assertTrue(listTwoResult.isPresent());
}
-
}
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class SchemaUtilsTest {
- private static String NS = "my-namespace";
- private static String REV = "1970-01-01";
+ private static final String NS = "my-namespace";
+ private static final String REV = "1970-01-01";
@Test
public void test() throws Exception {
assertTrue(target.iterator().next() instanceof ContainerSchemaNode);
// test l schema nodes (i.e. container and two leafs)
- Collection<SchemaNode> l = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
+ Collection<SchemaNode> schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-3"), qN("l")));
- assertEquals(1, l.size());
- assertTrue(l.iterator().next() instanceof ContainerSchemaNode);
+ assertEquals(1, schema.size());
+ assertTrue(schema.iterator().next() instanceof ContainerSchemaNode);
- l = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
+ schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-1"), qN("l")));
- assertEquals(1, l.size());
- assertTrue(l.iterator().next() instanceof LeafSchemaNode);
+ assertEquals(1, schema.size());
+ assertTrue(schema.iterator().next() instanceof LeafSchemaNode);
- l = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
+ schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-2"), qN("l")));
- assertTrue(l.isEmpty());
+ assertTrue(schema.isEmpty());
- l = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
+ schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-3"), qN("output"), qN("con-2"), qN("l")));
- assertEquals(1, l.size());
- assertTrue(l.iterator().next() instanceof LeafSchemaNode);
+ assertEquals(1, schema.size());
+ assertTrue(schema.iterator().next() instanceof LeafSchemaNode);
}
- private QName qN(final String localName) {
+ private static QName qN(final String localName) {
return QName.create(NS, REV, localName);
}
-
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
public class AbstractImmutableNormalizedValueAttrNodeTest {
- private static QName ROOT_QNAME = QName.create("urn:test", "2014-03-13",
- "root");
- private static QName LEAF_QNAME = QName.create(ROOT_QNAME, "my-leaf");
- private static QName SAME_LEAF_QNAME = QName.create(ROOT_QNAME, "my-leaf");
- private static QName OTHER_LEAF_QNAME = QName.create(ROOT_QNAME,
- "my-other-leaf");
+ private static final QName ROOT_QNAME = QName.create("urn:test", "2014-03-13", "root");
+ private static final QName LEAF_QNAME = QName.create(ROOT_QNAME, "my-leaf");
+ private static final QName SAME_LEAF_QNAME = QName.create(ROOT_QNAME, "my-leaf");
+ private static final QName OTHER_LEAF_QNAME = QName.create(ROOT_QNAME, "my-other-leaf");
@Test
// This test is based on using different references; we're testing equals()
@SuppressWarnings({"RedundantStringConstructorCall", "EqualsWithItself"})
public void equalsByteTest() {
- LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(LEAF_QNAME,
- null);
- LeafNode<byte[]> equalLeafNodeNull = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, null);
+ LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(LEAF_QNAME, null);
+ LeafNode<byte[]> equalLeafNodeNull = ImmutableNodes.leafNode(SAME_LEAF_QNAME, null);
assertTrue(leafNodeNull.equals(leafNodeNull));
assertTrue(leafNodeNull.equals(equalLeafNodeNull));
byte[] equalValue = "test".getBytes();
LeafNode<byte[]> leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value);
- LeafNode<byte[]> equalLeafNode = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue);
+ LeafNode<byte[]> equalLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue);
assertTrue(leafNode.equals(leafNode));
assertTrue(leafNode.equals(equalLeafNode));
LeafNode<Byte[]> leafNode2 = ImmutableNodes
.leafNode(LEAF_QNAME, value2);
- LeafNode<Byte[]> equalLeafNode2 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue2);
+ LeafNode<Byte[]> equalLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue2);
assertTrue(leafNode2.equals(leafNode2));
assertTrue(leafNode2.equals(equalLeafNode2));
assertTrue(equalLeafNode2.equals(leafNode2));
byte[][] value3 = new byte[][] { "test".getBytes(), "test2".getBytes() };
- byte[][] equalValue3 = new byte[][] { "test".getBytes(),
- "test2".getBytes() };
+ byte[][] equalValue3 = new byte[][] { "test".getBytes(), "test2".getBytes() };
LeafNode<byte[][]> leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME,
value3);
- LeafNode<byte[][]> equalLeafNode3 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue3);
+ LeafNode<byte[][]> equalLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue3);
assertTrue(leafNode3.equals(leafNode3));
assertTrue(leafNode3.equals(equalLeafNode3));
assertTrue(equalLeafNode3.equals(leafNode3));
Byte[][] value4 = new Byte[][] {
- new Byte[] { new Byte("1"), new Byte("2") },
- new Byte[] { new Byte("3"), new Byte("4") } };
+ new Byte[] { new Byte("1"), new Byte("2") },
+ new Byte[] { new Byte("3"), new Byte("4") },
+ };
Byte[][] equalValue4 = new Byte[][] {
- new Byte[] { new Byte("1"), new Byte("2") },
- new Byte[] { new Byte("3"), new Byte("4") } };
+ new Byte[] { new Byte("1"), new Byte("2") },
+ new Byte[] { new Byte("3"), new Byte("4") },
+ };
- LeafNode<Byte[][]> leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME,
- value4);
- LeafNode<Byte[][]> equalLeafNode4 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue4);
+ LeafNode<Byte[][]> leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME,value4);
+ LeafNode<Byte[][]> equalLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue4);
assertTrue(leafNode4.equals(leafNode4));
assertTrue(leafNode4.equals(equalLeafNode4));
String value5 = "test";
String equalValue5 = new String("test");
- LeafNode<String> leafNode5 = ImmutableNodes
- .leafNode(LEAF_QNAME, value5);
- LeafNode<String> equalLeafNode5 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue5);
+ LeafNode<String> leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5);
+ LeafNode<String> equalLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue5);
assertTrue(leafNode5.equals(leafNode5));
assertTrue(leafNode5.equals(equalLeafNode5));
assertTrue(equalLeafNode5.equals(leafNode5));
-
}
@Test
byte[] equalValue = "test".getBytes();
LeafNode<byte[]> leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value);
- LeafNode<byte[]> otherLeafNode = ImmutableNodes.leafNode(
- OTHER_LEAF_QNAME, equalValue);
+ LeafNode<byte[]> otherLeafNode = ImmutableNodes.leafNode(OTHER_LEAF_QNAME, equalValue);
assertFalse(leafNode.equals(null));
assertFalse(leafNode.equals(new Object()));
byte[] value1 = "test".getBytes();
byte[] otherValue1 = "test1".getBytes();
- LeafNode<byte[]> leafNode1 = ImmutableNodes
- .leafNode(LEAF_QNAME, value1);
- LeafNode<byte[]> otherLeafNode1 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, otherValue1);
+ LeafNode<byte[]> leafNode1 = ImmutableNodes.leafNode(LEAF_QNAME, value1);
+ LeafNode<byte[]> otherLeafNode1 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue1);
assertFalse(leafNode1.equals(otherLeafNode1));
assertFalse(otherLeafNode1.equals(leafNode1));
Byte[] value2 = new Byte[] { new Byte("1"), new Byte("1") };
Byte[] otherValue2 = new Byte[] { new Byte("1"), new Byte("2") };
- LeafNode<Byte[]> leafNode2 = ImmutableNodes
- .leafNode(LEAF_QNAME, value2);
- LeafNode<Byte[]> otherLeafNode2 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, otherValue2);
+ LeafNode<Byte[]> leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2);
+ LeafNode<Byte[]> otherLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue2);
assertFalse(leafNode2.equals(otherLeafNode2));
assertFalse(otherLeafNode2.equals(leafNode2));
byte[][] value3 = new byte[][] { "test".getBytes(), "test2".getBytes() };
- byte[][] otherValue3 = new byte[][] { "test".getBytes(),
- "test3".getBytes() };
+ byte[][] otherValue3 = new byte[][] { "test".getBytes(), "test3".getBytes() };
- LeafNode<byte[][]> leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME,
- value3);
- LeafNode<byte[][]> otherLeafNode3 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, otherValue3);
+ LeafNode<byte[][]> leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3);
+ LeafNode<byte[][]> otherLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue3);
assertFalse(leafNode3.equals(otherLeafNode3));
assertFalse(otherLeafNode3.equals(leafNode3));
Byte[][] value4 = new Byte[][] {
- new Byte[] { new Byte("1"), new Byte("2") },
- new Byte[] { new Byte("3"), new Byte("4") } };
+ new Byte[] { new Byte("1"), new Byte("2") },
+ new Byte[] { new Byte("3"), new Byte("4") },
+ };
Byte[][] otherValue4 = new Byte[][] {
- new Byte[] { new Byte("1"), new Byte("2") },
- new Byte[] { new Byte("3"), new Byte("5") } };
+ new Byte[] { new Byte("1"), new Byte("2") },
+ new Byte[] { new Byte("3"), new Byte("5") },
+ };
- LeafNode<Byte[][]> leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME,
- value4);
- LeafNode<Byte[][]> otherLeafNode4 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, otherValue4);
+ LeafNode<Byte[][]> leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME, value4);
+ LeafNode<Byte[][]> otherLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue4);
assertFalse(leafNode4.equals(otherLeafNode4));
assertFalse(otherLeafNode4.equals(leafNode4));
Byte otherValue6 = new Byte("2");
LeafNode<Byte> leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6);
- LeafNode<Byte> otherLeafNode6 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, otherValue6);
+ LeafNode<Byte> otherLeafNode6 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue6);
assertFalse(leafNode6.equals(otherLeafNode6));
assertFalse(otherLeafNode6.equals(leafNode6));
String value5 = "test";
String otherValue5 = "test2";
- LeafNode<String> leafNode5 = ImmutableNodes
- .leafNode(LEAF_QNAME, value5);
- LeafNode<String> otherLeafNode5 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, otherValue5);
+ LeafNode<String> leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5);
+ LeafNode<String> otherLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue5);
assertFalse(leafNode5.equals(otherLeafNode5));
assertFalse(otherLeafNode5.equals(leafNode5));
assertFalse(leafNode4.equals(leafNode5));
assertFalse(leafNode6.equals(leafNode5));
- LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, null);
+ LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(SAME_LEAF_QNAME, null);
assertFalse(leafNodeNull.equals(leafNode));
assertFalse(leafNode.equals(leafNodeNull));
byte[] byteValue = new byte[] { 1, 1 };
- LeafNode<byte[]> byteLeafNode = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, byteValue);
+ LeafNode<byte[]> byteLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, byteValue);
assertFalse(byteLeafNode.equals(leafNode2));
assertFalse(leafNode2.equals(byteLeafNode));
-
}
@Test
char[] valueChar = "test".toCharArray();
char[] equalValueChar = "test".toCharArray();
- LeafNode<char[]> leafNodeChar = ImmutableNodes.leafNode(LEAF_QNAME,
- valueChar);
- LeafNode<char[]> equalLeafNodeChar = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValueChar);
+ LeafNode<char[]> leafNodeChar = ImmutableNodes.leafNode(LEAF_QNAME, valueChar);
+ LeafNode<char[]> equalLeafNodeChar = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValueChar);
assertTrue(leafNodeChar.equals(leafNodeChar));
assertTrue(leafNodeChar.equals(equalLeafNodeChar));
boolean[] value = new boolean[] { true, false };
boolean[] equalValue = new boolean[] { true, false };
- LeafNode<boolean[]> leafNode = ImmutableNodes.leafNode(LEAF_QNAME,
- value);
- LeafNode<boolean[]> equalLeafNode = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue);
+ LeafNode<boolean[]> leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value);
+ LeafNode<boolean[]> equalLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue);
assertTrue(leafNode.equals(leafNode));
assertTrue(leafNode.equals(equalLeafNode));
int[] equalValue2 = new int[] { 1, 2 };
LeafNode<int[]> leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2);
- LeafNode<int[]> equalLeafNode2 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue2);
+ LeafNode<int[]> equalLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue2);
assertTrue(leafNode2.equals(leafNode2));
assertTrue(leafNode2.equals(equalLeafNode2));
short[] value3 = new short[] { 1, 2 };
short[] equalValue3 = new short[] { 1, 2 };
- LeafNode<short[]> leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME,
- value3);
- LeafNode<short[]> equalLeafNode3 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue3);
+ LeafNode<short[]> leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3);
+ LeafNode<short[]> equalLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue3);
assertTrue(leafNode3.equals(leafNode3));
assertTrue(leafNode3.equals(equalLeafNode3));
long[] value4 = new long[] { 1, 2 };
long[] equalValue4 = new long[] { 1, 2 };
- LeafNode<long[]> leafNode4 = ImmutableNodes
- .leafNode(LEAF_QNAME, value4);
- LeafNode<long[]> equalLeafNode4 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue4);
+ LeafNode<long[]> leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME, value4);
+ LeafNode<long[]> equalLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue4);
assertTrue(leafNode4.equals(leafNode4));
assertTrue(leafNode4.equals(equalLeafNode4));
double[] value6 = new double[] { 1, 2 };
double[] equalValue6 = new double[] { 1, 2 };
- LeafNode<double[]> leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME,
- value6);
- LeafNode<double[]> equalLeafNode6 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue6);
+ LeafNode<double[]> leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6);
+ LeafNode<double[]> equalLeafNode6 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue6);
assertTrue(leafNode6.equals(leafNode6));
assertTrue(leafNode6.equals(equalLeafNode6));
float[] value5 = new float[] { 1, 2 };
float[] equalValue5 = new float[] { 1, 2 };
- LeafNode<float[]> leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME,
- value5);
- LeafNode<float[]> equalLeafNode5 = ImmutableNodes.leafNode(
- SAME_LEAF_QNAME, equalValue5);
+ LeafNode<float[]> leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5);
+ LeafNode<float[]> equalLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue5);
assertTrue(leafNode5.equals(leafNode5));
assertTrue(leafNode5.equals(equalLeafNode5));
assertFalse(leafNode5.equals(leafNodeChar));
assertFalse(leafNode5.equals(leafNode6));
}
-
}
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
private QName subRoot;
private QName outerList;
private QName innerList;
- private QName oId;
- private QName iId;
- private QName oLeaf;
- private QName iLeaf;
+ private QName oid;
+ private QName iid;
+ private QName oleaf;
+ private QName ileaf;
private QNameModule foo;
@Before
subRoot = QName.create(foo, "sub-root");
outerList = QName.create(foo, "outer-list");
innerList = QName.create(foo, "inner-list");
- oId = QName.create(foo, "o-id");
- iId = QName.create(foo, "i-id");
- oLeaf = QName.create(foo, "o");
- iLeaf = QName.create(foo, "i");
- inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ oid = QName.create(foo, "o-id");
+ iid = QName.create(foo, "i-id");
+ oleaf = QName.create(foo, "o");
+ ileaf = QName.create(foo, "i");
+ inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(DataTreeConfiguration.DEFAULT_OPERATIONAL);
inMemoryDataTree.setSchemaContext(context);
}
.withChild(createOuterListEntry("3", "o-3"))
.build();
ContainerNode rootContainerNode = createRootContainerBuilder()
- .withChild(
- createSubRootContainerBuilder()
- .withChild(outerListNode)
- .build())
- .build();
+ .withChild(createSubRootContainerBuilder().withChild(outerListNode).build())
+ .build();
YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
modification.merge(path, rootContainerNode);
.withChild(createInnerListEntry("a", "i-a"))
.withChild(createInnerListEntry("b", "i-b"))
.build();
- path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2")).node(innerList);
+ path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2"))
+ .node(innerList);
modification.write(path, innerListNode);
/* COMMIT */
inMemoryDataTree.commit(inMemoryDataTree.prepare(modification));
}
- private void secondModification(int testScenarioNumber) throws DataValidationFailedException {
+ private void secondModification(final int testScenarioNumber) throws DataValidationFailedException {
/* MERGE */
MapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList))
.withChild(createOuterListEntry("3", "o-3"))
.build();
ContainerNode rootContainerNode = createRootContainerBuilder()
- .withChild(
- createSubRootContainerBuilder()
- .withChild(outerListNode)
- .build())
- .build();
+ .withChild(createSubRootContainerBuilder().withChild(outerListNode).build())
+ .build();
YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
inMemoryDataTree.commit(inMemoryDataTree.prepare(modification));
}
- private void writeEmptyInnerList(DataTreeModification modification, String outerListEntryKey) {
+ private void writeEmptyInnerList(final DataTreeModification modification, final String outerListEntryKey) {
YangInstanceIdentifier path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList)
.node(createOuterListEntryPath(outerListEntryKey)).node(innerList);
modification.write(path, createInnerListBuilder().build());
return ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(innerList));
}
- private NodeIdentifierWithPredicates createInnerListEntryPath(String keyValue) {
+ private NodeIdentifierWithPredicates createInnerListEntryPath(final String keyValue) {
Builder<QName, Object> builder = ImmutableMap.builder();
- ImmutableMap<QName, Object> keys = builder.put(iId, keyValue).build();
+ ImmutableMap<QName, Object> keys = builder.put(iid, keyValue).build();
return new YangInstanceIdentifier.NodeIdentifierWithPredicates(innerList, keys);
}
- private NodeIdentifierWithPredicates createOuterListEntryPath(String keyValue) {
+ private NodeIdentifierWithPredicates createOuterListEntryPath(final String keyValue) {
Builder<QName, Object> builder = ImmutableMap.builder();
- ImmutableMap<QName, Object> keys = builder.put(oId, keyValue).build();
+ ImmutableMap<QName, Object> keys = builder.put(oid, keyValue).build();
return new YangInstanceIdentifier.NodeIdentifierWithPredicates(outerList, keys);
}
- private MapEntryNode createOuterListEntry(String keyValue, String leafValue) {
- return ImmutableNodes.mapEntryBuilder(outerList, oId, keyValue)
- .withChild(ImmutableNodes.leafNode(oLeaf, leafValue)).build();
+ private MapEntryNode createOuterListEntry(final String keyValue, final String leafValue) {
+ return ImmutableNodes.mapEntryBuilder(outerList, oid, keyValue)
+ .withChild(ImmutableNodes.leafNode(oleaf, leafValue)).build();
}
- private MapEntryNode createInnerListEntry(String keyValue, String leafValue) {
- return ImmutableNodes.mapEntryBuilder(innerList, iId, keyValue)
- .withChild(ImmutableNodes.leafNode(iLeaf, leafValue)).build();
+ private MapEntryNode createInnerListEntry(final String keyValue, final String leafValue) {
+ return ImmutableNodes.mapEntryBuilder(innerList, iid, keyValue)
+ .withChild(ImmutableNodes.leafNode(ileaf, leafValue)).build();
}
}
\ No newline at end of file
import static org.junit.Assert.assertTrue;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
private static final YangInstanceIdentifier MIN_MAX_LIST_NO_MINMAX_PATH = YangInstanceIdentifier
.builder(MASTER_CONTAINER_PATH)
.node(MIN_MAX_LIST_QNAME_NO_MINMAX).build();
- private static final YangInstanceIdentifier MIN_MAX_LEAF_LIST_PATH = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
- .node(MIN_MAX_LEAF_LIST_QNAME).build();
-
- private static Map<QName,Object> fooPredicates = new HashMap<>();
- static {
- fooPredicates.put(MIN_MAX_KEY_LEAF_QNAME,"foo");
- }
-
- private static Map<QName,Object> bazPredicates = new HashMap<>();
- static {
- bazPredicates.put(MIN_MAX_KEY_LEAF_QNAME,"baz");
- }
-
- private final MapEntryNode fooEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(new
- NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, fooPredicates)).
- withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "footest")).build();
- private final MapEntryNode BazEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(new
- NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, bazPredicates)).
- withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "baztest")).build();
+ private static final YangInstanceIdentifier MIN_MAX_LEAF_LIST_PATH = YangInstanceIdentifier
+ .builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LEAF_LIST_QNAME).build();
+
+ private static final Map<QName, Object> FOO_PREDICATES = ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "foo");
+ private static final Map<QName, Object> BAZ_PREDICATES = ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "baz");
+
+ private final MapEntryNode fooEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
+ new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, FOO_PREDICATES))
+ .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "footest")).build();
+ private final MapEntryNode bazEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
+ new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, BAZ_PREDICATES))
+ .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "baztest")).build();
private final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
"foo");
private final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
"baz");
private final MapNode mapNodeBazFuzWithNodes = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
- .withChild(bazEntryNode).withChild(BazEntryNodeWithValue).withChild(fooEntryNode)
+ .withChild(bazEntryNode).withChild(bazEntryNodeWithValue).withChild(fooEntryNode)
.build();
private final MapNode mapNodeFooWithNodes = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , key);
- YangInstanceIdentifier MIN_MAX_LEAF_FOO = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
+ final YangInstanceIdentifier minMaxLeafFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
key.clear();
mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
- YangInstanceIdentifier MIN_MAX_LEAF_NEL = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node
- (MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
+ final YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
+ .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
final Map<QName, Object> keyTemp = new HashMap<>();
keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "baz");
keyTemp.clear();
keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
- final NodeIdentifierWithPredicates mapEntryPathTestKey = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , keyTemp);
+ final NodeIdentifierWithPredicates mapEntryPathTestKey = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
+ keyTemp);
final YangInstanceIdentifier pathToKeyFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
.node(MIN_MAX_LIST_QNAME).node(mapEntryPathTestKey).node(MIN_MAX_KEY_LEAF_QNAME).build();
modificationTree1.write(pathToBaz, newNode2);
modificationTree1.write(pathToBaz, newNode1);
modificationTree1.write(pathToBaz, newNode);
- modificationTree1.delete(MIN_MAX_LEAF_FOO);
- modificationTree1.delete(MIN_MAX_LEAF_NEL);
+ modificationTree1.delete(minMaxLeafFoo);
+ modificationTree1.delete(minMaxLeafNel);
modificationTree1.ready();
inMemoryDataTree.validate(modificationTree1);
final InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
final Optional<NormalizedNode<?, ?>> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
assertTrue(masterContainer.isPresent());
- final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get()).getChild(
- new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
+ final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get())
+ .getChild(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
assertTrue(leafList.isPresent());
assertTrue(leafList.get().getValue().size() == 3);
}
Map<QName, Object> key = new HashMap<>();
key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
- NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , key);
+ NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
- YangInstanceIdentifier MIN_MAX_LEAF_FOO = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
- .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
+ final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
+ .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
key.clear();
key.put(MIN_MAX_KEY_LEAF_QNAME, "bar");
mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
- YangInstanceIdentifier MIN_MAX_LEAF_BAR = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node
- (MIN_MAX_LIST_QNAME)
- .node(mapEntryPath2).build();
+ final YangInstanceIdentifier minMaxLeafBar = MASTER_CONTAINER_PATH
+ .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
key.clear();
key.put(MIN_MAX_KEY_LEAF_QNAME, "baz");
mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
- YangInstanceIdentifier MIN_MAX_LEAF_BAZ = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node
- (MIN_MAX_LIST_QNAME)
- .node(mapEntryPath2).build();
+ final YangInstanceIdentifier minMaxLeafBaz = MASTER_CONTAINER_PATH
+ .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
modificationTree.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBar);
modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
- modificationTree.delete(MIN_MAX_LEAF_FOO);
- modificationTree.delete(MIN_MAX_LEAF_BAR);
- modificationTree.delete(MIN_MAX_LEAF_BAZ);
+ modificationTree.delete(minMaxLeafFoo);
+ modificationTree.delete(minMaxLeafBar);
+ modificationTree.delete(minMaxLeafBaz);
modificationTree.ready();
@Test
public void minMaxListNoMinMaxDeleteTest() throws DataValidationFailedException {
- final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME
- , "foo");
+ final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME,
+ "foo");
final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME_NO_MINMAX))
.withChild(fooEntryNode).build();
Map<QName, Object> key = new HashMap<>();
key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
- NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME_NO_MINMAX , key);
+ NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME_NO_MINMAX,
+ key);
- YangInstanceIdentifier MIN_MAX_LEAF_FOO = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node
- (MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2).build();
+ final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
+ .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2);
key.clear();
key.put(MIN_MAX_KEY_LEAF_QNAME, "non-existing-leaf");
mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
- YangInstanceIdentifier MIN_MAX_LEAF_NEL = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node
- (MIN_MAX_LIST_QNAME_NO_MINMAX)
- .node(mapEntryPath2).build();
+ YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
+ .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2).build();
modificationTree.write(MIN_MAX_LIST_NO_MINMAX_PATH, mapNode1);
- modificationTree.delete(MIN_MAX_LEAF_FOO);
- modificationTree.delete(MIN_MAX_LEAF_NEL);
+ modificationTree.delete(minMaxLeafFoo);
+ modificationTree.delete(minMaxLeafNel);
modificationTree.ready();
UnmodifiableCollection<?> collectionChildren = (UnmodifiableCollection<?>) minMaxListRead.get().getValue();
for (Object collectionChild : collectionChildren) {
- if (collectionChild.toString().contains(first)){
+ if (collectionChild.toString().contains(first)) {
assertTrue(collectionChild.toString().contains(first));
} else {
assertTrue(collectionChild.toString().contains(second));
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
private static InMemoryDataTree initDataTree(final SchemaContext schemaContext)
throws DataValidationFailedException {
InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
- TreeType.CONFIGURATION);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION);
inMemoryDataTree.setSchemaContext(schemaContext);
final MapNode taskNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(TASK)).build();
inMemoryDataTree.commit(prepare);
}
- private static void testMandatoryLeaf2IsPresent(final SchemaContext schemaContext, final boolean withPresenceContianer)
- throws DataValidationFailedException {
+ private static void testMandatoryLeaf2IsPresent(final SchemaContext schemaContext,
+ final boolean withPresenceContianer) throws DataValidationFailedException {
final InMemoryDataTree inMemoryDataTree = initDataTree(schemaContext);
final MapEntryNode taskEntryNode = Builders.mapEntryBuilder()
}
}
- private static void mergeMap(final InMemoryDataTreeModification modificationTree, final boolean mandatoryDataMissing)
- throws DataValidationFailedException {
+ private static void mergeMap(final InMemoryDataTreeModification modificationTree,
+ final boolean mandatoryDataMissing) throws DataValidationFailedException {
final MapNode myList = createMap(mandatoryDataMissing);
modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), myList);
}
.withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue));
}
- private static CollectionNodeBuilder<MapEntryNode, MapNode> createMapBuilder() throws DataValidationFailedException {
+ private static CollectionNodeBuilder<MapEntryNode, MapNode> createMapBuilder() {
return Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST));
}
- private static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createContainerBuilder()
- throws DataValidationFailedException {
+ private static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createContainerBuilder() {
return Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(ROOT));
}
}
}
- private static void writeMap(final InMemoryDataTreeModification modificationTree, final boolean mandatoryDataMissing)
- throws DataValidationFailedException {
+ private static void writeMap(final InMemoryDataTreeModification modificationTree,
+ final boolean mandatoryDataMissing) {
final MapNode myList = createMap(mandatoryDataMissing);
modificationTree.write(YangInstanceIdentifier.of(ROOT).node(MY_LIST), myList);
}
- private static MapNode createMap(final boolean mandatoryDataMissing) throws DataValidationFailedException {
+ private static MapNode createMap(final boolean mandatoryDataMissing) {
return Builders
.mapBuilder()
.withNodeIdentifier(new NodeIdentifier(MY_LIST))
}
private static MapEntryNode createMapEntry(final Object listIdValue, final Object mandatoryLeafValue,
- final Object commonLeafValue) throws DataValidationFailedException {
+ final Object commonLeafValue) {
return Builders.mapEntryBuilder()
.withNodeIdentifier(new NodeIdentifierWithPredicates(MY_LIST, ImmutableMap.of(LIST_ID, listIdValue)))
.withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
.withChild(ImmutableNodes.leafNode(COMMON_LEAF, commonLeafValue)).build();
}
- private static MapEntryNode createMapEntry(final Object listIdValue, final Object commonLeafValue)
- throws DataValidationFailedException {
+ private static MapEntryNode createMapEntry(final Object listIdValue, final Object commonLeafValue) {
return Builders.mapEntryBuilder()
.withNodeIdentifier(new NodeIdentifierWithPredicates(MY_LIST, ImmutableMap.of(LIST_ID, listIdValue)))
.withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
+
import com.google.common.collect.ImmutableSet;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
-
public class CaseAugmentTest {
private SchemaContext schemaContext;
- private final QName CHOICE1_QNAME = QName.create(TestModel.TEST_QNAME, "choice1");
- private final QName C1L1_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf1");
- private final QName C1L2_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf2");
- private final QName C1L3_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf3");
- private final QName C2L1_QNAME = QName.create(TestModel.TEST_QNAME, "case2-leaf1");
- private final NodeIdentifier CHOICE_ID = new NodeIdentifier(CHOICE1_QNAME);
- private final AugmentationIdentifier AUGMENT_ID =
- new AugmentationIdentifier(ImmutableSet.<QName>builder().add(C1L2_QNAME).add(C1L3_QNAME).build());
-
+ private static final QName CHOICE1_QNAME = QName.create(TestModel.TEST_QNAME, "choice1");
+ private static final QName C1L1_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf1");
+ private static final QName C1L2_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf2");
+ private static final QName C1L3_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf3");
+ private static final QName C2L1_QNAME = QName.create(TestModel.TEST_QNAME, "case2-leaf1");
+ private static final NodeIdentifier CHOICE_ID = new NodeIdentifier(CHOICE1_QNAME);
+ private static final AugmentationIdentifier AUGMENT_ID = new AugmentationIdentifier(
+ ImmutableSet.of(C1L2_QNAME, C1L3_QNAME));
@Before
public void prepare() throws ReactorException {
import static org.junit.Assert.fail;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
+
import com.google.common.base.Optional;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
private static final Short ONE_ID = 1;
private static final Short TWO_ID = 2;
- private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
- .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
+ private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(
+ TestModel.OUTER_LIST_PATH)
+ .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)
.build();
- private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
- .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
+ private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(
+ TestModel.OUTER_LIST_PATH)
+ .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
.build();
- private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
- .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) //
- .build()) //
+ private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)
+ .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).build())
.build();
- private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
- .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) //
- .build()) //
+ private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
+ .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).build())
.build();
private SchemaContext schemaContext;
public void prepare() throws ReactorException {
schemaContext = TestModel.createTestContext();
assertNotNull("Schema context must not be null.", schemaContext);
- inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
+ DataTreeConfiguration.DEFAULT_OPERATIONAL);
inMemoryDataTree.setSchemaContext(schemaContext);
}
private static ContainerNode createFooTestContainerNode() {
- return ImmutableContainerNodeBuilder
- .create()
+ return ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
.withChild(
mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
public void writeWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+ initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .build());
initialDataTreeModification.ready();
inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
public void writeMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+ initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .build());
initialDataTreeModification.ready();
inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
public void mergeWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+ initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .build());
initialDataTreeModification.ready();
inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
public void mergeMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+ initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .build());
initialDataTreeModification.ready();
inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
public void deleteWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+ initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .build());
initialDataTreeModification.ready();
inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
fail("Exception should have been thrown");
- } catch (final Exception e) {
- LOG.debug("Exception was thrown because path no longer exist in tree");
+ } catch (final ConflictingModificationAppliedException e) {
+ LOG.debug("Exception was thrown because path no longer exist in tree", e);
}
final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
public void deleteMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+ initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .build());
initialDataTreeModification.ready();
inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
fail("Exception should have been thrown");
- } catch (final Exception e) {
- LOG.debug("Exception was thrown because path no longer exist in tree");
+ } catch (final ConflictingModificationAppliedException e) {
+ LOG.debug("Exception was thrown because path no longer exist in tree", e);
}
final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
private static final Short TWO_ID = 2;
private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier
- .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
+ .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)
.build();
private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier
- .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
+ .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
.build();
private static final MapEntryNode INNER_FOO_ENTRY_NODE = ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME,
.mapEntryBuilder(QName.create(TestModel.TEST_QNAME, "inner-list2"), TestModel.NAME_QNAME, "foo")
.withChild(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "value")).build();
- private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
- .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(INNER_FOO_ENTRY_NODE) //
- .build()) //
+ private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)
+ .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(INNER_FOO_ENTRY_NODE)
+ .build())
.build();
- private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
- .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(INNER_BAR_ENTRY_NODE) //
- .build()) //
+ private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
+ .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(INNER_BAR_ENTRY_NODE)
+ .build())
.build();
private SchemaContext schemaContext;
@Test(expected = SchemaValidationFailedException.class)
public void testOnPathFail() throws DataValidationFailedException {
final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
- TreeType.CONFIGURATION);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION);
inMemoryDataTree.setSchemaContext(schemaContext);
final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node(
@Test(expected = SchemaValidationFailedException.class)
public void testOnDataFail() throws DataValidationFailedException {
final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
- TreeType.CONFIGURATION);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION);
inMemoryDataTree.setSchemaContext(schemaContext);
final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(TestModel.TEST_PATH, createFooTestContainerNode());
@Test(expected = SchemaValidationFailedException.class)
public void testOnDataLeafFail() throws DataValidationFailedException {
final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
- TreeType.CONFIGURATION);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION);
inMemoryDataTree.setSchemaContext(schemaContext);
final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(TestModel.TEST_PATH, createBarTestContainerNode());
@Test(expected = SchemaValidationFailedException.class)
public void testOnPathCaseLeafFail() throws DataValidationFailedException {
final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
- TreeType.CONFIGURATION);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION);
inMemoryDataTree.setSchemaContext(schemaContext);
final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
TestModel.TEST_QNAME, "choice1"));
@Test(expected = VerifyException.class)
public void testOnDataCaseLeafFail() throws DataValidationFailedException {
final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
- TreeType.CONFIGURATION);
+ DataTreeConfiguration.DEFAULT_CONFIGURATION);
inMemoryDataTree.setSchemaContext(schemaContext);
final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
TestModel.TEST_QNAME, "choice1"));
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
@Before
public void setUp() throws Exception {
- dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ dataTree = InMemoryDataTreeFactory.getInstance().create(DataTreeConfiguration.DEFAULT_OPERATIONAL);
dataTree.setSchemaContext(SCHEMA_CONTEXT);
final ContainerNode testContainer = ImmutableContainerNodeBuilder.create()
.build())
.build();
- final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) dataTree.takeSnapshot().newModification();
+ final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) dataTree.takeSnapshot()
+ .newModification();
final DataTreeModificationCursor cursor = modification.createCursor(YangInstanceIdentifier.EMPTY);
cursor.write(TestModel.TEST_PATH.getLastPathArgument(), testContainer);
modification.ready();
@Test
public void testRootedCandidate() throws Exception {
- final DataTree innerDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL, TestModel.INNER_CONTAINER_PATH);
+ final DataTree innerDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL,
+ TestModel.INNER_CONTAINER_PATH);
innerDataTree.setSchemaContext(SCHEMA_CONTEXT);
final LeafNode<String> leaf = ImmutableLeafNodeBuilder.<String>create()
.withValue("testing-value")
.build();
- final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) innerDataTree.takeSnapshot().newModification();
+ final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) innerDataTree.takeSnapshot()
+ .newModification();
modification.write(TestModel.VALUE_PATH, leaf);
modification.ready();
dataTree.commit(candidate);
final DataTreeModification newModification = dataTree.takeSnapshot().newModification();
- final DataTreeCandidate newCandidate = DataTreeCandidates.newDataTreeCandidate(TestModel.INNER_CONTAINER_PATH, candidate.getRootNode());
+ final DataTreeCandidate newCandidate = DataTreeCandidates.newDataTreeCandidate(TestModel.INNER_CONTAINER_PATH,
+ candidate.getRootNode());
try {
// lets see if getting the identifier of the root node throws an exception
tree.prepare(mod);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnsealedValidate() throws DataValidationFailedException {
final DataTreeModification mod = tree.takeSnapshot().newModification();
tree.validate(mod);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUnsealedPrepare() {
final DataTreeModification mod = tree.takeSnapshot().newModification();
tree.prepare(mod);
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
@Before
public void setup() throws ReactorException {
- tree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ tree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
+ DataTreeConfiguration.DEFAULT_OPERATIONAL);
tree.setSchemaContext(TestModel.createTestContext());
}
public void writeWithoutParentExisting() {
InMemoryDataTreeModification modification = tree.takeSnapshot().newModification();
// We write node without creating parent
- modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+ modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .build());
modification.ready();
try {
tree.validate(modification);
// We commit transaction
tree.commit(tree.prepare(initial));
- InMemoryDataTreeModification writeTx = tree.takeSnapshot().newModification();
- InMemoryDataTreeModification deleteTx = tree.takeSnapshot().newModification();
+ final InMemoryDataTreeModification writeTx = tree.takeSnapshot().newModification();
+ final InMemoryDataTreeModification deleteTx = tree.takeSnapshot().newModification();
deleteTx.delete(TestModel.TEST_PATH);
deleteTx.ready();
// We commit delete modification
} catch (DataValidationFailedException e) {
fail("ConflictingModificationAppliedException expected");
}
-
}
}
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class ListConstraintsValidation {
- private static final Logger LOG = LoggerFactory.getLogger(ListConstraintsValidation.class);
-
private static final String CONSTRAINTS_VALIDATION_TEST_YANG = "/list-constraints-validation-test-model.yang";
- private SchemaContext schemaContext;
-
- private InMemoryDataTree inMemoryDataTree;
-
private static final QName MASTER_CONTAINER_QNAME = QName.create(
"urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model", "2015-02-02",
"master-container");
private static final YangInstanceIdentifier UNKEYED_LIST_PATH = YangInstanceIdentifier
.builder(MASTER_CONTAINER_PATH).node(UNKEYED_LIST_QNAME).build();
+ private SchemaContext schemaContext;
+ private InMemoryDataTree inMemoryDataTree;
+
@Before
public void prepare() {
schemaContext = createTestContext();
assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 2);
}
- @Test(expected=DataValidationFailedException.class)
+ @Test(expected = DataValidationFailedException.class)
public void minMaxListFail() throws DataValidationFailedException {
InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
final Optional<NormalizedNode<?, ?>> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
assertTrue(masterContainer.isPresent());
- final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get()).getChild(
- new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
+ final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get())
+ .getChild(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
assertTrue(leafList.isPresent());
assertTrue(leafList.get().getValue().size() == 2);
}
- @Test(expected=DataValidationFailedException.class)
+ @Test(expected = DataValidationFailedException.class)
public void minMaxLeafListFail() throws DataValidationFailedException {
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
assertTrue(((UnkeyedListNode) unkeyedListRead.get()).getSize() == 1);
}
- @Test(expected=DataValidationFailedException.class)
+ @Test(expected = DataValidationFailedException.class)
public void unkeyedListTestFail() throws DataValidationFailedException {
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
} catch (final IllegalArgumentException e) {
- assertEquals(
- "Node (urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)choice1 is missing mandatory descendant /(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)case2-cont/case2-leaf1",
+ assertEquals("Node (urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?"
+ + "revision=2014-03-13)choice1 is missing mandatory descendant /(urn:opendaylight:params:xml:ns:"
+ + "yang:controller:md:sal:dom:store:test?revision=2014-03-13)case2-cont/case2-leaf1",
e.getMessage());
throw e;
}
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
} catch (final IllegalArgumentException e) {
- assertEquals(
- "Node (urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)choice1 is missing mandatory descendant /(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)case2-cont/case2-leaf1",
+ assertEquals("Node (urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?"
+ + "revision=2014-03-13)choice1 is missing mandatory descendant /(urn:opendaylight:params:xml:ns:"
+ + "yang:controller:md:sal:dom:store:test?revision=2014-03-13)case2-cont/case2-leaf1",
e.getMessage());
throw e;
}
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-/**
- *
+/*
* Schema structure of document is
*
- * <pre>
* container root {Â
* list list-a {
* key leaf-a;
* }
* }
* }
- * </pre>
- *
*/
public class ModificationMetadataTreeTest {
private static final String TWO_ONE_NAME = "one";
private static final String TWO_TWO_NAME = "two";
- private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
- .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
+ private static final YangInstanceIdentifier OUTER_LIST_1_PATH =
+ YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
+ .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)
.build();
- private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
- .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
+ private static final YangInstanceIdentifier OUTER_LIST_2_PATH =
+ YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
+ .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
.build();
private static final YangInstanceIdentifier TWO_TWO_PATH = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH)
- .node(TestModel.INNER_LIST_QNAME) //
- .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME) //
+ .node(TestModel.INNER_LIST_QNAME)
+ .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME)
.build();
private static final YangInstanceIdentifier TWO_TWO_VALUE_PATH = YangInstanceIdentifier.builder(TWO_TWO_PATH)
- .node(TestModel.VALUE_QNAME) //
+ .node(TestModel.VALUE_QNAME)
.build();
- private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
- .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) //
- .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME)) //
- .withChild(mapEntry(TestModel.INNER_LIST_QNAME,TestModel.NAME_QNAME, TWO_TWO_NAME)) //
- .build()) //
+ private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
+ .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME)
+ .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME))
+ .withChild(mapEntry(TestModel.INNER_LIST_QNAME,TestModel.NAME_QNAME, TWO_TWO_NAME))
+ .build())
.build();
private SchemaContext schemaContext;
public void prepare() throws ReactorException {
schemaContext = TestModel.createTestContext();
assertNotNull("Schema context must not be null.", schemaContext);
- rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, DataTreeConfiguration.DEFAULT_OPERATIONAL));
+ rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext,
+ DataTreeConfiguration.DEFAULT_OPERATIONAL));
}
/**
- * Returns a test document
- *
+ * Returns a test document.
* <pre>
* test
* outer-list
@Test
public void basicReadWrites() {
- final DataTreeModification modificationTree = new InMemoryDataTreeModification(new InMemoryDataTreeSnapshot(schemaContext,
- TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper),
- rootOper);
+ final DataTreeModification modificationTree = new InMemoryDataTreeModification(
+ new InMemoryDataTreeSnapshot(schemaContext,
+ TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper), rootOper);
final Optional<NormalizedNode<?, ?>> originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH);
assertTrue(originalBarNode.isPresent());
assertSame(BAR_NODE, originalBarNode.get());
/**
* Creates empty Snapshot with associated schema context.
*/
- final DataTree t = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ final DataTree t = InMemoryDataTreeFactory.getInstance().create(DataTreeConfiguration.DEFAULT_OPERATIONAL);
t.setSchemaContext(schemaContext);
/**
public void createFromEmptyState() {
final DataTreeModification modificationTree = createEmptyModificationTree();
- /**
- * Writes empty container node to /test
- *
- */
+ // Writes empty container node to /test
modificationTree.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- /**
- * Writes empty list node to /test/outer-list
- */
- modificationTree.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+ // Writes empty list node to /test/outer-list
+ modificationTree.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .build());
- /**
- * Reads list node from /test/outer-list
- */
+ // Reads list node from /test/outer-list.
final Optional<NormalizedNode<?, ?>> potentialOuterList = modificationTree.readNode(TestModel.OUTER_LIST_PATH);
assertTrue(potentialOuterList.isPresent());
- /**
- * Reads container node from /test and verifies that it contains test
- * node
- */
+ // Reads container node from /test and verifies that it contains test node.
final Optional<NormalizedNode<?, ?>> potentialTest = modificationTree.readNode(TestModel.TEST_PATH);
final ContainerNode containerTest = assertPresentAndType(potentialTest, ContainerNode.class);
*
*/
assertPresentAndType(containerTest.getChild(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)), MapNode.class);
-
}
@Test
assertTrue(type.isInstance(potential.get()));
return type.cast(potential.get());
}
-
}
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.LoggerFactory;
public class OrderedListTest {
- private Logger LOG = LoggerFactory.getLogger(OrderedListTest.class);
+ private static final Logger LOG = LoggerFactory.getLogger(OrderedListTest.class);
private TipProducingDataTree inMemoryDataTree;
private SchemaContext context;
.withChild(createChildOrderedListEntry("chkval2", "chlfval2updated"))
.withChild(createChildOrderedListEntry("chkval3", "chlfval3")).build();
- YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer).node
- (parentOrderedList).node(createParentOrderedListEntryPath("pkval2")).node(childOrderedList);
+ YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer)
+ .node(parentOrderedList).node(createParentOrderedListEntryPath("pkval2")).node(childOrderedList);
treeModification.merge(path2, childOrderedListNode);
treeModification.ready();
new NodeIdentifier(childOrderedList))
.withChild(createChildOrderedListEntry("chkval1", "chlfval1new")).build();
- YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer).node
- (parentOrderedList)
+ YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer)
+ .node(parentOrderedList)
.node(createParentOrderedListEntryPath("pkval4")).node(childOrderedList);
treeModification.merge(path2, childOrderedListNode);
DataTreeModification treeModification1 = inMemoryDataTree.takeSnapshot().newModification();
DataTreeModification treeModification2 = inMemoryDataTree.takeSnapshot().newModification();
- OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new
- NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval1",
- "plfval1")).build();
+ OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval1", "plfval1"))
+ .build();
- OrderedMapNode parentOrderedListNode2 = Builders.orderedMapBuilder().withNodeIdentifier(new
- NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval2",
- "plfval2")).build();
+ OrderedMapNode parentOrderedListNode2 = Builders.orderedMapBuilder().withNodeIdentifier(
+ new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval2", "plfval2"))
+ .build();
ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(
new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build()).build();
+ .withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build())
+ .build();
ContainerNode parentContainerNode2 = Builders.containerBuilder().withNodeIdentifier(
new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder()
assertFalse(readNode.isPresent());
}
- private MapEntryNode createParentOrderedListEntry(String keyValue, String leafValue) {
+ private MapEntryNode createParentOrderedListEntry(final String keyValue, final String leafValue) {
return Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(parentOrderedList,
parentKeyLeaf, keyValue))
- .withChild(Builders.leafBuilder().withNodeIdentifier(NodeIdentifier.create(parentOrdinaryLeaf)).withValue
- (leafValue).build()).build();
+ .withChild(Builders.leafBuilder().withNodeIdentifier(NodeIdentifier.create(parentOrdinaryLeaf))
+ .withValue(leafValue).build()).build();
}
- private MapEntryNode createChildOrderedListEntry(String keyValue, String leafValue) {
+ private MapEntryNode createChildOrderedListEntry(final String keyValue, final String leafValue) {
return Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(childOrderedList,
childKeyLeaf, keyValue))
- .withChild(Builders.leafBuilder().withNodeIdentifier(NodeIdentifier.create(childOrdinaryLeaf)).withValue
- (leafValue).build()).build();
+ .withChild(Builders.leafBuilder().withNodeIdentifier(NodeIdentifier.create(childOrdinaryLeaf))
+ .withValue(leafValue).build()).build();
}
- private NodeIdentifierWithPredicates createParentOrderedListEntryPath(String keyValue) {
+ private NodeIdentifierWithPredicates createParentOrderedListEntryPath(final String keyValue) {
ImmutableMap.Builder<QName, Object> builder = ImmutableMap.builder();
ImmutableMap<QName, Object> keys = builder.put(parentKeyLeaf, keyValue).build();
return new NodeIdentifierWithPredicates(parentOrderedList, keys);
}
- private NodeIdentifierWithPredicates createChildOrderedListEntryPath(String keyValue) {
+ private NodeIdentifierWithPredicates createChildOrderedListEntryPath(final String keyValue) {
ImmutableMap.Builder<QName, Object> builder = ImmutableMap.builder();
ImmutableMap<QName, Object> keys = builder.put(childKeyLeaf, keyValue).build();
return new NodeIdentifierWithPredicates(childOrderedList, keys);
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNodes;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNodes;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
private static final String TWO_ONE_NAME = "one";
private static final String TWO_TWO_NAME = "two";
- private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
- .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
+ private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(
+ TestModel.OUTER_LIST_PATH)
+ .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)
.build();
- private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
- .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
+ private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(
+ TestModel.OUTER_LIST_PATH)
+ .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
.build();
private static final YangInstanceIdentifier TWO_TWO_PATH = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH)
- .node(TestModel.INNER_LIST_QNAME) //
- .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME) //
+ .node(TestModel.INNER_LIST_QNAME)
+ .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME)
.build();
- private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
- .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) //
- .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME)) //
- .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME)) //
- .build()) //
+ private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID)
+ .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME)
+ .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME))
+ .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME))
+ .build())
.build();
private SchemaContext schemaContext;
public void prepare() throws ReactorException {
schemaContext = TestModel.createTestContext();
assertNotNull("Schema context must not be null.", schemaContext);
- rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, DataTreeConfiguration.DEFAULT_OPERATIONAL));
+ rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext,
+ DataTreeConfiguration.DEFAULT_OPERATIONAL));
}
public NormalizedNode<?, ?> createDocumentOne() {
final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
final Optional<TreeNode> expectedNode = StoreTreeNodes.findNode(rootNode, TWO_TWO_PATH);
assertPresentAndType(expectedNode, TreeNode.class);
- final Map.Entry<YangInstanceIdentifier, TreeNode> actualNode = StoreTreeNodes.findClosest(rootNode, TWO_TWO_PATH);
+ final Map.Entry<YangInstanceIdentifier, TreeNode> actualNode = StoreTreeNodes.findClosest(rootNode,
+ TWO_TWO_PATH);
assertEquals("Expected node and actual node are not the same", expectedNode.get(), actualNode.getValue());
}
.build();
final Optional<TreeNode> expectedNode = StoreTreeNodes.findNode(rootNode, outerListInnerListPath);
assertPresentAndType(expectedNode, TreeNode.class);
- final Map.Entry<YangInstanceIdentifier, TreeNode> actualNode = StoreTreeNodes.findClosest(rootNode, twoTwoInvalidPath);
+ final Map.Entry<YangInstanceIdentifier, TreeNode> actualNode = StoreTreeNodes.findClosest(rootNode,
+ twoTwoInvalidPath);
assertEquals("Expected node and actual node are not the same", expectedNode.get(), actualNode.getValue());
}
public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH)
.node(OUTER_LIST_QNAME).build();
- public static final YangInstanceIdentifier INNER_CONTAINER_PATH = YangInstanceIdentifier.builder(TEST_PATH).node(INNER_CONTAINER_QNAME).build();
+ public static final YangInstanceIdentifier INNER_CONTAINER_PATH = TEST_PATH.node(INNER_CONTAINER_QNAME);
public static final YangInstanceIdentifier VALUE_PATH = YangInstanceIdentifier.of(VALUE_QNAME);
- public static final YangInstanceIdentifier INNER_VALUE_PATH = YangInstanceIdentifier.builder(INNER_CONTAINER_PATH).node(VALUE_QNAME).build();
+ public static final YangInstanceIdentifier INNER_VALUE_PATH = INNER_CONTAINER_PATH.node(VALUE_QNAME);
public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two");
public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three");