Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | package org.onosproject.net.flow.criteria; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
| 22 | /** |
| 23 | * Implementation of Metadata criterion. |
| 24 | */ |
| 25 | public final class MetadataCriterion implements Criterion { |
| 26 | private final long metadata; |
| 27 | |
| 28 | /** |
| 29 | * Constructor. |
| 30 | * |
| 31 | * @param metadata the metadata to match (64 bits data) |
| 32 | */ |
| 33 | MetadataCriterion(long metadata) { |
| 34 | this.metadata = metadata; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public Type type() { |
| 39 | return Type.METADATA; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Gets the metadata to match. |
| 44 | * |
| 45 | * @return the metadata to match (64 bits data) |
| 46 | */ |
| 47 | public long metadata() { |
| 48 | return metadata; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public String toString() { |
| 53 | return toStringHelper(type().toString()) |
| 54 | .add("metadata", Long.toHexString(metadata)) |
| 55 | .toString(); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public int hashCode() { |
| 60 | return Objects.hash(type(), metadata); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(Object obj) { |
| 65 | if (this == obj) { |
| 66 | return true; |
| 67 | } |
| 68 | if (obj instanceof MetadataCriterion) { |
| 69 | MetadataCriterion that = (MetadataCriterion) obj; |
| 70 | return Objects.equals(metadata, that.metadata) && |
| 71 | Objects.equals(this.type(), that.type()); |
| 72 | } |
| 73 | return false; |
| 74 | } |
| 75 | } |