HONEYCOMB-331: unify initialization handling
[honeycomb.git] / infra / translate-api / src / main / java / io / fd / honeycomb / translate / read / ListReader.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.translate.read;
18
19 import com.google.common.annotations.Beta;
20 import java.util.Collections;
21 import java.util.List;
22 import javax.annotation.Nonnull;
23 import org.opendaylight.yangtools.concepts.Builder;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.Identifiable;
26 import org.opendaylight.yangtools.yang.binding.Identifier;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 /**
30  * List reader, allowing read of all the elements.
31  *
32  * @param <D> Specific DataObject derived type, that is handled by this reader
33  */
34 @Beta
35 public interface ListReader
36         <D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>> extends Reader<D, B> {
37
38     /**
39      * Read all elements in this list.
40      *
41      * @param id Wildcarded identifier of list managed by this reader
42      * @param ctx Read context
43      *
44      * @return List of all entries in this list
45      * @throws ReadFailedException if read was unsuccessful
46      */
47     @Nonnull
48     List<D> readList(@Nonnull final InstanceIdentifier<D> id, @Nonnull final ReadContext ctx)
49             throws ReadFailedException;
50
51     /**
52      * Get IDs for all entries in the list.
53      */
54     List<K> getAllIds(@Nonnull InstanceIdentifier<D> id, @Nonnull ReadContext ctx)
55             throws ReadFailedException;
56
57     /**
58      * Merge read data into provided parent builder.
59      */
60     void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<D> readData);
61
62     @Override
63     default void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final D readValue) {
64         merge(parentBuilder, Collections.singletonList(readValue));
65     }
66 }