org.onos.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode.java Source code

Java tutorial

Introduction

Here is the source code for org.onos.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode.java

Source

/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.onos.yangtools.yang.data.impl.schema.nodes;

import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.onos.yangtools.yang.common.QName;
import org.onos.yangtools.yang.data.api.AttributesContainer;
import org.onos.yangtools.yang.data.api.YangInstanceIdentifier;

public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangInstanceIdentifier.PathArgument, V>
        extends AbstractImmutableNormalizedValueNode<K, V> implements AttributesContainer {

    private final Map<QName, String> attributes;

    protected AbstractImmutableNormalizedValueAttrNode(final K nodeIdentifier, final V value,
            final Map<QName, String> attributes) {
        super(nodeIdentifier, value);
        this.attributes = ImmutableMap.copyOf(attributes);
    }

    @Override
    public final Map<QName, String> getAttributes() {
        return attributes;
    }

    @Override
    public final Object getAttributeValue(final QName value) {
        return attributes.get(value);
    }

    @Override
    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
        return super.addToStringAttributes(toStringHelper).add("attributes", attributes);
    }

    @Override
    protected int valueHashCode() {
        final int result = getValue() != null ? getValue().hashCode() : 1;
        // FIXME: are attributes part of hashCode/equals?
        //        for (final Entry<?, ?> a : attributes.entrySet()) {
        //            result = 31 * result + a.hashCode();
        //        }
        return result;
    }

    @Override
    protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
        // We can not call directly getValue.equals because of Empty Type
        // Definition leaves which allways have NULL value

        if (!java.util.Objects.deepEquals(getValue(), other.getValue())) {
            return false;
        }

        // FIXME: are attributes part of hashCode/equals?
        // final Set<Entry<QName, String>> tas = getAttributes().entrySet();
        // final Set<Entry<QName, String>> oas =
        // container.getAttributes().entrySet();
        //
        // return tas.containsAll(oas) && oas.containsAll(tas);
        return true;
    }

}