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;
29 // Only for Serialization use
30 public AbstractNodeTO(){
39 public AbstractNodeTO(QName qname, CompositeNode parent, T value) {
51 public AbstractNodeTO(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) {
55 this.modifyAction = modifyAction;
59 public QName getNodeType() {
66 public QName getQName() {
71 public CompositeNode getParent() {
79 public void setParent(CompositeNode parent) {
87 public T setValue(T value) {
88 T oldValue = this.value;
99 * @return modification action
100 * @see NodeModification#getModificationAction()
103 public ModifyAction getModificationAction() {
108 * @param modifyAction
109 * the modifyAction to set
111 protected void setModificationAction(ModifyAction modifyAction) {
112 this.modifyAction = modifyAction;
116 public String toString() {
117 StringBuffer out = new StringBuffer();
118 out.append(String.format("Node[%s], qName[%s], modify[%s]", getClass().getSimpleName(), getQName()
119 .getLocalName(), getModificationAction() == null ? "n/a" : getModificationAction()));
120 return out.toString();
125 public final QName getKey() {
126 return getNodeType();
131 public int hashCode() {
132 final int prime = 31;
134 result = prime * result + ((modifyAction == null) ? 0 : modifyAction.hashCode());
135 result = prime * result + ((qName == null) ? 0 : qName.hashCode());
136 result = prime * result + ((value == null) ? 0 : value.hashCode());
141 public boolean equals(Object obj) {
148 if (getClass() != obj.getClass()) {
151 @SuppressWarnings("unchecked")
152 AbstractNodeTO<T> other = (AbstractNodeTO<T>) obj;
153 if (modifyAction != other.modifyAction) {
156 if (parent == null) {
157 if (other.parent != null) {
160 } else if (other.parent == null) {
164 if (other.qName != null) {
167 } else if (!qName.equals(other.qName)) {
171 if (other.value != null) {
174 } else if (!value.equals(other.value)) {
182 //Serialization related
184 protected final void init(QName qName, CompositeNode parent, T value, ModifyAction modifyAction){
186 this.modifyAction = modifyAction;
187 this.parent = parent;