2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.binding;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Verify.verify;
12 import static java.util.Objects.requireNonNull;
14 import com.google.common.base.MoreObjects;
15 import com.google.common.base.MoreObjects.ToStringHelper;
16 import com.google.common.base.VerifyException;
17 import com.google.common.collect.ImmutableCollection;
18 import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.Iterables;
20 import java.io.ObjectStreamException;
21 import java.io.Serializable;
22 import java.util.Collections;
23 import java.util.Iterator;
24 import java.util.Objects;
25 import java.util.Optional;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.eclipse.jdt.annotation.Nullable;
28 import org.opendaylight.yangtools.concepts.Builder;
29 import org.opendaylight.yangtools.concepts.Immutable;
30 import org.opendaylight.yangtools.concepts.Path;
31 import org.opendaylight.yangtools.util.HashCodeBuilder;
34 * This instance identifier uniquely identifies a specific DataObject in the data tree modeled by YANG.
37 * For Example let's say you were trying to refer to a node in inventory which was modeled in YANG as follows,
41 * module opendaylight-inventory {
47 * ext:context-instance "node-context";
57 * You can create an instance identifier as follows to get to a node with id "openflow:1": {@code
58 * InstanceIdentifierBuilder.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:1")).build();
62 * This would be the same as using a path like so, "/nodes/node/openflow:1" to refer to the openflow:1 node
64 public class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<? extends DataObject>>,
65 Immutable, Serializable {
66 private static final long serialVersionUID = 3L;
69 * Protected to differentiate internal and external access. Internal access is required never to modify
70 * the contents. References passed to outside entities have to be wrapped in an unmodifiable view.
72 final Iterable<PathArgument> pathArguments;
74 private final @NonNull Class<T> targetType;
75 private final boolean wildcarded;
76 private final int hash;
78 InstanceIdentifier(final Class<T> type, final Iterable<PathArgument> pathArguments, final boolean wildcarded,
80 this.pathArguments = requireNonNull(pathArguments);
81 this.targetType = requireNonNull(type);
82 this.wildcarded = wildcarded;
87 * Return the type of data which this InstanceIdentifier identifies.
91 public final @NonNull Class<T> getTargetType() {
96 * Perform a safe target type adaptation of this instance identifier to target type. This method is useful when
97 * dealing with type-squashed instances.
99 * @return Path argument with target type
100 * @throws VerifyException if this instance identifier cannot be adapted to target type
101 * @throws NullPointerException if {@code target} is null
103 @SuppressWarnings("unchecked")
104 public final <N extends DataObject> @NonNull InstanceIdentifier<N> verifyTarget(final Class<@NonNull N> target) {
105 verify(target.equals(targetType), "Cannot adapt %s to %s", this, target);
106 return (InstanceIdentifier<N>) this;
110 * Return the path argument chain which makes up this instance identifier.
112 * @return Path argument chain. Immutable and does not contain nulls.
114 public final @NonNull Iterable<PathArgument> getPathArguments() {
115 return Iterables.unmodifiableIterable(pathArguments);
119 * Check whether an instance identifier contains any wildcards. A wildcard is an path argument which has a null key.
121 * @return true if any of the path arguments has a null key.
123 public final boolean isWildcarded() {
128 public final int hashCode() {
133 public final boolean equals(final Object obj) {
140 if (getClass() != obj.getClass()) {
144 final InstanceIdentifier<?> other = (InstanceIdentifier<?>) obj;
145 if (pathArguments == other.pathArguments) {
150 * We could now just go and compare the pathArguments, but that
151 * can be potentially expensive. Let's try to avoid that by
152 * checking various things that we have cached from pathArguments
153 * and trying to prove the identifiers are *not* equal.
155 if (hash != other.hash) {
158 if (wildcarded != other.wildcarded) {
161 if (targetType != other.targetType) {
164 if (fastNonEqual(other)) {
168 // Everything checks out so far, so we have to do a full equals
169 return Iterables.elementsEqual(pathArguments, other.pathArguments);
173 * Perform class-specific fast checks for non-equality. This allows subclasses to avoid iterating over the
174 * pathArguments by performing quick checks on their specific fields.
176 * @param other The other identifier, guaranteed to be the same class
177 * @return true if the other identifier cannot be equal to this one.
179 protected boolean fastNonEqual(final InstanceIdentifier<?> other) {
184 public final String toString() {
185 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
189 * Add class-specific toString attributes.
191 * @param toStringHelper ToStringHelper instance
192 * @return ToStringHelper instance which was passed in
194 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
195 return toStringHelper.add("targetType", targetType).add("path", Iterables.toString(pathArguments));
199 * Return an instance identifier trimmed at the first occurrence of a specific component type.
202 * For example let's say an instance identifier was built like so,
204 * identifier = InstanceIdentifierBuilder.builder(Nodes.class).child(Node.class,
205 * new NodeKey(new NodeId("openflow:1")).build();
209 * And you wanted to obtain the Instance identifier which represented Nodes you would do it like so,
213 * identifier.firstIdentifierOf(Nodes.class)
216 * @param type component type
217 * @return trimmed instance identifier, or null if the component type
220 public final <I extends DataObject> @Nullable InstanceIdentifier<I> firstIdentifierOf(
221 final Class<@NonNull I> type) {
223 for (final PathArgument a : pathArguments) {
224 if (type.equals(a.getType())) {
225 @SuppressWarnings("unchecked")
226 final InstanceIdentifier<I> ret = (InstanceIdentifier<I>) internalCreate(
227 Iterables.limit(pathArguments, count));
238 * Return the key associated with the first component of specified type in
241 * @param listItem component type
242 * @return key associated with the component, or null if the component type
245 public final <N extends Identifiable<K> & DataObject, K extends Identifier<N>> @Nullable K firstKeyOf(
246 final Class<@NonNull N> listItem) {
247 for (final PathArgument i : pathArguments) {
248 if (listItem.equals(i.getType())) {
249 @SuppressWarnings("unchecked")
250 final K ret = ((IdentifiableItem<N, K>)i).getKey();
259 * Check whether an identifier is contained in this identifier. This is a strict subtree check, which requires all
260 * PathArguments to match exactly.
263 * The contains method checks if the other identifier is fully contained within the current identifier. It does this
264 * by looking at only the types of the path arguments and not by comparing the path arguments themselves.
267 * To illustrate here is an example which explains the working of this API. Let's say you have two instance
268 * identifiers as follows:
270 * this = /nodes/node/openflow:1
271 * other = /nodes/node/openflow:2
273 * then this.contains(other) will return false.
275 * @param other Potentially-container instance identifier
276 * @return True if the specified identifier is contained in this identifier.
279 public final boolean contains(final InstanceIdentifier<? extends DataObject> other) {
280 requireNonNull(other, "other should not be null");
282 final Iterator<?> lit = pathArguments.iterator();
283 final Iterator<?> oit = other.pathArguments.iterator();
285 while (lit.hasNext()) {
286 if (!oit.hasNext()) {
290 if (!lit.next().equals(oit.next())) {
299 * Check whether this instance identifier contains the other identifier after wildcard expansion. This is similar
300 * to {@link #contains(InstanceIdentifier)}, with the exception that a wildcards are assumed to match the their
301 * non-wildcarded PathArgument counterpart.
303 * @param other Identifier which should be checked for inclusion.
304 * @return true if this identifier contains the other object
306 public final boolean containsWildcarded(final InstanceIdentifier<?> other) {
307 requireNonNull(other, "other should not be null");
309 final Iterator<PathArgument> lit = pathArguments.iterator();
310 final Iterator<PathArgument> oit = other.pathArguments.iterator();
312 while (lit.hasNext()) {
313 if (!oit.hasNext()) {
317 final PathArgument la = lit.next();
318 final PathArgument oa = oit.next();
320 if (!la.getType().equals(oa.getType())) {
323 if (la instanceof IdentifiableItem<?, ?> && oa instanceof IdentifiableItem<?, ?> && !la.equals(oa)) {
331 private <N extends DataObject> @NonNull InstanceIdentifier<N> childIdentifier(final AbstractPathArgument<N> arg) {
332 return trustedCreate(arg, Iterables.concat(pathArguments, Collections.singleton(arg)),
333 HashCodeBuilder.nextHashCode(hash, arg), isWildcarded());
337 * Create an InstanceIdentifier for a child container. This method is a more efficient equivalent to
338 * {@code builder().child(container).build()}.
340 * @param container Container to append
341 * @param <N> Container type
342 * @return An InstanceIdentifier.
343 * @throws NullPointerException if {@code container} is null
345 public final <N extends ChildOf<? super T>> @NonNull InstanceIdentifier<N> child(
346 final Class<@NonNull N> container) {
347 return childIdentifier(Item.of(container));
351 * Create an InstanceIdentifier for a child list item. This method is a more efficient equivalent to
352 * {@code builder().child(listItem, listKey).build()}.
354 * @param listItem List to append
355 * @param listKey List key
356 * @param <N> List type
357 * @param <K> Key type
358 * @return An InstanceIdentifier.
359 * @throws NullPointerException if any argument is null
361 @SuppressWarnings("unchecked")
362 public final <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>>
363 @NonNull KeyedInstanceIdentifier<N, K> child(final Class<@NonNull N> listItem, final K listKey) {
364 return (KeyedInstanceIdentifier<N, K>) childIdentifier(IdentifiableItem.of(listItem, listKey));
368 * Create an InstanceIdentifier for a child container. This method is a more efficient equivalent to
369 * {@code builder().child(caze, container).build()}.
371 * @param caze Choice case class
372 * @param container Container to append
373 * @param <C> Case type
374 * @param <N> Container type
375 * @return An InstanceIdentifier.
376 * @throws NullPointerException if any argument is null
378 // FIXME: add a proper caller
379 public final <C extends ChoiceIn<? super T> & DataObject, N extends ChildOf<? super C>>
380 @NonNull InstanceIdentifier<N> child(final Class<@NonNull C> caze, final Class<@NonNull N> container) {
381 return childIdentifier(Item.of(caze, container));
385 * Create an InstanceIdentifier for a child list item. This method is a more efficient equivalent to
386 * {@code builder().child(caze, listItem, listKey).build()}.
388 * @param caze Choice case class
389 * @param listItem List to append
390 * @param listKey List key
391 * @param <C> Case type
392 * @param <N> List type
393 * @param <K> Key type
394 * @return An InstanceIdentifier.
395 * @throws NullPointerException if any argument is null
397 // FIXME: add a proper caller
398 @SuppressWarnings("unchecked")
399 public final <C extends ChoiceIn<? super T> & DataObject, K extends Identifier<N>,
400 N extends Identifiable<K> & ChildOf<? super C>> @NonNull KeyedInstanceIdentifier<N, K> child(
401 final Class<@NonNull C> caze, final Class<@NonNull N> listItem, final K listKey) {
402 return (KeyedInstanceIdentifier<N, K>) childIdentifier(IdentifiableItem.of(caze, listItem, listKey));
406 * Create an InstanceIdentifier for a child augmentation. This method is a more efficient equivalent to
407 * {@code builder().augmentation(container).build()}.
409 * @param container Container to append
410 * @param <N> Container type
411 * @return An InstanceIdentifier.
412 * @throws NullPointerException if {@code container} is null
414 public final <N extends DataObject & Augmentation<? super T>> @NonNull InstanceIdentifier<N> augmentation(
415 final Class<@NonNull N> container) {
416 return childIdentifier(Item.of(container));
420 * Create a builder rooted at this key.
422 * @return A builder instance
424 public @NonNull InstanceIdentifierBuilder<T> builder() {
425 return new InstanceIdentifierBuilderImpl<>(Item.of(targetType), pathArguments, hash, isWildcarded());
429 * Create an InstanceIdentifierBuilder for a specific type of InstanceIdentifier as specified by container.
431 * @param container Base container
432 * @param <T> Type of the container
433 * @return A new {@link InstanceIdentifierBuilder}
434 * @throws NullPointerException if {@code container} is null
436 public static <T extends ChildOf<? extends DataRoot>> @NonNull InstanceIdentifierBuilder<T> builder(
437 final Class<T> container) {
438 return new InstanceIdentifierBuilderImpl<T>().addWildNode(Item.of(container));
442 * Create an InstanceIdentifierBuilder for a specific type of InstanceIdentifier as specified by container in
443 * a {@code grouping} used in the {@code case} statement.
445 * @param caze Choice case class
446 * @param container Base container
447 * @param <C> Case type
448 * @param <T> Type of the container
449 * @return A new {@link InstanceIdentifierBuilder}
450 * @throws NullPointerException if any argument is null
452 public static <C extends ChoiceIn<? extends DataRoot> & DataObject, T extends ChildOf<? super C>>
453 @NonNull InstanceIdentifierBuilder<T> builder(final Class<C> caze, final Class<T> container) {
454 return new InstanceIdentifierBuilderImpl<T>().addWildNode(Item.of(caze, container));
458 * Create an InstanceIdentifierBuilder for a specific type of InstanceIdentifier which represents an
459 * {@link IdentifiableItem}.
461 * @param listItem list item class
462 * @param listKey key value
463 * @param <N> List type
464 * @param <K> List key
465 * @return A new {@link InstanceIdentifierBuilder}
466 * @throws NullPointerException if any argument is null
468 public static <N extends Identifiable<K> & ChildOf<? extends DataRoot>,
469 K extends Identifier<N>> @NonNull InstanceIdentifierBuilder<N> builder(final Class<N> listItem,
471 return new InstanceIdentifierBuilderImpl<N>().addNode(IdentifiableItem.of(listItem, listKey));
475 * Create an InstanceIdentifierBuilder for a specific type of InstanceIdentifier which represents an
476 * {@link IdentifiableItem} in a {@code grouping} used in the {@code case} statement.
478 * @param caze Choice case class
479 * @param listItem list item class
480 * @param listKey key value
481 * @param <C> Case type
482 * @param <N> List type
483 * @param <K> List key
484 * @return A new {@link InstanceIdentifierBuilder}
485 * @throws NullPointerException if any argument is null
487 public static <C extends ChoiceIn<? extends DataRoot> & DataObject,
488 N extends Identifiable<K> & ChildOf<? super C>, K extends Identifier<N>>
489 @NonNull InstanceIdentifierBuilder<N> builder(final Class<C> caze, final Class<N> listItem,
491 return new InstanceIdentifierBuilderImpl<N>().addNode(IdentifiableItem.of(caze, listItem, listKey));
495 * Create an instance identifier for a very specific object type. This method implements {@link #create(Iterable)}
496 * semantics, except it is used by internal callers, which have assured that the argument is an immutable Iterable.
498 * @param pathArguments The path to a specific node in the data tree
499 * @return InstanceIdentifier instance
500 * @throws IllegalArgumentException if pathArguments is empty or contains a null element.
501 * @throws NullPointerException if {@code pathArguments} is null
503 private static @NonNull InstanceIdentifier<?> internalCreate(final Iterable<PathArgument> pathArguments) {
504 final Iterator<? extends PathArgument> it = requireNonNull(pathArguments, "pathArguments may not be null")
506 final HashCodeBuilder<PathArgument> hashBuilder = new HashCodeBuilder<>();
507 boolean wildcard = false;
508 PathArgument arg = null;
510 while (it.hasNext()) {
512 checkArgument(arg != null, "pathArguments may not contain null elements");
514 // TODO: sanity check ChildOf<>;
515 hashBuilder.addArgument(arg);
517 if (Identifiable.class.isAssignableFrom(arg.getType()) && !(arg instanceof IdentifiableItem<?, ?>)) {
521 checkArgument(arg != null, "pathArguments may not be empty");
523 return trustedCreate(arg, pathArguments, hashBuilder.build(), wildcard);
527 * Create an instance identifier for a very specific object type.
532 * List<PathArgument> path = Arrays.asList(new Item(Nodes.class))
533 * new InstanceIdentifier(path);
536 * @param pathArguments The path to a specific node in the data tree
537 * @return InstanceIdentifier instance
538 * @throws IllegalArgumentException if pathArguments is empty or
539 * contains a null element.
541 public static @NonNull InstanceIdentifier<?> create(final Iterable<? extends PathArgument> pathArguments) {
542 if (pathArguments instanceof ImmutableCollection<?>) {
543 @SuppressWarnings("unchecked")
544 final Iterable<PathArgument> immutableArguments = (Iterable<PathArgument>) pathArguments;
545 return internalCreate(immutableArguments);
548 return internalCreate(ImmutableList.copyOf(pathArguments));
552 * Create an instance identifier for a very specific object type.
557 * new InstanceIdentifier(Nodes.class)
559 * would create an InstanceIdentifier for an object of type Nodes
561 * @param type The type of the object which this instance identifier represents
562 * @return InstanceIdentifier instance
564 @SuppressWarnings("unchecked")
565 public static <T extends DataObject> @NonNull InstanceIdentifier<T> create(final Class<@NonNull T> type) {
566 return (InstanceIdentifier<T>) create(ImmutableList.of(Item.of(type)));
570 * Return the key associated with the last component of the specified identifier.
572 * @param id instance identifier
573 * @return key associated with the last component
574 * @throws IllegalArgumentException if the supplied identifier type cannot have a key.
575 * @throws NullPointerException if id is null.
577 public static <N extends Identifiable<K> & DataObject, K extends Identifier<N>> K keyOf(
578 final InstanceIdentifier<N> id) {
580 checkArgument(id instanceof KeyedInstanceIdentifier, "%s does not have a key", id);
582 @SuppressWarnings("unchecked")
583 final K ret = ((KeyedInstanceIdentifier<N, K>)id).getKey();
587 @SuppressWarnings({ "unchecked", "rawtypes" })
588 static <N extends DataObject> @NonNull InstanceIdentifier<N> trustedCreate(final PathArgument arg,
589 final Iterable<PathArgument> pathArguments, final int hash, boolean wildcarded) {
590 if (Identifiable.class.isAssignableFrom(arg.getType()) && !wildcarded) {
591 Identifier<?> key = null;
592 if (arg instanceof IdentifiableItem) {
593 key = ((IdentifiableItem<?, ?>)arg).getKey();
598 return new KeyedInstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash, key);
601 return new InstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash);
605 * Path argument of {@link InstanceIdentifier}. Interface which implementations are used as path components of the
606 * path in overall data tree.
608 public interface PathArgument extends Comparable<PathArgument> {
610 * Return the data object type backing this PathArgument.
612 * @return Data object type.
614 @NonNull Class<? extends DataObject> getType();
617 * Return an optional enclosing case type. This is used only when {@link #getType()} references a node defined
618 * in a {@code grouping} which is reference inside a {@code case} statement in order to safely reference the
621 * @return Optional case class.
623 default Optional<? extends Class<? extends DataObject>> getCaseType() {
624 return Optional.empty();
628 private abstract static class AbstractPathArgument<T extends DataObject> implements PathArgument, Serializable {
629 private static final long serialVersionUID = 1L;
631 private final @NonNull Class<T> type;
633 AbstractPathArgument(final Class<T> type) {
634 this.type = requireNonNull(type, "Type may not be null.");
638 public final Class<T> getType() {
647 public final int hashCode() {
648 return Objects.hash(type, getCaseType(), getKey());
652 public final boolean equals(final Object obj) {
656 if (!(obj instanceof AbstractPathArgument)) {
659 final AbstractPathArgument<?> other = (AbstractPathArgument<?>) obj;
660 return type.equals(other.type) && Objects.equals(getKey(), other.getKey())
661 && getCaseType().equals(other.getCaseType());
665 public final int compareTo(final PathArgument arg) {
666 final int cmp = compareClasses(type, arg.getType());
670 final Optional<? extends Class<?>> caseType = getCaseType();
671 if (!caseType.isPresent()) {
672 return arg.getCaseType().isPresent() ? -1 : 1;
674 final Optional<? extends Class<?>> argCaseType = getCaseType();
675 return argCaseType.isPresent() ? compareClasses(caseType.get(), argCaseType.get()) : 1;
678 private static int compareClasses(final Class<?> first, final Class<?> second) {
679 return first.getCanonicalName().compareTo(second.getCanonicalName());
684 * An Item represents an object that probably is only one of it's kind. For example a Nodes object is only one of
685 * a kind. In YANG terms this would probably represent a container.
687 * @param <T> Item type
689 public static class Item<T extends DataObject> extends AbstractPathArgument<T> {
690 private static final long serialVersionUID = 1L;
692 Item(final Class<T> type) {
697 * Return a PathArgument instance backed by the specified class.
699 * @param type Backing class
700 * @param <T> Item type
701 * @return A new PathArgument
702 * @throws NullPointerException if {@code} is null.
704 public static <T extends DataObject> @NonNull Item<T> of(final Class<T> type) {
705 return new Item<>(type);
709 * Return a PathArgument instance backed by the specified class, which in turn is defined in a {@code grouping}
710 * used in a corresponding {@code case} statement.
712 * @param caseType defining case class
713 * @param type Backing class
714 * @param <C> Case type
715 * @param <T> Item type
716 * @return A new PathArgument
717 * @throws NullPointerException if any argument is null.
719 public static <C extends ChoiceIn<?> & DataObject, T extends ChildOf<? super C>> @NonNull Item<T> of(
720 final Class<C> caseType, final Class<T> type) {
721 return new CaseItem<>(caseType, type);
725 public String toString() {
726 return getType().getName();
731 * An IdentifiableItem represents a object that is usually present in a collection and can be identified uniquely
732 * by a key. In YANG terms this would probably represent an item in a list.
734 * @param <I> An object that is identifiable by an identifier
735 * @param <T> The identifier of the object
737 public static class IdentifiableItem<I extends Identifiable<T> & DataObject, T extends Identifier<I>>
738 extends AbstractPathArgument<I> {
739 private static final long serialVersionUID = 1L;
741 private final @NonNull T key;
743 IdentifiableItem(final Class<I> type, final T key) {
745 this.key = requireNonNull(key, "Key may not be null.");
749 * Return an IdentifiableItem instance backed by the specified class with specified key.
751 * @param type Backing class
753 * @param <T> List type
754 * @param <I> Key type
755 * @return An IdentifiableItem
756 * @throws NullPointerException if any argument is null.
758 public static <T extends Identifiable<I> & DataObject, I extends Identifier<T>>
759 @NonNull IdentifiableItem<T, I> of(final Class<T> type, final I key) {
760 return new IdentifiableItem<>(type, key);
764 * Return an IdentifiableItem instance backed by the specified class with specified key. The class is in turn
765 * defined in a {@code grouping} used in a corresponding {@code case} statement.
767 * @param caseType defining case class
768 * @param type Backing class
769 * @param <C> Case type
770 * @param <T> List type
771 * @param <I> Key type
772 * @return A new PathArgument
773 * @throws NullPointerException if any argument is null.
775 public static <C extends ChoiceIn<?> & DataObject, T extends ChildOf<? super C> & Identifiable<I>,
776 I extends Identifier<T>> @NonNull IdentifiableItem<T, I> of(final Class<C> caseType,
777 final Class<T> type, final I key) {
778 return new CaseIdentifiableItem<>(caseType, type, key);
782 * Return the data object type backing this PathArgument.
784 * @return Data object type.
787 public final @NonNull T getKey() {
792 public String toString() {
793 return getType().getName() + "[key=" + key + "]";
797 private static final class CaseItem<C extends ChoiceIn<?> & DataObject, T extends ChildOf<? super C>>
799 private static final long serialVersionUID = 1L;
801 private final Class<C> caseType;
803 CaseItem(final Class<C> caseType, final Class<T> type) {
805 this.caseType = requireNonNull(caseType);
809 public Optional<Class<C>> getCaseType() {
810 return Optional.of(caseType);
814 private static final class CaseIdentifiableItem<C extends ChoiceIn<?> & DataObject,
815 T extends ChildOf<? super C> & Identifiable<K>, K extends Identifier<T>> extends IdentifiableItem<T, K> {
816 private static final long serialVersionUID = 1L;
818 private final Class<C> caseType;
820 CaseIdentifiableItem(final Class<C> caseType, final Class<T> type, final K key) {
822 this.caseType = requireNonNull(caseType);
826 public Optional<Class<C>> getCaseType() {
827 return Optional.of(caseType);
831 public interface InstanceIdentifierBuilder<T extends DataObject> extends Builder<InstanceIdentifier<T>> {
833 * Append the specified container as a child of the current InstanceIdentifier referenced by the builder. This
834 * method should be used when you want to build an instance identifier by appending top-level elements, for
837 * InstanceIdentifier.builder().child(Nodes.class).build();
841 * NOTE :- The above example is only for illustration purposes InstanceIdentifier.builder() has been deprecated
842 * and should not be used. Use InstanceIdentifier.builder(Nodes.class) instead
844 * @param container Container to append
845 * @param <N> Container type
846 * @return this builder
847 * @throws NullPointerException if {@code container} is null
849 <N extends ChildOf<? super T>> @NonNull InstanceIdentifierBuilder<N> child(Class<N> container);
852 * Append the specified container as a child of the current InstanceIdentifier referenced by the builder. This
853 * method should be used when you want to build an instance identifier by appending a container node to the
854 * identifier and the {@code container} is defined in a {@code grouping} used in a {@code case} statement.
856 * @param caze Choice case class
857 * @param container Container to append
858 * @param <C> Case type
859 * @param <N> Container type
860 * @return this builder
861 * @throws NullPointerException if {@code container} is null
863 <C extends ChoiceIn<? super T> & DataObject, N extends ChildOf<? super C>>
864 @NonNull InstanceIdentifierBuilder<N> child(Class<C> caze, Class<N> container);
867 * Append the specified listItem as a child of the current InstanceIdentifier referenced by the builder. This
868 * method should be used when you want to build an instance identifier by appending a specific list element to
871 * @param listItem List to append
872 * @param listKey List key
873 * @param <N> List type
874 * @param <K> Key type
875 * @return this builder
876 * @throws NullPointerException if any argument is null
878 <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>>
879 @NonNull InstanceIdentifierBuilder<N> child(Class<@NonNull N> listItem, K listKey);
882 * Append the specified listItem as a child of the current InstanceIdentifier referenced by the builder. This
883 * method should be used when you want to build an instance identifier by appending a specific list element to
884 * the identifier and the {@code list} is defined in a {@code grouping} used in a {@code case} statement.
886 * @param caze Choice case class
887 * @param listItem List to append
888 * @param listKey List key
889 * @param <C> Case type
890 * @param <N> List type
891 * @param <K> Key type
892 * @return this builder
893 * @throws NullPointerException if any argument is null
895 <C extends ChoiceIn<? super T> & DataObject, K extends Identifier<N>,
896 N extends Identifiable<K> & ChildOf<? super C>> @NonNull InstanceIdentifierBuilder<N> child(
897 Class<C> caze, Class<N> listItem, K listKey);
900 * Build an identifier which refers to a specific augmentation of the current InstanceIdentifier referenced by
903 * @param container augmentation class
904 * @param <N> augmentation type
905 * @return this builder
906 * @throws NullPointerException if {@code container} is null
908 <N extends DataObject & Augmentation<? super T>> @NonNull InstanceIdentifierBuilder<N> augmentation(
912 * Build the instance identifier.
914 * @return Resulting instance identifier.
917 InstanceIdentifier<T> build();
920 private Object writeReplace() throws ObjectStreamException {
921 return new InstanceIdentifierV3<>(this);