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.*;
14 * @author michal.rehak
19 public abstract class AbstractNodeTO<T> implements Node<T>, NodeModification {
22 private CompositeNode parent;
24 private ModifyAction modifyAction;
26 // Only for Serialization use
27 public AbstractNodeTO(){
36 public AbstractNodeTO(QName qname, CompositeNode parent, T value) {
37 this(qname, parent, value, null);
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 public T setValue(T value) {
83 T oldValue = this.value;
94 * @return modification action
95 * @see NodeModification#getModificationAction()
98 public ModifyAction getModificationAction() {
103 * @param modifyAction
104 * the modifyAction to set
106 protected void setModificationAction(ModifyAction modifyAction) {
107 this.modifyAction = modifyAction;
111 public String toString() {
112 StringBuffer out = new StringBuffer();
113 out.append(String.format("Node[%s], qName[%s], modify[%s]", getClass().getSimpleName(), getQName()
114 .getLocalName(), getModificationAction() == null ? "n/a" : getModificationAction()));
115 return out.toString();
120 public final QName getKey() {
121 return getNodeType();
126 public int hashCode() {
127 final int prime = 31;
129 result = prime * result + ((qName == null) ? 0 : qName.hashCode());
130 result = prime * result + ((value == null) ? 0 : value.hashCode());
135 public boolean equals(Object obj) {
142 if (getClass() != obj.getClass()) {
145 @SuppressWarnings("unchecked")
146 AbstractNodeTO<T> other = (AbstractNodeTO<T>) obj;
147 if (parent == null) {
148 if (other.parent != null) {
151 } else if (other.parent == null) {
155 if (other.qName != null) {
158 } else if (!qName.equals(other.qName)) {
162 if (other.value != null) {
165 } else if (!value.equals(other.value)) {
173 //Serialization related
175 protected final void init(QName qName, CompositeNode parent, T value, ModifyAction modifyAction){
177 this.modifyAction = modifyAction;
178 this.parent = parent;