blob: 69cf186880ce953ed91ca85bebf1b184a0520af9 [file] [log] [blame]
Yi Tsengf33c0772017-06-06 14:56:18 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yi Tsengf33c0772017-06-06 14:56:18 -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 */
16package org.onosproject.bmv2.model;
17
18import com.google.common.annotations.Beta;
19import com.google.common.base.MoreObjects;
20import org.onosproject.net.pi.model.PiActionParamModel;
21
22import java.util.Objects;
23
24import static com.google.common.base.Preconditions.*;
25
26/**
27 * BMv2 action parameter model.
28 */
29@Beta
30public final class Bmv2ActionParamModel implements PiActionParamModel {
31 private final String name;
32 private final int bitWidth;
33
34 /**
35 * Builds a BMv2 action parameter model with given name and bit width.
36 *
37 * @param name the name
38 * @param bitWidth the bit width
39 */
40 public Bmv2ActionParamModel(String name, int bitWidth) {
41 checkNotNull(name, "Parameter name can't be null");
42 checkArgument(bitWidth > 0, "Bit width should be a non-zero positive integer");
43 this.name = name;
44 this.bitWidth = bitWidth;
45 }
46
47 @Override
48 public String name() {
49 return name;
50 }
51
52 @Override
53 public int bitWidth() {
54 return bitWidth;
55 }
56
57 @Override
58 public int hashCode() {
59 return Objects.hash(name, bitWidth);
60 }
61
62 @Override
63 public boolean equals(Object obj) {
64 if (obj == this) {
65 return true;
66 }
67 if (!(obj instanceof Bmv2ActionParamModel)) {
68 return false;
69 }
70 Bmv2ActionParamModel that = (Bmv2ActionParamModel) obj;
71 return Objects.equals(this.name, that.name) &&
72 this.bitWidth == that.bitWidth;
73 }
74
75 @Override
76 public String toString() {
77 return MoreObjects.toStringHelper(getClass())
78 .add("name", name)
79 .add("bitWidth", bitWidth)
80 .toString();
81 }
82}