blob: 646b418427abc64af2645b35e60370aa67771521 [file] [log] [blame]
Jonathan Hart26a8d952015-12-02 15:16:35 -08001/*
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
17package org.onosproject.net.flow.criteria;
18
19import org.onosproject.net.DeviceId;
20
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * Criterion for implementing selector extensions.
27 */
28public class ExtensionCriterion implements Criterion {
29
30 private final ExtensionSelector extensionSelector;
31 private final DeviceId deviceId;
32
33 /**
34 * Constructor.
35 *
36 * @param extensionSelector extension selector
37 */
38 public ExtensionCriterion(ExtensionSelector extensionSelector, DeviceId deviceId) {
39 this.extensionSelector = extensionSelector;
40 this.deviceId = deviceId;
41 }
42
43 /**
44 * Returns the extension selector.
45 *
46 * @return extension selector
47 */
48 public ExtensionSelector extensionSelector() {
49 return extensionSelector;
50 }
51
52 /**
53 * Returns the device ID.
54 *
55 * @return device ID
56 */
57 public DeviceId deviceId() {
58 return deviceId;
59 }
60
61 @Override
62 public Type type() {
63 return Type.EXTENSION;
64 }
65
66 @Override
67 public String toString() {
68 return toStringHelper(type().toString())
69 .add("extensionSelector", extensionSelector.toString())
70 .add("deviceId", deviceId)
71 .toString();
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hash(type().ordinal(), extensionSelector, deviceId);
77 }
78
79 @Override
80 public boolean equals(Object obj) {
81 if (this == obj) {
82 return true;
83 }
84 if (obj instanceof ExtensionCriterion) {
85 ExtensionCriterion that = (ExtensionCriterion) obj;
86 return Objects.equals(extensionSelector, that.extensionSelector) &&
87 Objects.equals(deviceId, that.deviceId) &&
88 Objects.equals(this.type(), that.type());
89 }
90 return false;
91 }
92}