Remove YangInstanceIdentifier.EMPTY
[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.Collection;
11 import java.util.Map;
12 import java.util.Optional;
13 import org.opendaylight.yangtools.util.ImmutableOffsetMap;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
16 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
17
18 public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
19         extends AbstractImmutableNormalizedNode<K, Collection<DataContainerChild<? extends PathArgument, ?>>>
20         implements DataContainerNode<K> {
21     private final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children;
22
23     public AbstractImmutableDataContainerNode(
24             final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children, final K nodeIdentifier) {
25         super(nodeIdentifier);
26
27         this.children = ImmutableOffsetMap.unorderedCopyOf(children);
28     }
29
30     @Override
31     public final Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
32         return Optional.ofNullable(children.get(child));
33     }
34
35     @Override
36     public final Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
37         return children.values();
38     }
39
40     @Override
41     protected int valueHashCode() {
42         return children.hashCode();
43     }
44
45     /**
46      * DO NOT USE THIS METHOD.
47      *
48      * <p>
49      * This is an implementation-internal API and no outside users should use it. If you do,
50      * you are asking for trouble, as the returned object is not guaranteed to conform to
51      * java.util.Map interface.
52      *
53      * @return An unmodifiable view if this node's children.
54      */
55     public final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> getChildren() {
56         return children;
57     }
58
59     @Override
60     protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
61         return other instanceof AbstractImmutableDataContainerNode<?> && children.equals(
62                 ((AbstractImmutableDataContainerNode<?>) other).children);
63
64     }
65 }