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.data.spi.node.impl;
10 import static java.util.Objects.requireNonNull;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
19 abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode>
20 implements NormalizedNodeBuilder<I, V, R> {
21 private @Nullable I nodeIdentifier = null;
22 private @Nullable V value = null;
24 protected final I getNodeIdentifier() {
25 return checkSet(nodeIdentifier, "Identifier has not been set");
28 protected final V getValue() {
29 return checkSet(value, "Value has not been set");
33 public NormalizedNodeBuilder<I, V, R> withValue(final V withValue) {
34 this.value = checkValue(withValue);
39 public NormalizedNodeBuilder<I, V, R> withNodeIdentifier(final I withNodeIdentifier) {
40 this.nodeIdentifier = requireNonNull(withNodeIdentifier);
44 private static <T> @NonNull T checkSet(final @Nullable T obj, final String message) {
46 throw new IllegalStateException(message);
51 protected static final <T> @NonNull T checkValue(final @Nullable T value) {
52 final var nonNull = requireNonNull(value);
53 if (nonNull instanceof YangInstanceIdentifier yiid && yiid.isEmpty()) {
54 throw new IllegalArgumentException("Node value cannot be an empty instance identifier");