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 private final boolean value;
32
33 /**
34 * Creates a gawk boolean-number value.
35 *
36 * @param valueParam boolean value
37 */
38 public GawkBool(boolean valueParam) {
39 this.value = valueParam;
40 }
41
42 /**
43 * Returns the boolean value.
44 *
45 * @return boolean value
46 */
47 public boolean booleanValue() {
48 return value;
49 }
50
51 /** {@inheritDoc} */
52 @Override
53 public int intValue() {
54 return value ? 1 : 0;
55 }
56
57 /** {@inheritDoc} */
58 @Override
59 public long longValue() {
60 return value ? 1L : 0L;
61 }
62
63 /** {@inheritDoc} */
64 @Override
65 public float floatValue() {
66 return value ? 1.0F : 0.0F;
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 public double doubleValue() {
72 return value ? 1.0D : 0.0D;
73 }
74
75 /** {@inheritDoc} */
76 @Override
77 public String toString() {
78 return value ? "1" : "0";
79 }
80 }