Merge "Fixed possible NPE in CodecMapping."
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / nodes / AbstractImmutableDataContainerNode.java
1 /*
2  * Copyright (c) 2013 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.yangtools.yang.data.impl.schema.nodes;
9
10 import java.util.Map;
11
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
15 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
16
17 import com.google.common.base.Optional;
18
19 public abstract class AbstractImmutableDataContainerNode<K extends PathArgument> //
20         extends AbstractImmutableNormalizedNode<K, Iterable<DataContainerChild<? extends PathArgument, ?>>> //
21         implements Immutable, DataContainerNode<K> {
22
23     protected final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children;
24
25     public AbstractImmutableDataContainerNode(
26             final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children, final K nodeIdentifier) {
27         super(nodeIdentifier, children.values());
28         this.children = children;
29     }
30
31     @Override
32     public final Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
33         return Optional.<DataContainerChild<? extends PathArgument, ?>> fromNullable(children.get(child));
34     }
35
36     @Override
37     public String toString() {
38         final StringBuffer sb = new StringBuffer("ImmutableContainerNode{");
39         sb.append("nodeIdentifier=").append(nodeIdentifier);
40         sb.append(", children=").append(children);
41         sb.append('}');
42         return sb.toString();
43     }
44 }