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