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