Switch to Objects.requireNonNull
[mdsal.git] / binding2 / mdsal-binding2-dom-codec / src / main / java / org / opendaylight / mdsal / binding / javav2 / dom / codec / generator / spi / source / AbstractAugmentSerializerSource.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. 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.mdsal.binding.javav2.dom.codec.generator.spi.source;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.spi.generator.AbstractGenerator;
16 import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedType;
17 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 @Beta
23 public abstract class AbstractAugmentSerializerSource extends AbstractDataNodeContainerSerializerSource {
24
25     private static final Logger LOG = LoggerFactory.getLogger(AbstractAugmentSerializerSource.class);
26     private final Collection<AugmentationSchemaNode> augmentationSchemas;
27
28     public AbstractAugmentSerializerSource(final AbstractGenerator generator, final GeneratedType type,
29                                            final Collection<AugmentationSchemaNode> augmentationSchemas) {
30         // Note: passing first augmentation schema node just to avoid exceptions from super class.
31         super(generator, type, augmentationSchemas.stream().findFirst().get());
32         this.augmentationSchemas = requireNonNull(augmentationSchemas);
33     }
34
35     /**
36      * Override {@link AbstractDataNodeContainerSerializerSource#getChildNodes()} to get all children nodes
37      * of same target augmentation schema nodes.
38      */
39     @Override
40     protected Collection<DataSchemaNode> getChildNodes() {
41         Collection<DataSchemaNode> childNodes = new ArrayList<>();
42         for (AugmentationSchemaNode schema : this.augmentationSchemas) {
43             childNodes.addAll(schema.getChildNodes());
44         }
45         return childNodes;
46     }
47
48 }