Fix toString for different events to avoid NPE
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / SouthboundEvent.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
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
7  *
8  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.openstack.netvirt;
11
12 import org.opendaylight.ovsdb.lib.notation.Row;
13 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
15
16 public class SouthboundEvent extends AbstractEvent {
17     public enum Type { NODE, ROW }
18     private Type type;
19     private Node node;
20     private String tableName;
21     private String uuid;
22     private Row row;
23     private Object context;
24     public SouthboundEvent(Node node, Action action) {
25         super(HandlerType.SOUTHBOUND, action);
26         this.type = Type.NODE;
27         this.node = node;
28     }
29     public SouthboundEvent(Node node, String tableName, String uuid, Row row, Action action) {
30         super(HandlerType.SOUTHBOUND, action);
31         this.type = Type.ROW;
32         this.node = node;
33         this.tableName = tableName;
34         this.uuid = uuid;
35         this.row = row;
36     }
37     public SouthboundEvent(Node node, String tableName, String uuid, Row row, Object context, Action action) {
38         super(HandlerType.SOUTHBOUND, action);
39         this.type = Type.ROW;
40         this.node = node;
41         this.tableName = tableName;
42         this.uuid = uuid;
43         this.row = row;
44         this.context = context;
45     }
46     public Type getType() {
47         return type;
48     }
49     public Node getNode() {
50         return node;
51     }
52     public String getTableName() {
53         return tableName;
54     }
55     public String getUuid() {
56         return uuid;
57     }
58     public Row getRow() {
59         return row;
60     }
61     public Object getContext() {
62         return context;
63     }
64     @Override
65     public String toString() {
66         if (type == Type.NODE) {
67             return "SouthboundEvent [type=" + type
68                     + ", action=" + super.getAction()
69                     + ", node=" + node + "]";
70         } else if (type == Type.ROW) {
71             return "SouthboundEvent [type=" + type
72                     + ", action=" + super.getAction()
73                     + ", node=" + node
74                     + ", tableName=" + tableName
75                     + ", uuid=" + uuid
76                     + ", row=" + row
77                     + ", context=" + context + "]";
78         } else {
79             return "SouthboundEvent [type=" + type + "]";
80         }
81     }
82
83     @Override
84     public int hashCode() {
85         final int prime = 31;
86         int result = super.hashCode();
87         result = prime * result + ((node == null) ? 0 : node.hashCode());
88         result = prime * result + ((tableName == null) ? 0 : tableName.hashCode());
89         result = prime * result + ((type == null) ? 0 : type.hashCode());
90         result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
91         return result;
92     }
93     @Override
94     public boolean equals(Object obj) {
95         if (this == obj) {
96             return true;
97         }
98         if (obj == null) {
99             return false;
100         }
101         if (getClass() != obj.getClass()) {
102             return false;
103         }
104         if (!super.equals(obj)) {
105             return false;
106         }
107         SouthboundEvent other = (SouthboundEvent) obj;
108         if (node == null) {
109             if (other.node != null) {
110                 return false;
111             }
112         } else if (!node.equals(other.node)) {
113             return false;
114         }
115         if (tableName == null) {
116             if (other.tableName != null) {
117                 return false;
118             }
119         } else if (!tableName.equals(other.tableName)) {
120             return false;
121         }
122         if (type == null) {
123             if (other.type != null) {
124                 return false;
125             }
126         } else if (!type.equals(other.type)) {
127             return false;
128         }
129         if (uuid == null) {
130             if (other.uuid != null) {
131                 return false;
132             }
133         } else if (!uuid.equals(other.uuid)) {
134             return false;
135         }
136         return true;
137     }
138 }