2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import com.google.common.collect.ImmutableMap;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 public abstract class AbstractImmutableNormalizedValueAttrNode<K extends PathArgument,V>
19 extends AbstractImmutableNormalizedValueNode<K, V>
20 implements AttributesContainer {
22 private final Map<QName, String> attributes;
24 protected AbstractImmutableNormalizedValueAttrNode(final K nodeIdentifier, final V value,
25 final Map<QName, String> attributes) {
26 super(nodeIdentifier, value);
27 this.attributes = ImmutableMap.copyOf(attributes);
31 public final Map<QName, String> getAttributes() {
36 public final Object getAttributeValue(final QName value) {
37 return attributes.get(value);
41 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
42 return super.addToStringAttributes(toStringHelper).add("attributes", attributes);
46 protected int valueHashCode() {
47 final V local = value();
48 final int result = local != null ? local.hashCode() : 1;
49 // FIXME: are attributes part of hashCode/equals?
54 protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
55 // We can not call directly getValue.equals because of Empty Type
56 // RequireInstanceStatementSupport leaves which always have NULL value
58 // FIXME: are attributes part of hashCode/equals?
59 return Objects.deepEquals(value(), other.getValue());