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