+ /**
+ * A builder of {@link InstanceIdentifier} objects.
+ *
+ * @param <T> Instance identifier target type
+ */
+ public abstract static sealed class Builder<T extends DataObject> {
+ private final ImmutableList.Builder<DataObjectStep<?>> pathBuilder;
+ private final HashCodeBuilder<DataObjectStep<?>> hashBuilder;
+ private final Iterable<? extends DataObjectStep<?>> basePath;
+
+ private boolean wildcard;
+
+ Builder(final Builder<?> prev, final DataObjectStep<?> item) {
+ pathBuilder = prev.pathBuilder;
+ hashBuilder = prev.hashBuilder;
+ basePath = prev.basePath;
+ wildcard = prev.wildcard;
+ appendItem(item);
+ }
+
+ Builder(final InstanceIdentifier<T> identifier) {
+ pathBuilder = ImmutableList.builder();
+ hashBuilder = new HashCodeBuilder<>(identifier.hashCode());
+ wildcard = identifier.isWildcarded();
+ basePath = identifier.pathArguments;
+ }
+
+ Builder(final DataObjectStep<?> item, final boolean wildcard) {
+ pathBuilder = ImmutableList.builder();
+ hashBuilder = new HashCodeBuilder<>();
+ basePath = null;
+ hashBuilder.addArgument(item);
+ pathBuilder.add(item);
+ this.wildcard = wildcard;
+ }
+
+ final boolean wildcard() {
+ return wildcard;
+ }
+
+ /**
+ * Build an identifier which refers to a specific augmentation of the current InstanceIdentifier referenced by
+ * the builder.
+ *
+ * @param container augmentation class
+ * @param <N> augmentation type
+ * @return this builder
+ * @throws NullPointerException if {@code container} is null
+ */
+ public final <N extends DataObject & Augmentation<? super T>> Builder<N> augmentation(
+ final Class<N> container) {
+ return append(new NodeStep<>(container));
+ }
+