blob: f41f76dcc0ac7432bb60629b0c06b24b5fce06d3 [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07003 *
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 java.util.Objects;
19
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070020/**
21 * Implementation of Metadata criterion.
22 */
23public final class MetadataCriterion implements Criterion {
24 private final long metadata;
25
26 /**
27 * Constructor.
28 *
29 * @param metadata the metadata to match (64 bits data)
30 */
31 MetadataCriterion(long metadata) {
32 this.metadata = metadata;
33 }
34
35 @Override
36 public Type type() {
37 return Type.METADATA;
38 }
39
40 /**
41 * Gets the metadata to match.
42 *
43 * @return the metadata to match (64 bits data)
44 */
45 public long metadata() {
46 return metadata;
47 }
48
49 @Override
50 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080051 return type().toString() + SEPARATOR + Long.toHexString(metadata);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070052 }
53
54 @Override
55 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070056 return Objects.hash(type().ordinal(), metadata);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070057 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (this == obj) {
62 return true;
63 }
64 if (obj instanceof MetadataCriterion) {
65 MetadataCriterion that = (MetadataCriterion) obj;
66 return Objects.equals(metadata, that.metadata) &&
67 Objects.equals(this.type(), that.type());
68 }
69 return false;
70 }
71}