Fix eclipse/checkstyle warnings
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / YangInstanceIdentifier.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.api;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import com.google.common.cache.CacheBuilder;
14 import com.google.common.cache.CacheLoader;
15 import com.google.common.cache.LoadingCache;
16 import com.google.common.collect.ImmutableSet;
17 import com.google.common.collect.Iterables;
18 import java.io.Serializable;
19 import java.lang.reflect.Array;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Map.Entry;
26 import java.util.Objects;
27 import java.util.Set;
28 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
29 import javax.annotation.Nonnull;
30 import javax.annotation.Nullable;
31 import org.opendaylight.yangtools.concepts.Builder;
32 import org.opendaylight.yangtools.concepts.Immutable;
33 import org.opendaylight.yangtools.concepts.Path;
34 import org.opendaylight.yangtools.util.HashCodeBuilder;
35 import org.opendaylight.yangtools.util.ImmutableOffsetMap;
36 import org.opendaylight.yangtools.util.SharedSingletonMap;
37 import org.opendaylight.yangtools.yang.common.QName;
38 import org.opendaylight.yangtools.yang.common.QNameModule;
39 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
40
41 /**
42  * Unique identifier of a particular node instance in the data tree.
43  *
44  * <p>
45  * Java representation of YANG Built-in type <code>instance-identifier</code>,
46  * which conceptually is XPath expression minimized to uniquely identify element
47  * in data tree which conforms to constraints maintained by YANG Model,
48  * effectively this makes Instance Identifier a path to element in data tree.
49  *
50  * <p>
51  * Constraints put in YANG specification on instance-identifier allowed it to be
52  * effectively represented in Java and it's evaluation does not require
53  * full-blown XPath processor.
54  *
55  * <p>
56  * <h3>Path Arguments</h3>
57  * Path to the node represented in instance identifier consists of
58  * {@link PathArgument} which carries necessary information to uniquely identify
59  * node on particular level in the subtree.
60  *
61  * <ul>
62  * <li>{@link NodeIdentifier} - Identifier of node, which has cardinality
63  * <code>0..1</code> in particular subtree in data tree.</li>
64  * <li>{@link NodeIdentifierWithPredicates} - Identifier of node (list item),
65  * which has cardinality <code>0..n</code>.</li>
66  * <li>{@link NodeWithValue} - Identifier of instance <code>leaf</code> node or
67  * <code>leaf-list</code> node.</li>
68  * <li>{@link AugmentationIdentifier} - Identifier of instance of
69  * <code>augmentation</code> node.</li>
70  * </ul>
71  *
72  * @see <a href="http://tools.ietf.org/html/rfc6020#section-9.13">RFC6020</a>
73  */
74 public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentifier>, Immutable, Serializable {
75     /**
76      * An empty {@link YangInstanceIdentifier}. It corresponds to the path of the conceptual
77      * root of the YANG namespace.
78      */
79     public static final YangInstanceIdentifier EMPTY = FixedYangInstanceIdentifier.EMPTY_INSTANCE;
80
81     private static final AtomicReferenceFieldUpdater<YangInstanceIdentifier, String> TOSTRINGCACHE_UPDATER =
82             AtomicReferenceFieldUpdater.newUpdater(YangInstanceIdentifier.class, String.class, "toStringCache");
83     private static final long serialVersionUID = 4L;
84
85     private final int hash;
86     private transient volatile String toStringCache = null;
87
88     // Package-private to prevent outside subclassing
89     YangInstanceIdentifier(final int hash) {
90         this.hash = hash;
91     }
92
93     @Nonnull abstract YangInstanceIdentifier createRelativeIdentifier(int skipFromRoot);
94
95     @Nonnull abstract Collection<PathArgument> tryPathArguments();
96
97     @Nonnull abstract Collection<PathArgument> tryReversePathArguments();
98
99     /**
100      * Check if this instance identifier has empty path arguments, e.g. it is
101      * empty and corresponds to {@link #EMPTY}.
102      *
103      * @return True if this instance identifier is empty, false otherwise.
104      */
105     public abstract boolean isEmpty();
106
107     /**
108      * Return an optimized version of this identifier, useful when the identifier
109      * will be used very frequently.
110      *
111      * @return A optimized equivalent instance.
112      */
113     @Beta
114     public abstract YangInstanceIdentifier toOptimized();
115
116     /**
117      * Return the conceptual parent {@link YangInstanceIdentifier}, which has
118      * one item less in {@link #getPathArguments()}.
119      *
120      * @return Parent {@link YangInstanceIdentifier}, or null if this object is {@link #EMPTY}.
121      */
122     @Nullable public abstract YangInstanceIdentifier getParent();
123
124     /**
125      * Return the ancestor {@link YangInstanceIdentifier} with a particular depth, e.g. number of path arguments.
126      *
127      * @param depth Ancestor depth
128      * @return Ancestor {@link YangInstanceIdentifier}
129      * @throws IllegalArgumentException if the specified depth is negative or is greater than the depth of this object.
130      */
131     @Nonnull public abstract YangInstanceIdentifier getAncestor(int depth);
132
133     /**
134      * Returns an ordered iteration of path arguments.
135      *
136      * @return Immutable iteration of path arguments.
137      */
138     public abstract List<PathArgument> getPathArguments();
139
140     /**
141      * Returns an iterable of path arguments in reverse order. This is useful
142      * when walking up a tree organized this way.
143      *
144      * @return Immutable iterable of path arguments in reverse order.
145      */
146     public abstract List<PathArgument> getReversePathArguments();
147
148     /**
149      * Returns the last PathArgument. This is equivalent of iterating
150      * to the last element of the iterable returned by {@link #getPathArguments()}.
151      *
152      * @return The last past argument, or null if there are no PathArguments.
153      */
154     public abstract PathArgument getLastPathArgument();
155
156     public static YangInstanceIdentifier create(final Iterable<? extends PathArgument> path) {
157         if (Iterables.isEmpty(path)) {
158             return EMPTY;
159         }
160
161         final HashCodeBuilder<PathArgument> hash = new HashCodeBuilder<>();
162         for (PathArgument a : path) {
163             hash.addArgument(a);
164         }
165
166         return FixedYangInstanceIdentifier.create(path, hash.build());
167     }
168
169     public static YangInstanceIdentifier create(final PathArgument... path) {
170         // We are forcing a copy, since we cannot trust the user
171         return create(Arrays.asList(path));
172     }
173
174     boolean pathArgumentsEqual(final YangInstanceIdentifier other) {
175         return Iterables.elementsEqual(getPathArguments(), other.getPathArguments());
176     }
177
178     @Override
179     public boolean equals(final Object obj) {
180         if (this == obj) {
181             return true;
182         }
183         if (!(obj instanceof YangInstanceIdentifier)) {
184             return false;
185         }
186         YangInstanceIdentifier other = (YangInstanceIdentifier) obj;
187         if (this.hashCode() != obj.hashCode()) {
188             return false;
189         }
190
191         return pathArgumentsEqual(other);
192     }
193
194     /**
195      * Constructs a new Instance Identifier with new {@link NodeIdentifier} added to the end of path arguments.
196      *
197      * @param name QName of {@link NodeIdentifier}
198      * @return Instance Identifier with additional path argument added to the end.
199      */
200     public final YangInstanceIdentifier node(final QName name) {
201         return node(new NodeIdentifier(name));
202     }
203
204     /**
205      * Constructs a new Instance Identifier with new {@link PathArgument} added to the end of path arguments.
206      *
207      * @param arg Path argument which should be added to the end
208      * @return Instance Identifier with additional path argument added to the end.
209      */
210     public final YangInstanceIdentifier node(final PathArgument arg) {
211         return new StackedYangInstanceIdentifier(this, arg, HashCodeBuilder.nextHashCode(hash, arg));
212     }
213
214     /**
215      * Get the relative path from an ancestor. This method attempts to perform
216      * the reverse of concatenating a base (ancestor) and a path.
217      *
218      * @param ancestor
219      *            Ancestor against which the relative path should be calculated
220      * @return This object's relative path from parent, or Optional.absent() if
221      *         the specified parent is not in fact an ancestor of this object.
222      */
223     public Optional<YangInstanceIdentifier> relativeTo(final YangInstanceIdentifier ancestor) {
224         if (this == ancestor) {
225             return Optional.of(EMPTY);
226         }
227         if (ancestor.isEmpty()) {
228             return Optional.of(this);
229         }
230
231         final Iterator<?> lit = getPathArguments().iterator();
232         final Iterator<?> oit = ancestor.getPathArguments().iterator();
233         int common = 0;
234
235         while (oit.hasNext()) {
236             // Ancestor is not really an ancestor
237             if (!lit.hasNext() || !lit.next().equals(oit.next())) {
238                 return Optional.absent();
239             }
240
241             ++common;
242         }
243
244         if (common == 0) {
245             return Optional.of(this);
246         }
247         if (!lit.hasNext()) {
248             return Optional.of(EMPTY);
249         }
250
251         return Optional.of(createRelativeIdentifier(common));
252     }
253
254     @Override
255     public final boolean contains(@Nonnull final YangInstanceIdentifier other) {
256         if (this == other) {
257             return true;
258         }
259
260         Preconditions.checkArgument(other != null, "other should not be null");
261         final Iterator<?> lit = getPathArguments().iterator();
262         final Iterator<?> oit = other.getPathArguments().iterator();
263
264         while (lit.hasNext()) {
265             if (!oit.hasNext()) {
266                 return false;
267             }
268
269             if (!lit.next().equals(oit.next())) {
270                 return false;
271             }
272         }
273
274         return true;
275     }
276
277     @Override
278     public final String toString() {
279         /*
280          * The toStringCache is safe, since the object contract requires
281          * immutability of the object and all objects referenced from this
282          * object.
283          * Used lists, maps are immutable. Path Arguments (elements) are also
284          * immutable, since the PathArgument contract requires immutability.
285          * The cache is thread-safe - if multiple computations occurs at the
286          * same time, cache will be overwritten with same result.
287          */
288         String ret = toStringCache;
289         if (ret == null) {
290             final StringBuilder builder = new StringBuilder("/");
291             PathArgument prev = null;
292             for (PathArgument argument : getPathArguments()) {
293                 if (prev != null) {
294                     builder.append('/');
295                 }
296                 builder.append(argument.toRelativeString(prev));
297                 prev = argument;
298             }
299
300             ret = builder.toString();
301             TOSTRINGCACHE_UPDATER.lazySet(this, ret);
302         }
303         return ret;
304     }
305
306     @Override
307     public final int hashCode() {
308         /*
309          * The caching is safe, since the object contract requires
310          * immutability of the object and all objects referenced from this
311          * object.
312          * Used lists, maps are immutable. Path Arguments (elements) are also
313          * immutable, since the PathArgument contract requires immutability.
314          */
315         return hash;
316     }
317
318     private static int hashCode(final Object value) {
319         if (value == null) {
320             return 0;
321         }
322
323         if (byte[].class.equals(value.getClass())) {
324             return Arrays.hashCode((byte[]) value);
325         }
326
327         if (value.getClass().isArray()) {
328             int hash = 0;
329             int length = Array.getLength(value);
330             for (int i = 0; i < length; i++) {
331                 hash += Objects.hashCode(Array.get(value, i));
332             }
333
334             return hash;
335         }
336
337         return Objects.hashCode(value);
338     }
339
340     // Static factories & helpers
341
342     /**
343      * Returns a new InstanceIdentifier with only one path argument of type {@link NodeIdentifier} with supplied
344      * QName.
345      *
346      * @param name QName of first node identifier
347      * @return Instance Identifier with only one path argument of type {@link NodeIdentifier}
348      */
349     public static YangInstanceIdentifier of(final QName name) {
350         return create(new NodeIdentifier(name));
351     }
352
353     /**
354      * Returns new builder for InstanceIdentifier with empty path arguments.
355      *
356      * @return new builder for InstanceIdentifier with empty path arguments.
357      */
358     public static InstanceIdentifierBuilder builder() {
359         return new YangInstanceIdentifierBuilder();
360     }
361
362     /**
363      * Returns new builder for InstanceIdentifier with path arguments copied from original instance identifier.
364      *
365      * @param origin InstanceIdentifier from which path arguments are copied.
366      * @return new builder for InstanceIdentifier with path arguments copied from original instance identifier.
367      */
368     public static InstanceIdentifierBuilder builder(final YangInstanceIdentifier origin) {
369         return new YangInstanceIdentifierBuilder(origin.getPathArguments(), origin.hashCode());
370     }
371
372     /**
373      * Path argument / component of InstanceIdentifier.
374      * Path argument uniquely identifies node in data tree on particular
375      * level.
376      *
377      * <p>
378      * This interface itself is used as common parent for actual
379      * path arguments types and should not be implemented by user code.
380      *
381      * <p>
382      * Path arguments SHOULD contain only minimum of information
383      * required to uniquely identify node on particular subtree level.
384      *
385      * <p>
386      * For actual path arguments types see:
387      * <ul>
388      * <li>{@link NodeIdentifier} - Identifier of container or leaf
389      * <li>{@link NodeIdentifierWithPredicates} - Identifier of list entries, which have key defined
390      * <li>{@link AugmentationIdentifier} - Identifier of augmentation
391      * <li>{@link NodeWithValue} - Identifier of leaf-list entry
392      * </ul>
393      */
394     public interface PathArgument extends Comparable<PathArgument>, Immutable, Serializable {
395         /**
396          * If applicable returns unique QName of data node as defined in YANG
397          * Schema.
398          *
399          * <p>
400          * This method may return null, if the corresponding schema node, does
401          * not have QName associated, such as in cases of augmentations.
402          *
403          * @return Node type
404          */
405         QName getNodeType();
406
407         /**
408          * Return the string representation of this object for use in context
409          * provided by a previous object. This method can be implemented in
410          * terms of {@link #toString()}, but implementations are encourage to
411          * reuse any context already emitted by the previous object.
412          *
413          * @param previous Previous path argument
414          * @return String representation
415          */
416         String toRelativeString(PathArgument previous);
417     }
418
419     private abstract static class AbstractPathArgument implements PathArgument {
420         private static final long serialVersionUID = -4546547994250849340L;
421         private final QName nodeType;
422         private transient int hashValue;
423         private transient volatile boolean hashGuard = false;
424
425         protected AbstractPathArgument(final QName nodeType) {
426             this.nodeType = Preconditions.checkNotNull(nodeType);
427         }
428
429         @Override
430         public final QName getNodeType() {
431             return nodeType;
432         }
433
434         @Override
435         @SuppressWarnings("checkstyle:parameterName")
436         public int compareTo(@Nonnull final PathArgument o) {
437             return nodeType.compareTo(o.getNodeType());
438         }
439
440         protected int hashCodeImpl() {
441             return 31 + getNodeType().hashCode();
442         }
443
444         @Override
445         public final int hashCode() {
446             if (!hashGuard) {
447                 hashValue = hashCodeImpl();
448                 hashGuard = true;
449             }
450
451             return hashValue;
452         }
453
454         @Override
455         public boolean equals(final Object obj) {
456             if (this == obj) {
457                 return true;
458             }
459             if (obj == null || this.getClass() != obj.getClass()) {
460                 return false;
461             }
462
463             return getNodeType().equals(((AbstractPathArgument)obj).getNodeType());
464         }
465
466         @Override
467         public String toString() {
468             return getNodeType().toString();
469         }
470
471         @Override
472         public String toRelativeString(final PathArgument previous) {
473             if (previous instanceof AbstractPathArgument) {
474                 final QNameModule mod = previous.getNodeType().getModule();
475                 if (getNodeType().getModule().equals(mod)) {
476                     return getNodeType().getLocalName();
477                 }
478             }
479
480             return getNodeType().toString();
481         }
482     }
483
484     /**
485      * Simple path argument identifying a {@link org.opendaylight.yangtools.yang.data.api.schema.ContainerNode} or
486      * {@link org.opendaylight.yangtools.yang.data.api.schema.LeafNode} leaf in particular subtree.
487      */
488     public static final class NodeIdentifier extends AbstractPathArgument {
489         private static final long serialVersionUID = -2255888212390871347L;
490         private static final LoadingCache<QName, NodeIdentifier> CACHE = CacheBuilder.newBuilder().weakValues()
491                 .build(new CacheLoader<QName, NodeIdentifier>() {
492                     @Override
493                     public NodeIdentifier load(@Nonnull final QName key) {
494                         return new NodeIdentifier(key);
495                     }
496                 });
497
498         public NodeIdentifier(final QName node) {
499             super(node);
500         }
501
502         /**
503          * Return a NodeIdentifier for a particular QName. Unlike the constructor, this factory method uses a global
504          * instance cache, resulting in object reuse for equal inputs.
505          *
506          * @param node Node's QName
507          * @return A {@link NodeIdentifier}
508          */
509         public static NodeIdentifier create(final QName node) {
510             return CACHE.getUnchecked(node);
511         }
512     }
513
514     /**
515      * Composite path argument identifying a {@link org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode} leaf
516      * overall data tree.
517      */
518     public static final class NodeIdentifierWithPredicates extends AbstractPathArgument {
519         private static final long serialVersionUID = -4787195606494761540L;
520
521         private final Map<QName, Object> keyValues;
522
523         public NodeIdentifierWithPredicates(final QName node, final Map<QName, Object> keyValues) {
524             super(node);
525             // Retains ImmutableMap for empty maps. For larger sizes uses a shared key set.
526             this.keyValues = ImmutableOffsetMap.unorderedCopyOf(keyValues);
527         }
528
529         public NodeIdentifierWithPredicates(final QName node, final QName key, final Object value) {
530             super(node);
531             this.keyValues = SharedSingletonMap.unorderedOf(key, value);
532         }
533
534         public Map<QName, Object> getKeyValues() {
535             return keyValues;
536         }
537
538         @Override
539         protected int hashCodeImpl() {
540             final int prime = 31;
541             int result = super.hashCodeImpl();
542             result = prime * result;
543
544             for (Entry<QName, Object> entry : keyValues.entrySet()) {
545                 result += Objects.hashCode(entry.getKey()) + YangInstanceIdentifier.hashCode(entry.getValue());
546             }
547             return result;
548         }
549
550         @Override
551         public boolean equals(final Object obj) {
552             if (!super.equals(obj)) {
553                 return false;
554             }
555
556             final Map<QName, Object> otherKeyValues = ((NodeIdentifierWithPredicates) obj).keyValues;
557
558             // TODO: benchmark to see if just calling equals() on the two maps is not faster
559             if (keyValues == otherKeyValues) {
560                 return true;
561             }
562             if (keyValues.size() != otherKeyValues.size()) {
563                 return false;
564             }
565
566             for (Entry<QName, Object> entry : keyValues.entrySet()) {
567                 if (!otherKeyValues.containsKey(entry.getKey())
568                         || !Objects.deepEquals(entry.getValue(), otherKeyValues.get(entry.getKey()))) {
569
570                     return false;
571                 }
572             }
573
574             return true;
575         }
576
577         @Override
578         public String toString() {
579             return super.toString() + '[' + keyValues + ']';
580         }
581
582         @Override
583         public String toRelativeString(final PathArgument previous) {
584             return super.toRelativeString(previous) + '[' + keyValues + ']';
585         }
586     }
587
588     /**
589      * Simple path argument identifying a {@link LeafSetEntryNode} leaf
590      * overall data tree.
591      */
592     public static final class NodeWithValue<T> extends AbstractPathArgument {
593         private static final long serialVersionUID = -3637456085341738431L;
594
595         private final T value;
596
597         public NodeWithValue(final QName node, final T value) {
598             super(node);
599             this.value = value;
600         }
601
602         public T getValue() {
603             return value;
604         }
605
606         @Override
607         protected int hashCodeImpl() {
608             final int prime = 31;
609             int result = super.hashCodeImpl();
610             result = prime * result + YangInstanceIdentifier.hashCode(value);
611             return result;
612         }
613
614         @Override
615         public boolean equals(final Object obj) {
616             if (!super.equals(obj)) {
617                 return false;
618             }
619             final NodeWithValue<?> other = (NodeWithValue<?>) obj;
620             return Objects.deepEquals(value, other.value);
621         }
622
623         @Override
624         public String toString() {
625             return super.toString() + '[' + value + ']';
626         }
627
628         @Override
629         public String toRelativeString(final PathArgument previous) {
630             return super.toRelativeString(previous) + '[' + value + ']';
631         }
632     }
633
634     /**
635      * Composite path argument identifying a {@link org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode}
636      * node in particular subtree.
637      *
638      * <p>
639      * Augmentation is uniquely identified by set of all possible child nodes.
640      * This is possible
641      * to identify instance of augmentation,
642      * since RFC6020 states that <code>augment</code> that augment
643      * statement must not add multiple nodes from same namespace
644      * / module to the target node.
645      *
646      * @see <a href="http://tools.ietf.org/html/rfc6020#section-7.15">RFC6020</a>
647      */
648     public static final class AugmentationIdentifier implements PathArgument {
649         private static final long serialVersionUID = -8122335594681936939L;
650         private final ImmutableSet<QName> childNames;
651
652         @Override
653         public QName getNodeType() {
654             // This should rather throw exception than return always null
655             throw new UnsupportedOperationException("Augmentation node has no QName");
656         }
657
658         /**
659          * Construct new augmentation identifier using supplied set of possible
660          * child nodes.
661          *
662          * @param childNames
663          *            Set of possible child nodes.
664          */
665         public AugmentationIdentifier(final Set<QName> childNames) {
666             this.childNames = ImmutableSet.copyOf(childNames);
667         }
668
669         /**
670          * Returns set of all possible child nodes.
671          *
672          * @return set of all possible child nodes.
673          */
674         public Set<QName> getPossibleChildNames() {
675             return childNames;
676         }
677
678         @Override
679         public String toString() {
680             return "AugmentationIdentifier{" + "childNames=" + childNames + '}';
681         }
682
683         @Override
684         public String toRelativeString(final PathArgument previous) {
685             return toString();
686         }
687
688         @Override
689         public boolean equals(final Object obj) {
690             if (this == obj) {
691                 return true;
692             }
693             if (!(obj instanceof AugmentationIdentifier)) {
694                 return false;
695             }
696
697             AugmentationIdentifier that = (AugmentationIdentifier) obj;
698             return childNames.equals(that.childNames);
699         }
700
701         @Override
702         public int hashCode() {
703             return childNames.hashCode();
704         }
705
706         @Override
707         @SuppressWarnings("checkstyle:parameterName")
708         public int compareTo(@Nonnull final PathArgument o) {
709             if (!(o instanceof AugmentationIdentifier)) {
710                 return -1;
711             }
712             AugmentationIdentifier other = (AugmentationIdentifier) o;
713             Set<QName> otherChildNames = other.getPossibleChildNames();
714             int thisSize = childNames.size();
715             int otherSize = otherChildNames.size();
716             if (thisSize == otherSize) {
717                 Iterator<QName> otherIterator = otherChildNames.iterator();
718                 for (QName name : childNames) {
719                     int child = name.compareTo(otherIterator.next());
720                     if (child != 0) {
721                         return child;
722                     }
723                 }
724                 return 0;
725             } else if (thisSize < otherSize) {
726                 return 1;
727             } else {
728                 return -1;
729             }
730         }
731     }
732
733     /**
734      * Fluent Builder of Instance Identifier instances.
735      */
736     public interface InstanceIdentifierBuilder extends Builder<YangInstanceIdentifier> {
737         /**
738          * Adds a {@link PathArgument} to to path arguments of resulting instance identifier.
739          *
740          * @param arg A {@link PathArgument} to be added
741          * @return this builder
742          */
743         InstanceIdentifierBuilder node(PathArgument arg);
744
745         /**
746          * Adds {@link NodeIdentifier} with supplied QName to path arguments of resulting instance identifier.
747          *
748          * @param nodeType QName of {@link NodeIdentifier} which will be added
749          * @return this builder
750          */
751         InstanceIdentifierBuilder node(QName nodeType);
752
753         /**
754          * Adds {@link NodeIdentifierWithPredicates} with supplied QName and key values to path arguments of resulting
755          * instance identifier.
756          *
757          * @param nodeType QName of {@link NodeIdentifierWithPredicates} which will be added
758          * @param keyValues Map of key components and their respective values for {@link NodeIdentifierWithPredicates}
759          * @return this builder
760          */
761         InstanceIdentifierBuilder nodeWithKey(QName nodeType, Map<QName, Object> keyValues);
762
763         /**
764          * Adds {@link NodeIdentifierWithPredicates} with supplied QName and key, value.
765          *
766          * @param nodeType QName of {@link NodeIdentifierWithPredicates} which will be added
767          * @param key QName of key which will be added
768          * @param value value of key which will be added
769          * @return this builder
770          */
771         InstanceIdentifierBuilder nodeWithKey(QName nodeType, QName key, Object value);
772
773         /**
774          * Builds an {@link YangInstanceIdentifier} with path arguments from this builder.
775          *
776          * @return {@link YangInstanceIdentifier}
777          */
778         @Override
779         YangInstanceIdentifier build();
780     }
781 }