63dcaeee0db2be403ddb3bef7f6399d755061e41
[onosfw.git] /
1 /*
2  * Copyright 2015 Open Networking Laboratory
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onosproject.vtnrsc.event;
17
18 import java.util.Objects;
19
20 import org.onosproject.vtnrsc.FloatingIp;
21 import org.onosproject.vtnrsc.Router;
22 import org.onosproject.vtnrsc.RouterInterface;
23
24 import static com.google.common.base.MoreObjects.toStringHelper;
25 import static com.google.common.base.Preconditions.checkNotNull;
26
27 /**
28  * Representation of a VtnRsc event feedback.
29  */
30 public class VtnRscEventFeedback {
31     private final FloatingIp floaingtIp;
32     private final Router router;
33     private final RouterInterface routerInterface;
34
35     /**
36      * Creates VtnRscEventFeedback object.
37      *
38      * @param floatingIp the floating Ip
39      */
40     public VtnRscEventFeedback(FloatingIp floatingIp) {
41         this.floaingtIp = checkNotNull(floatingIp, "floaintIp cannot be null");
42         this.router = null;
43         this.routerInterface = null;
44     }
45
46     /**
47      * Creates VtnRscEventFeedback object.
48      *
49      * @param router the router
50      */
51     public VtnRscEventFeedback(Router router) {
52         this.floaingtIp = null;
53         this.router = checkNotNull(router, "router cannot be null");
54         this.routerInterface = null;
55     }
56
57     /**
58      * Creates VtnRscEventFeedback object.
59      *
60      * @param routerInterface the router interface
61      */
62     public VtnRscEventFeedback(RouterInterface routerInterface) {
63         this.floaingtIp = null;
64         this.router = null;
65         this.routerInterface = checkNotNull(routerInterface,
66                                             "routerInterface cannot be null");
67     }
68
69     /**
70      * Returns floating IP.
71      *
72      * @return floaingtIp the floating IP
73      */
74     public FloatingIp floatingIp() {
75         return floaingtIp;
76     }
77
78     /**
79      * Returns router.
80      *
81      * @return router the router
82      */
83     public Router router() {
84         return router;
85     }
86
87     /**
88      * Returns router interface.
89      *
90      * @return routerInterface the router interface
91      */
92     public RouterInterface routerInterface() {
93         return routerInterface;
94     }
95
96     @Override
97     public int hashCode() {
98         return Objects.hash(floaingtIp, router, routerInterface);
99     }
100
101     @Override
102     public boolean equals(Object obj) {
103         if (this == obj) {
104             return true;
105         }
106         if (obj instanceof VtnRscEventFeedback) {
107             final VtnRscEventFeedback that = (VtnRscEventFeedback) obj;
108             return Objects.equals(this.floaingtIp, that.floaingtIp)
109                     && Objects.equals(this.router, that.router)
110                     && Objects.equals(this.routerInterface, that.routerInterface);
111         }
112         return false;
113     }
114
115     @Override
116     public String toString() {
117         return toStringHelper(this)
118                 .add("router", router)
119                 .add("floaingtIp", floaingtIp)
120                 .add("routerInterface", routerInterface)
121                 .toString();
122     }
123 }