FrankWang | ea70de3 | 2018-05-08 15:41:25 +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.net.pi.runtime.data; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onosproject.net.pi.model.PiData; |
| 22 | |
| 23 | /** |
| 24 | * Boolean entity in a protocol-independent pipeline. |
| 25 | */ |
| 26 | @Beta |
| 27 | public final class PiBool implements PiData { |
| 28 | private final Boolean bool; |
| 29 | |
| 30 | /** |
| 31 | * Creates a new protocol-independent Bool instance. |
| 32 | * |
| 33 | * @param bool boolean |
| 34 | */ |
| 35 | private PiBool(Boolean bool) { |
| 36 | this.bool = bool; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns a new protocol-independent Bool. |
| 41 | * @param bool boolean |
| 42 | * @return protocol-independent Bool |
| 43 | */ |
| 44 | public static PiBool of(Boolean bool) { |
| 45 | return new PiBool(bool); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Return protocol-independent Boolean instance. |
| 50 | * |
| 51 | * @return bool |
| 52 | */ |
| 53 | public Boolean bool() { |
| 54 | return this.bool; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public Type type() { |
| 59 | return Type.BOOL; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean equals(Object o) { |
| 64 | if (this == o) { |
| 65 | return true; |
| 66 | } |
| 67 | if (o == null || getClass() != o.getClass()) { |
| 68 | return false; |
| 69 | } |
| 70 | PiBool boolValue = (PiBool) o; |
| 71 | return Objects.equal(bool, boolValue.bool); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public int hashCode() { |
| 76 | return Objects.hashCode(bool); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public String toString() { |
| 81 | return bool.toString(); |
| 82 | } |
| 83 | } |