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 | * BMv2 model header type field. |
| 25 | */ |
| 26 | public final class Bmv2ModelFieldType { |
| 27 | |
| 28 | private final String name; |
| 29 | private final int bitWidth; |
| 30 | |
| 31 | protected Bmv2ModelFieldType(String name, int bitWidth) { |
| 32 | this.name = name; |
| 33 | this.bitWidth = bitWidth; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns the name of this header type field. |
| 38 | * |
| 39 | * @return a string value |
| 40 | */ |
| 41 | public String name() { |
| 42 | return name; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the bit width of this header type field. |
| 47 | * |
| 48 | * @return an integer value |
| 49 | */ |
| 50 | public int bitWidth() { |
| 51 | return bitWidth; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public int hashCode() { |
| 56 | return Objects.hashCode(name, bitWidth); |
| 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 Bmv2ModelFieldType other = (Bmv2ModelFieldType) obj; |
| 68 | return Objects.equal(this.name, other.name) |
| 69 | && Objects.equal(this.bitWidth, other.bitWidth); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public String toString() { |
| 74 | return toStringHelper(this) |
| 75 | .add("name", name) |
| 76 | .add("bitWidth", bitWidth) |
| 77 | .toString(); |
| 78 | } |
| 79 | } |