Revert Merge "Bug 2366: new parser - Types & TypeDefs"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / nodes / AbstractImmutableNormalizedValueAttrNode.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.MoreObjects.ToStringHelper;
11 import com.google.common.collect.ImmutableMap;
12 import java.util.Map;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16
17 public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangInstanceIdentifier.PathArgument,V>
18         extends AbstractImmutableNormalizedValueNode<K, V>
19         implements AttributesContainer {
20
21     private final Map<QName, String> attributes;
22
23     protected AbstractImmutableNormalizedValueAttrNode(final K nodeIdentifier, final V value, final Map<QName, String> attributes) {
24         super(nodeIdentifier, value);
25         this.attributes = ImmutableMap.copyOf(attributes);
26     }
27
28     @Override
29     public final Map<QName, String> getAttributes() {
30         return attributes;
31     }
32
33     @Override
34     public final Object getAttributeValue(final QName value) {
35         return attributes.get(value);
36     }
37
38     @Override
39     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
40         return super.addToStringAttributes(toStringHelper).add("attributes", attributes);
41     }
42
43     @Override
44     protected int valueHashCode() {
45         final int result = getValue() != null ? getValue().hashCode() : 1;
46 // FIXME: are attributes part of hashCode/equals?
47 //        for (final Entry<?, ?> a : attributes.entrySet()) {
48 //            result = 31 * result + a.hashCode();
49 //        }
50         return result;
51     }
52
53     @Override
54     protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
55         // We can not call directly getValue.equals because of Empty Type
56         // Definition leaves which allways have NULL value
57
58         if (!java.util.Objects.deepEquals(getValue(), other.getValue())) {
59             return false;
60         }
61
62         // FIXME: are attributes part of hashCode/equals?
63         // final Set<Entry<QName, String>> tas = getAttributes().entrySet();
64         // final Set<Entry<QName, String>> oas =
65         // container.getAttributes().entrySet();
66         //
67         // return tas.containsAll(oas) && oas.containsAll(tas);
68         return true;
69     }
70
71 }