ed0ccaa1226d00c8ba17708fd197a129feb861bb
[onosfw.git] /
1 /*
2  * Copyright 2014 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.store.device.impl;
17
18 import java.util.Objects;
19
20 import org.onosproject.net.DeviceId;
21 import org.onosproject.net.PortNumber;
22 import org.onosproject.net.provider.ProviderId;
23
24 import com.google.common.base.MoreObjects;
25
26 /**
27  * Identifier for PortDescription from a Provider.
28  */
29 public final class PortFragmentId {
30     public final ProviderId providerId;
31     public final DeviceId deviceId;
32     public final PortNumber portNumber;
33
34     public PortFragmentId(DeviceId deviceId, ProviderId providerId,
35                           PortNumber portNumber) {
36         this.providerId = providerId;
37         this.deviceId = deviceId;
38         this.portNumber = portNumber;
39     }
40
41     @Override
42     public int hashCode() {
43         return Objects.hash(providerId, deviceId, portNumber);
44     };
45
46     @Override
47     public boolean equals(Object obj) {
48         if (this == obj) {
49             return true;
50         }
51         if (!(obj instanceof PortFragmentId)) {
52             return false;
53         }
54         PortFragmentId that = (PortFragmentId) obj;
55         return Objects.equals(this.deviceId, that.deviceId) &&
56                Objects.equals(this.portNumber, that.portNumber) &&
57                Objects.equals(this.providerId, that.providerId);
58     }
59
60     @Override
61     public String toString() {
62         return MoreObjects.toStringHelper(getClass())
63                 .add("providerId", providerId)
64                 .add("deviceId", deviceId)
65                 .add("portNumber", portNumber)
66                 .toString();
67     }
68
69     // for serializer
70     @SuppressWarnings("unused")
71     private PortFragmentId() {
72         this.providerId = null;
73         this.deviceId = null;
74         this.portNumber = null;
75     }
76 }