Merge "Adjusted OVSDB features to enable the Pax-exam tests"
[netvirt.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
27         public static final int size = HandlerType.values().length;
28     }
29     public enum Action { ADD, UPDATE, DELETE }
30
31     private HandlerType handlerType;
32     private Action action;
33
34     private AbstractEvent() {
35         // this is private to force proper construction
36     }
37
38     protected AbstractEvent(HandlerType handlerType, Action action) {
39         this.handlerType = handlerType;
40         this.action = action;
41     }
42
43     public HandlerType getHandlerType() {
44         return handlerType;
45     }
46
47     public Action getAction() {
48         return action;
49     }
50
51     @Override
52     public String toString() {
53         return "AbstractEvent [handlerType=" + handlerType + " action=" + action + "]";
54     }
55
56     @Override
57     public int hashCode() {
58         final int prime = 31;
59         int result = 1;
60         result = prime * result + ((handlerType == null) ? 0 : handlerType.hashCode());
61         result = prime * result + ((action == null) ? 0 : action.hashCode());
62         return result;
63     }
64
65     @Override
66     public boolean equals(Object obj) {
67         if (this == obj)
68             return true;
69         if (obj == null)
70             return false;
71         if (getClass() != obj.getClass())
72             return false;
73         AbstractEvent other = (AbstractEvent) obj;
74         if (handlerType == null) {
75             if (other.handlerType != null)
76                 return false;
77         } else if (!handlerType.equals(other.handlerType))
78             return false;
79         if (action == null) {
80             if (other.action != null)
81                 return false;
82         } else if (!action.equals(other.action))
83             return false;
84         return true;
85     }
86 }