BUG-1092: rename data.api.InstanceIdentifier to YangInstanceIdentifier
[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 java.util.Map;
11
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15
16 import com.google.common.base.Objects.ToStringHelper;
17 import com.google.common.collect.ImmutableMap;
18
19 public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangInstanceIdentifier.PathArgument,V>
20         extends AbstractImmutableNormalizedValueNode<K, V>
21         implements AttributesContainer {
22
23     private final Map<QName, String> attributes;
24
25     protected AbstractImmutableNormalizedValueAttrNode(final K nodeIdentifier, final V value, final Map<QName, String> attributes) {
26         super(nodeIdentifier, value);
27         this.attributes = ImmutableMap.copyOf(attributes);
28     }
29
30     @Override
31     public final Map<QName, String> getAttributes() {
32         return attributes;
33     }
34
35     @Override
36     public final Object getAttributeValue(final QName value) {
37         return attributes.get(value);
38     }
39
40     @Override
41     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
42         return super.addToStringAttributes(toStringHelper).add("attributes", attributes);
43     }
44
45     @Override
46     protected int valueHashCode() {
47         final int result = getValue().hashCode();
48 // FIXME: are attributes part of hashCode/equals?
49 //        for (final Entry<?, ?> a : attributes.entrySet()) {
50 //            result = 31 * result + a.hashCode();
51 //        }
52         return result;
53     }
54
55     @Override
56     protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
57         if (!getValue().equals(other.getValue())) {
58             return false;
59         }
60
61 // FIXME: are attributes part of hashCode/equals?
62 //        final Set<Entry<QName, String>> tas = getAttributes().entrySet();
63 //        final Set<Entry<QName, String>> oas = container.getAttributes().entrySet();
64 //
65 //        return tas.containsAll(oas) && oas.containsAll(tas);
66         return true;
67     }
68 }