blob: e97d2bbea52d7940209a1393c1fa89593fbcc340 [file] [log] [blame]
Carmelo Cascone5899c132016-04-06 22:09:08 -07001/*
Carmelo Casconeaa8b6292016-04-13 14:27:06 -07002 * Copyright 2016-present Open Networking Laboratory
Carmelo Cascone5899c132016-04-06 22:09:08 -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 */
16
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070017package org.onosproject.bmv2.api.context;
18
19import com.google.common.annotations.Beta;
Carmelo Cascone5899c132016-04-06 22:09:08 -070020
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070026 * A BMv2 action runtime data model.
Carmelo Cascone5899c132016-04-06 22:09:08 -070027 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070028@Beta
29public final class Bmv2RuntimeDataModel {
Carmelo Cascone5899c132016-04-06 22:09:08 -070030
31 private final String name;
32 private final int bitWidth;
33
34 /**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070035 * Creates a new runtime data model.
Carmelo Cascone5899c132016-04-06 22:09:08 -070036 *
37 * @param name name
38 * @param bitWidth bitwidth
39 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070040 protected Bmv2RuntimeDataModel(String name, int bitWidth) {
Carmelo Cascone5899c132016-04-06 22:09:08 -070041 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 Cascone17fc9e42016-05-31 11:29:21 -070076 final Bmv2RuntimeDataModel other = (Bmv2RuntimeDataModel) obj;
Carmelo Cascone5899c132016-04-06 22:09:08 -070077 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}