blob: 824e00ea125c8a6274cd79c6bc1f01d24aec7c28 [file] [log] [blame]
Sho SHIMIZUefc2e282015-05-04 15:26:23 -07001/*
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 */
16package org.onosproject.net.flow.criteria;
17
18import com.google.common.base.MoreObjects;
19import org.onosproject.net.IndexedLambda;
20
21import java.util.Objects;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Implementation of indexed lambda criterion.
27 */
28public class IndexedLambdaCriterion implements Criterion {
29
30 private final IndexedLambda lambda;
31
32 /**
33 * Creates a criterion with the specified value.
34 *
35 * @param lambda lambda index number
36 */
37 IndexedLambdaCriterion(IndexedLambda lambda) {
38 this.lambda = checkNotNull(lambda);
39 }
40
41 @Override
42 public Type type() {
43 // TODO: consider defining a new specific type
44 // Now OCH_SIGID is used due to compatibility concerns
45 return Type.OCH_SIGID;
46 }
47
48 /**
49 * Returns the indexed lambda to match.
50 *
51 * @return the indexed lambda to match
52 */
53 public IndexedLambda lambda() {
54 return lambda;
55 }
56
57 @Override
58 public int hashCode() {
59 return Objects.hash(lambda);
60 }
61
62 @Override
63 public boolean equals(Object obj) {
64 if (this == obj) {
65 return true;
66 }
67 if (!(obj instanceof IndexedLambdaCriterion)) {
68 return false;
69 }
70 final IndexedLambdaCriterion that = (IndexedLambdaCriterion) obj;
71 return Objects.equals(this.lambda, that.lambda);
72 }
73
74 @Override
75 public String toString() {
76 return MoreObjects.toStringHelper(this)
77 .add("lambda", lambda)
78 .toString();
79 }
80}