1 package io.jawk.ext;
2
3 /*-
4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5 * Jawk
6 * ჻჻჻჻჻჻
7 * Copyright (C) 2006 - 2026 MetricsHub
8 * ჻჻჻჻჻჻
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23 */
24
25 /**
26 * Numeric value carrying gawk's boolean type attribute.
27 */
28 public final class GawkBool extends Number {
29
30 private static final long serialVersionUID = 1L;
31
32 /** Boolean this number carries; {@code 1} when true, {@code 0} when false. */
33 private final boolean value;
34
35 /**
36 * Creates a gawk boolean-number value.
37 *
38 * @param valueParam boolean value
39 */
40 public GawkBool(boolean valueParam) {
41 this.value = valueParam;
42 }
43
44 /**
45 * Returns the boolean value.
46 *
47 * @return boolean value
48 */
49 public boolean booleanValue() {
50 return value;
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public int intValue() {
56 return value ? 1 : 0;
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public long longValue() {
62 return value ? 1L : 0L;
63 }
64
65 /** {@inheritDoc} */
66 @Override
67 public float floatValue() {
68 return value ? 1.0F : 0.0F;
69 }
70
71 /** {@inheritDoc} */
72 @Override
73 public double doubleValue() {
74 return value ? 1.0D : 0.0D;
75 }
76
77 /** {@inheritDoc} */
78 @Override
79 public String toString() {
80 return value ? "1" : "0";
81 }
82 }