blob: 9c3d6342d3136a3e091262d327c2b9e3239ed78e [file] [log] [blame]
Jian Li2c4e9a92017-03-13 16:45:53 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li2c4e9a92017-03-13 16:45:53 +09003 *
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 */
16package org.onosproject.mapping.addresses;
17
18import org.onosproject.net.DeviceId;
Jian Li2c4e9a92017-03-13 16:45:53 +090019
20import java.util.Objects;
21
22/**
23 * Mapping address for implementing extensions.
24 */
25public final class ExtensionMappingAddressWrapper implements MappingAddress {
26
Jian Li0f0d7482017-03-20 15:16:13 +090027 private final ExtensionMappingAddress extensionMappingAddress;
Jian Li2c4e9a92017-03-13 16:45:53 +090028 private final DeviceId deviceId;
29
30 /**
31 * Default constructor of ExtensionMappingAddressWrapper.
32 *
Jian Li0f0d7482017-03-20 15:16:13 +090033 * @param extensionMappingAddress extension mapping address
34 * @param deviceId device identifier
Jian Li2c4e9a92017-03-13 16:45:53 +090035 */
Jian Li0f0d7482017-03-20 15:16:13 +090036 public ExtensionMappingAddressWrapper(ExtensionMappingAddress extensionMappingAddress,
37 DeviceId deviceId) {
38 this.extensionMappingAddress = extensionMappingAddress;
Jian Li2c4e9a92017-03-13 16:45:53 +090039 this.deviceId = deviceId;
40 }
41
42 @Override
43 public Type type() {
44 return Type.EXTENSION;
45 }
46
47 /**
Jian Li0f0d7482017-03-20 15:16:13 +090048 * Returns the extension mapping address.
Jian Li2c4e9a92017-03-13 16:45:53 +090049 *
Jian Li0f0d7482017-03-20 15:16:13 +090050 * @return extension mapping address
Jian Li2c4e9a92017-03-13 16:45:53 +090051 */
Jian Li0f0d7482017-03-20 15:16:13 +090052 public ExtensionMappingAddress extensionMappingAddress() {
53 return extensionMappingAddress;
Jian Li2c4e9a92017-03-13 16:45:53 +090054 }
55
56 /**
57 * Returns the device identifier.
58 *
59 * @return the device identifier
60 */
61 public DeviceId deviceId() {
62 return deviceId;
63 }
64
65 @Override
66 public String toString() {
Jian Li0f0d7482017-03-20 15:16:13 +090067 return type().toString() + TYPE_SEPARATOR + extensionMappingAddress;
Jian Li2c4e9a92017-03-13 16:45:53 +090068 }
69
70 @Override
71 public int hashCode() {
Jian Li0f0d7482017-03-20 15:16:13 +090072 return Objects.hash(type().ordinal(), extensionMappingAddress);
Jian Li2c4e9a92017-03-13 16:45:53 +090073 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj) {
78 return true;
79 }
80 if (obj instanceof ExtensionMappingAddressWrapper) {
81 ExtensionMappingAddressWrapper that = (ExtensionMappingAddressWrapper) obj;
Jian Li0f0d7482017-03-20 15:16:13 +090082 return Objects.equals(extensionMappingAddress, that.extensionMappingAddress) &&
Jian Li2c4e9a92017-03-13 16:45:53 +090083 Objects.equals(deviceId, that.deviceId);
84 }
85 return false;
86 }
87}