2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.yang.data.impl;
\r
10 import org.opendaylight.controller.yang.common.QName;
\r
11 import org.opendaylight.controller.yang.data.api.CompositeNode;
\r
12 import org.opendaylight.controller.yang.data.api.ModifyAction;
\r
13 import org.opendaylight.controller.yang.data.api.Node;
\r
14 import org.opendaylight.controller.yang.data.api.NodeModification;
\r
17 * @author michal.rehak
\r
19 * type of node value
\r
22 public abstract class AbstractNodeTO<T> implements Node<T>, NodeModification {
\r
24 private QName qName;
\r
25 private CompositeNode parent;
\r
27 private ModifyAction modifyAction;
\r
34 public AbstractNodeTO(QName qname, CompositeNode parent, T value) {
\r
36 this.parent = parent;
\r
44 * @param modifyAction
\r
46 public AbstractNodeTO(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) {
\r
48 this.parent = parent;
\r
50 this.modifyAction = modifyAction;
\r
54 public QName getNodeType() {
\r
61 public QName getQName() {
\r
66 public CompositeNode getParent() {
\r
71 * @param parent the parent to set
\r
73 public void setParent(CompositeNode parent) {
\r
74 this.parent = parent;
\r
78 * @param value the value to set
\r
80 protected void setValue(T value) {
\r
85 public T getValue() {
\r
90 * @return modification action
\r
91 * @see org.opendaylight.controller.yang.data.impl.NodeModificationSupport#getModificationAction()
\r
94 public ModifyAction getModificationAction() {
\r
95 return modifyAction;
\r
99 * @param modifyAction
\r
100 * the modifyAction to set
\r
102 protected void setModificationAction(ModifyAction modifyAction) {
\r
103 this.modifyAction = modifyAction;
\r
107 public String toString() {
\r
108 StringBuffer out = new StringBuffer();
\r
109 out.append(String.format("Node[%s], qName[%s], modify[%s]",
\r
110 getClass().getSimpleName(), getQName().getLocalName(),
\r
111 getModificationAction() == null ? "n/a" : getModificationAction()));
\r
112 return out.toString();
\r
117 public int hashCode() {
\r
118 final int prime = 31;
\r
120 result = prime * result
\r
121 + ((modifyAction == null) ? 0 : modifyAction.hashCode());
\r
122 // result = prime * result + ((parent == null) ? 0 : parent.hashCode());
\r
123 result = prime * result + ((qName == null) ? 0 : qName.hashCode());
\r
124 result = prime * result + ((value == null) ? 0 : value.hashCode());
\r
129 public boolean equals(Object obj) {
\r
134 if (getClass() != obj.getClass())
\r
136 @SuppressWarnings("unchecked")
\r
137 AbstractNodeTO<T> other = (AbstractNodeTO<T>) obj;
\r
138 if (modifyAction != other.modifyAction)
\r
140 if (parent == null) {
\r
141 if (other.parent != null)
\r
143 } else if (other.parent == null) {
\r
146 if (qName == null) {
\r
147 if (other.qName != null)
\r
149 } else if (!qName.equals(other.qName))
\r
151 if (value == null) {
\r
152 if (other.value != null)
\r
154 } else if (!value.equals(other.value))
\r