blob: 4981a61811872aeb50346cb38044844337af11b1 [file] [log] [blame]
Jian Li23906cc2016-03-31 11:16:44 -07001/*
2 * Copyright 2016 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 */
16package org.onosproject.cpman.impl;
17
18import com.google.common.base.MoreObjects;
19import org.onosproject.cpman.ControlMetricType;
20import org.onosproject.net.DeviceId;
21
22import java.util.Objects;
23import java.util.Optional;
24
25import static com.google.common.base.MoreObjects.toStringHelper;
26
27/**
28 * A container class that is used to request control metric of remote node.
29 */
30public class ControlMetricsRequest {
31 private final ControlMetricType type;
32 private Optional<DeviceId> deviceId;
33 private String resourceName;
34
35 /**
36 * Instantiates a new control metric request with the given control metric
37 * type and device identifier.
38 *
39 * @param type control metric type
40 * @param deviceId device identifier
41 */
42 public ControlMetricsRequest(ControlMetricType type, Optional<DeviceId> deviceId) {
43 this.type = type;
44 this.deviceId = deviceId;
45 }
46
47 /**
48 * Instantiates a new control metric request with the given control metric
49 * type and resource name.
50 *
51 * @param type control metric type
52 * @param resourceName resource name
53 */
54 public ControlMetricsRequest(ControlMetricType type, String resourceName) {
55 this.type = type;
56 this.resourceName = resourceName;
57 }
58
59 /**
60 * Obtains control metric type.
61 *
62 * @return control metric type
63 */
64 public ControlMetricType getType() {
65 return type;
66 }
67
68 /**
69 * Obtains resource name.
70 *
71 * @return resource name
72 */
73 public String getResourceName() {
74 return resourceName;
75 }
76
77 /**
78 * Obtains device identifier.
79 *
80 * @return device identifier
81 */
82 public Optional<DeviceId> getDeviceId() {
83 return deviceId;
84 }
85
86 @Override
87 public int hashCode() {
88 return Objects.hash(type, deviceId, resourceName);
89 }
90
91 @Override
92 public boolean equals(Object obj) {
93 if (this == obj) {
94 return true;
95 }
96 if (obj instanceof ControlMetricsRequest) {
97 final ControlMetricsRequest other = (ControlMetricsRequest) obj;
98 return Objects.equals(this.type, other.type) &&
99 Objects.equals(this.deviceId, other.deviceId) &&
100 Objects.equals(this.resourceName, other.resourceName);
101 }
102 return false;
103 }
104
105 @Override
106 public String toString() {
107 MoreObjects.ToStringHelper helper;
108 helper = toStringHelper(this)
109 .add("type", type)
110 .add("resourceName", resourceName);
111 if (deviceId != null) {
112 helper.add("deviceId", deviceId.get());
113 }
114 return helper.toString();
115 }
116}