Merge "Bug 447 - Yang documentation generator improvements"
[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.Collections;
11 import java.util.Map;
12
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
16 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
17
18 import com.google.common.base.Optional;
19 import com.google.common.collect.Iterables;
20
21 public abstract class AbstractImmutableDataContainerNode<K extends PathArgument> //
22         extends AbstractImmutableNormalizedNode<K, Iterable<DataContainerChild<? extends PathArgument, ?>>> //
23         implements Immutable, DataContainerNode<K> {
24
25     protected final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children;
26
27     public AbstractImmutableDataContainerNode(
28             final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children, final K nodeIdentifier) {
29         super(nodeIdentifier, Iterables.unmodifiableIterable(children.values()));
30         this.children = children;
31     }
32
33     @Override
34     public final Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
35         return Optional.<DataContainerChild<? extends PathArgument, ?>> fromNullable(children.get(child));
36     }
37
38     @Override
39     protected int valueHashCode() {
40         return children.hashCode();
41     }
42
43     public final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> getChildren() {
44         // Make sure we do not leak a mutable view
45         return Collections.unmodifiableMap(children);
46     }
47
48     @Override
49     protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
50         if (!(other instanceof AbstractImmutableDataContainerNode<?>)) {
51             return false;
52         }
53
54         return children.equals(((AbstractImmutableDataContainerNode<?>)other).children);
55     }
56 }