2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.impl.schema;
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.concepts.Mutable;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedMetadata;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedMountpoints;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizationResult;
21 * Client-allocated result holder for {@link ImmutableNormalizedNodeStreamWriter} operation. The operation can result
22 * in multiple distinct, but related items, to be produced -- as captured by {@link NormalizationResult}.
24 public final class NormalizationResultHolder implements Mutable {
25 private NormalizedNode data;
26 private NormalizedMetadata metadata;
27 private NormalizedMountpoints mountPoints;
29 public @Nullable NormalizationResult result() {
30 final var localData = data;
31 return localData == null ? null : new NormalizationResult(localData, metadata, mountPoints);
34 public @NonNull NormalizationResult getResult() {
35 final var localData = data;
36 if (localData == null) {
37 throw new IllegalStateException("Holder " + this + " has not been completed");
39 return new NormalizationResult(localData, metadata, mountPoints);
42 void setData(final NormalizedNode data) {
43 if (this.data != null) {
44 throw new ResultAlreadySetException("Normalized Node result was already set.", this.data);
46 this.data = requireNonNull(data);
49 void setMetadata(final NormalizedMetadata metadata) {
50 this.metadata = metadata;
53 void setMountPoints(final NormalizedMountpoints mountPoints) {
54 this.mountPoints = mountPoints;