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;
15 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
18 * @author michal.rehak
21 * @deprecated Use one of the {@link NormalizedNodeBuilder} implementations.
24 public abstract class AbstractNodeTO<T> implements Node<T>, NodeModification {
27 private CompositeNode parent;
29 private ModifyAction modifyAction;
31 // Only for Serialization use
32 public AbstractNodeTO(){
41 public AbstractNodeTO(final QName qname, final CompositeNode parent, final T value) {
42 this(qname, parent, value, null);
51 public AbstractNodeTO(final QName qname, final CompositeNode parent, final T value, final ModifyAction modifyAction) {
55 this.modifyAction = modifyAction;
59 public QName getNodeType() {
66 public QName getQName() {
71 public CompositeNode getParent() {
79 public void setParent(final CompositeNode parent) {
88 public T setValue(final T value) {
89 T oldValue = this.value;
100 * @return modification action
101 * @see NodeModification#getModificationAction()
104 public ModifyAction getModificationAction() {
109 * @param modifyAction
110 * the modifyAction to set
112 protected void setModificationAction(final ModifyAction modifyAction) {
113 this.modifyAction = modifyAction;
117 public String toString() {
118 StringBuffer out = new StringBuffer();
119 out.append(String.format("Node[%s], qName[%s], modify[%s]", getClass().getSimpleName(), getQName()
120 .getLocalName(), getModificationAction() == null ? "n/a" : getModificationAction()));
121 return out.toString();
126 public final QName getKey() {
127 return getNodeType();
132 public int hashCode() {
133 final int prime = 31;
135 result = prime * result + ((qName == null) ? 0 : qName.hashCode());
136 result = prime * result + ((value == null) ? 0 : value.hashCode());
141 public boolean equals(final Object obj) {
148 if (getClass() != obj.getClass()) {
151 @SuppressWarnings("unchecked")
152 AbstractNodeTO<T> other = (AbstractNodeTO<T>) obj;
153 if (parent == null) {
154 if (other.parent != null) {
157 } else if (other.parent == null) {
161 if (other.qName != null) {
164 } else if (!qName.equals(other.qName)) {
168 if (other.value != null) {
171 } else if (!value.equals(other.value)) {
179 //Serialization related
181 protected final void init(final QName qName, final CompositeNode parent, final T value, final ModifyAction modifyAction){
183 this.modifyAction = modifyAction;
184 this.parent = parent;