Merge "Bug 1372 - toString methods in generated classes"
[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 com.google.common.base.Optional;
11
12 import java.util.Collections;
13 import java.util.Map;
14
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
18 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
19
20 public abstract class AbstractImmutableDataContainerNode<K extends PathArgument> extends AbstractImmutableNormalizedNode<K, Iterable<DataContainerChild<? extends PathArgument, ?>>>
21 implements Immutable, DataContainerNode<K> {
22
23     protected final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children;
24     private final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> publicChildren;
25
26     public AbstractImmutableDataContainerNode(
27             final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children, final K nodeIdentifier) {
28         super(nodeIdentifier);
29         this.children = children;
30         this.publicChildren = Collections.unmodifiableMap(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     public final Iterable<DataContainerChild<? extends PathArgument, ?>> getValue() {
40         return publicChildren.values();
41     }
42
43     @Override
44     protected int valueHashCode() {
45         return children.hashCode();
46     }
47
48     public final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> getChildren() {
49         return publicChildren;
50     }
51
52     @Override
53     protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
54         if (!(other instanceof AbstractImmutableDataContainerNode<?>)) {
55             return false;
56         }
57
58         return children.equals(((AbstractImmutableDataContainerNode<?>)other).children);
59     }
60 }