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 | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 17 | package org.onosproject.bmv2.api.context; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 24 | |
| 25 | /** |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 26 | * A BMv2 action runtime data model. |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 27 | */ |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 28 | @Beta |
| 29 | public final class Bmv2RuntimeDataModel { |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 30 | |
| 31 | private final String name; |
| 32 | private final int bitWidth; |
| 33 | |
| 34 | /** |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 35 | * Creates a new runtime data model. |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 36 | * |
| 37 | * @param name name |
| 38 | * @param bitWidth bitwidth |
| 39 | */ |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 40 | protected Bmv2RuntimeDataModel(String name, int bitWidth) { |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 41 | this.name = name; |
| 42 | this.bitWidth = bitWidth; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Return the name of this runtime data. |
| 47 | * |
| 48 | * @return a string value |
| 49 | */ |
| 50 | public String name() { |
| 51 | return name; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Return the bit width of this runtime data. |
| 56 | * |
| 57 | * @return an integer value |
| 58 | */ |
| 59 | public int bitWidth() { |
| 60 | return bitWidth; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int hashCode() { |
| 65 | return Objects.hash(name, bitWidth); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public boolean equals(Object obj) { |
| 70 | if (this == obj) { |
| 71 | return true; |
| 72 | } |
| 73 | if (obj == null || getClass() != obj.getClass()) { |
| 74 | return false; |
| 75 | } |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 76 | final Bmv2RuntimeDataModel other = (Bmv2RuntimeDataModel) obj; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 77 | return Objects.equals(this.name, other.name) |
| 78 | && Objects.equals(this.bitWidth, other.bitWidth); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public String toString() { |
| 83 | return toStringHelper(this) |
| 84 | .add("name", name) |
| 85 | .add("bitWidth", bitWidth) |
| 86 | .toString(); |
| 87 | } |
| 88 | } |