f6ab7607773c1bb3d990df004ae7c26334695828
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / AbstractNormalizedNodeDataInput.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableList.Builder;
14 import java.io.DataInput;
15 import java.io.IOException;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19
20 abstract class AbstractNormalizedNodeDataInput extends ForwardingDataInput implements NormalizedNodeDataInput {
21     // Visible for subclasses
22     final @NonNull DataInput input;
23
24     AbstractNormalizedNodeDataInput(final DataInput input) {
25         this.input = requireNonNull(input);
26     }
27
28     @Override
29     final DataInput delegate() {
30         return input;
31     }
32
33     @Override
34     public final SchemaPath readSchemaPath() throws IOException {
35         final boolean absolute = input.readBoolean();
36         final int size = input.readInt();
37
38         final Builder<QName> qnames = ImmutableList.builderWithExpectedSize(size);
39         for (int i = 0; i < size; ++i) {
40             qnames.add(readQName());
41         }
42         return SchemaPath.create(qnames.build(), absolute);
43     }
44
45 }