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;
10 import org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
12 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
13 import org.opendaylight.yangtools.yang.data.api.Node;
14 import org.opendaylight.yangtools.yang.data.api.NodeModification;
17 * @author michal.rehak
22 public abstract class AbstractNodeTO<T> implements Node<T>, NodeModification {
25 private CompositeNode parent;
27 private ModifyAction modifyAction;
34 public AbstractNodeTO(QName qname, CompositeNode parent, T value) {
46 public AbstractNodeTO(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) {
50 this.modifyAction = modifyAction;
54 public QName getNodeType() {
61 public QName getQName() {
66 public CompositeNode getParent() {
74 public void setParent(CompositeNode parent) {
82 protected void setValue(T value) {
92 * @return modification action
93 * @see org.opendaylight.yangtools.yang.data.impl.NodeModificationSupport#getModificationAction()
96 public ModifyAction getModificationAction() {
101 * @param modifyAction
102 * the modifyAction to set
104 protected void setModificationAction(ModifyAction modifyAction) {
105 this.modifyAction = modifyAction;
109 public String toString() {
110 StringBuffer out = new StringBuffer();
111 out.append(String.format("Node[%s], qName[%s], modify[%s]", getClass().getSimpleName(), getQName()
112 .getLocalName(), getModificationAction() == null ? "n/a" : getModificationAction()));
113 return out.toString();
118 public int hashCode() {
119 final int prime = 31;
121 result = prime * result + ((modifyAction == null) ? 0 : modifyAction.hashCode());
122 result = prime * result + ((qName == null) ? 0 : qName.hashCode());
123 result = prime * result + ((value == null) ? 0 : value.hashCode());
128 public boolean equals(Object obj) {
135 if (getClass() != obj.getClass()) {
138 @SuppressWarnings("unchecked")
139 AbstractNodeTO<T> other = (AbstractNodeTO<T>) obj;
140 if (modifyAction != other.modifyAction) {
143 if (parent == null) {
144 if (other.parent != null) {
147 } else if (other.parent == null) {
151 if (other.qName != null) {
154 } else if (!qName.equals(other.qName)) {
158 if (other.value != null) {
161 } else if (!value.equals(other.value)) {