FrankWang | 2674e45 | 2018-05-24 17:13:35 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.p4runtime.model; |
| 18 | |
| 19 | import org.onosproject.net.pi.model.PiRegisterModel; |
| 20 | import org.onosproject.net.pi.model.PiRegisterId; |
| 21 | |
| 22 | import java.util.Objects; |
| 23 | |
pierventre | db35289 | 2021-01-10 17:29:03 -0800 | [diff] [blame^] | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | |
FrankWang | 2674e45 | 2018-05-24 17:13:35 +0800 | [diff] [blame] | 26 | /** |
| 27 | * Implementation of PiRegisterModel for P4Runtime. |
| 28 | */ |
| 29 | final class P4RegisterModel implements PiRegisterModel { |
| 30 | |
| 31 | private final PiRegisterId id; |
| 32 | private final long size; |
| 33 | |
| 34 | P4RegisterModel(PiRegisterId id, long size) { |
| 35 | this.id = id; |
| 36 | this.size = size; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public PiRegisterId id() { |
| 41 | return id; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public long size() { |
| 46 | return size; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public int hashCode() { |
| 51 | return Objects.hash(id, size); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public boolean equals(Object obj) { |
| 56 | if (this == obj) { |
| 57 | return true; |
| 58 | } |
| 59 | if (obj == null || getClass() != obj.getClass()) { |
| 60 | return false; |
| 61 | } |
| 62 | final P4RegisterModel other = (P4RegisterModel) obj; |
| 63 | return Objects.equals(this.id, other.id) |
| 64 | && Objects.equals(this.size, other.size); |
| 65 | } |
pierventre | db35289 | 2021-01-10 17:29:03 -0800 | [diff] [blame^] | 66 | |
| 67 | @Override |
| 68 | public String toString() { |
| 69 | return toStringHelper(this) |
| 70 | .add("id", id) |
| 71 | .add("size", size) |
| 72 | .toString(); |
| 73 | } |
FrankWang | 2674e45 | 2018-05-24 17:13:35 +0800 | [diff] [blame] | 74 | } |