Merge "BUG 2509 : Removing all journal entries from a Followers in-memory journal...
[controller.git] / opendaylight / adsal / hosttracker_new / api / src / main / java / org / opendaylight / controller / hosttracker / SwitchPort.java
1 /*
2  * Copyright (c) 2012 Big Switch Networks, Inc.
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the
5  * "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/legal/epl-v10.html
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
13  * implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  *
16  * This file incorporates work covered by the following copyright and
17  * permission notice:
18  *
19  *    Originally created by David Erickson, Stanford University
20  *
21  *    Licensed under the Apache License, Version 2.0 (the "License");
22  *    you may not use this file except in compliance with the
23  *    License. You may obtain a copy of the License at
24  *
25  *         http://www.apache.org/licenses/LICENSE-2.0
26  *
27  *    Unless required by applicable law or agreed to in writing,
28  *    software distributed under the License is distributed on an "AS
29  *    IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
30  *    express or implied. See the License for the specific language
31  *    governing permissions and limitations under the License.
32  */
33
34 package org.opendaylight.controller.hosttracker;
35
36 import org.opendaylight.controller.sal.core.NodeConnector;
37
38 /**
39  * A simple switch DPID/port pair This class is immutable
40  *
41  * @author readams
42  *
43  */
44 public class SwitchPort {
45     public enum ErrorStatus {
46         DUPLICATE_DEVICE("duplicate-device");
47
48         private String value;
49
50         ErrorStatus(String v) {
51             value = v;
52         }
53
54         @Override
55         public String toString() {
56             return value;
57         }
58
59         public static ErrorStatus fromString(String str) {
60             for (ErrorStatus m : ErrorStatus.values()) {
61                 if (m.value.equals(str)) {
62                     return m;
63                 }
64             }
65             return null;
66         }
67     }
68
69     private final NodeConnector port;
70     private final ErrorStatus errorStatus;
71
72     /**
73      * Simple constructor
74      *
75      * @param switchDPID
76      *            the dpid
77      * @param port
78      *            the port
79      * @param errorStatus
80      *            any error status for the switch port
81      */
82     public SwitchPort(NodeConnector port, ErrorStatus errorStatus) {
83         super();
84         this.port = port;
85         this.errorStatus = errorStatus;
86     }
87
88     /**
89      * Simple constructor
90      *
91      * @param switchDPID
92      *            the dpid
93      * @param port
94      *            the port
95      */
96     public SwitchPort(NodeConnector port) {
97         super();
98         this.port = port;
99         this.errorStatus = null;
100     }
101
102     // ***************
103     // Getters/Setters
104     // ***************
105
106     public NodeConnector getPort() {
107         return port;
108     }
109
110     public ErrorStatus getErrorStatus() {
111         return errorStatus;
112     }
113
114     // ******
115     // Object
116     // ******
117
118     @Override
119     public int hashCode() {
120         final int prime = 31;
121         int result = 1;
122         result = prime * result
123                 + ((errorStatus == null) ? 0 : errorStatus.hashCode());
124         result = prime * result + ((port == null) ? 0 : port.hashCode());
125         return result;
126     }
127
128     @Override
129     public boolean equals(Object obj) {
130         if (this == obj) {
131             return true;
132         }
133         if (obj == null) {
134             return false;
135         }
136         if (getClass() != obj.getClass()) {
137             return false;
138         }
139         SwitchPort other = (SwitchPort) obj;
140         if (errorStatus != other.errorStatus) {
141             return false;
142         }
143         if (port == null) {
144             if (other.port != null) {
145                 return false;
146             }
147         } else if (!port.equals(other.port)) {
148             return false;
149         }
150         return true;
151     }
152
153     @Override
154     public String toString() {
155         return "SwitchPort [port=" + port + ", errorStatus=" + errorStatus
156                 + "]";
157     }
158 }