Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 1 | /* |
Carmelo Cascone | aa8b629 | 2016-04-13 14:27:06 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 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 | |
Carmelo Cascone | aa8b629 | 2016-04-13 14:27:06 -0700 | [diff] [blame^] | 17 | package org.onosproject.bmv2.api.model; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 18 | |
| 19 | import com.google.common.base.Objects; |
| 20 | |
| 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
| 23 | /** |
| 24 | * Representation of a BMv2 model's header field instance. |
| 25 | */ |
| 26 | public final class Bmv2ModelField { |
| 27 | |
| 28 | private final Bmv2ModelHeader header; |
| 29 | private final Bmv2ModelFieldType type; |
| 30 | |
| 31 | protected Bmv2ModelField(Bmv2ModelHeader header, Bmv2ModelFieldType type) { |
| 32 | this.header = header; |
| 33 | this.type = type; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns the header instance of this field instance. |
| 38 | * |
| 39 | * @return a header instance |
| 40 | */ |
| 41 | public Bmv2ModelHeader header() { |
| 42 | return header; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the type of this field instance. |
| 47 | * |
| 48 | * @return a field type value |
| 49 | */ |
| 50 | public Bmv2ModelFieldType type() { |
| 51 | return type; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public int hashCode() { |
| 56 | return Objects.hashCode(header, type); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public boolean equals(Object obj) { |
| 61 | if (this == obj) { |
| 62 | return true; |
| 63 | } |
| 64 | if (obj == null || getClass() != obj.getClass()) { |
| 65 | return false; |
| 66 | } |
| 67 | final Bmv2ModelField other = (Bmv2ModelField) obj; |
| 68 | return Objects.equal(this.header, other.header) |
| 69 | && Objects.equal(this.type, other.type); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public String toString() { |
| 74 | return toStringHelper(this) |
| 75 | .add("header", header) |
| 76 | .add("type", type) |
| 77 | .toString(); |
| 78 | } |
| 79 | } |