Bug 4160 - null pointer exception in getDHCPServerPort() (re-do)
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / AbstractEvent.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt;
10
11 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
12
13 /**
14  * Abstract class for events used by neutron northbound and southbound events.
15  */
16 public abstract class AbstractEvent {
17
18     public enum HandlerType {
19         SOUTHBOUND,
20         NEUTRON_FLOATING_IP,
21         NEUTRON_NETWORK,
22         NEUTRON_PORT,
23         NEUTRON_PORT_SECURITY,
24         NEUTRON_ROUTER,
25         NEUTRON_SUBNET,
26         NEUTRON_FWAAS,
27         NEUTRON_LOAD_BALANCER,
28         NEUTRON_LOAD_BALANCER_POOL,
29         NEUTRON_LOAD_BALANCER_POOL_MEMBER,
30         NODE;
31
32         public static final int size = HandlerType.values().length;
33     }
34
35     private HandlerType handlerType;
36     private Action action;
37
38     private AbstractEvent() {
39         // this is private to force proper construction
40     }
41
42     protected AbstractEvent(HandlerType handlerType, Action action) {
43         this.handlerType = handlerType;
44         this.action = action;
45     }
46
47     public HandlerType getHandlerType() {
48         return handlerType;
49     }
50
51     public Action getAction() {
52         return action;
53     }
54
55     @Override
56     public String toString() {
57         return "AbstractEvent [handlerType=" + handlerType + " action=" + action + "]";
58     }
59
60     @Override
61     public int hashCode() {
62         final int prime = 31;
63         int result = 1;
64         result = prime * result + ((handlerType == null) ? 0 : handlerType.hashCode());
65         result = prime * result + ((action == null) ? 0 : action.hashCode());
66         return result;
67     }
68
69     @Override
70     public boolean equals(Object obj) {
71         if (this == obj) {
72             return true;
73         }
74         if (obj == null) {
75             return false;
76         }
77         if (getClass() != obj.getClass()) {
78             return false;
79         }
80         AbstractEvent other = (AbstractEvent) obj;
81         if (handlerType == null) {
82             if (other.handlerType != null) {
83                 return false;
84             }
85         } else if (!handlerType.equals(other.handlerType)) {
86             return false;
87         }
88         if (action == null) {
89             if (other.action != null) {
90                 return false;
91             }
92         } else if (!action.equals(other.action)) {
93             return false;
94         }
95         return true;
96     }
97 }