2 * Copyright (c) 2019 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.util;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import java.io.IOException;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.opendaylight.yangtools.yang.data.api.schema.MetadataNormalizedAnydata;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedMetadata;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference;
24 public final class ImmutableMetadataNormalizedAnydata extends ImmutableNormalizedAnydata
25 implements MetadataNormalizedAnydata {
26 private final NormalizedMetadata metadata;
28 public ImmutableMetadataNormalizedAnydata(final EffectiveStatementInference inference, final NormalizedNode data,
29 final NormalizedMetadata metadata) {
30 super(inference, data);
31 this.metadata = requireNonNull(metadata);
34 public static ImmutableNormalizedAnydata ofOptional(final EffectiveStatementInference inference,
35 final NormalizedNode data, final Optional<NormalizedMetadata> metadata) {
36 return metadata.isPresent()
37 ? new ImmutableMetadataNormalizedAnydata(inference, data, metadata.get())
38 : new ImmutableNormalizedAnydata(inference, data);
42 public NormalizedMetadata getMetadata() {
47 public void writeTo(final NormalizedNodeStreamWriter writer, final boolean orderKeyLeaves) throws IOException {
48 NormalizedMetadataWriter.forStreamWriter(writer, orderKeyLeaves).write(getData(), getMetadata()).flush();