File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\value\ValueBoolean.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.value;
8
9 import java.sql.PreparedStatement;
10 import java.sql.SQLException;
11
12 /**
13 * Implementation of the BOOLEAN data type.
14 */
15 public class ValueBoolean extends Value {
16
17 /**
18 * The precision in digits.
19 */
20 public static final int PRECISION = 1;
21
22 /**
23 * The maximum display size of a boolean.
24 * Example: FALSE
25 */
26 public static final int DISPLAY_SIZE = 5;
27
28 /**
29 * Of type Object so that Tomcat doesn't set it to null.
30 */
31 private static final Object TRUE = new ValueBoolean(true);
32 private static final Object FALSE = new ValueBoolean(false);
33
34 private final Boolean value;
35
36 private ValueBoolean(boolean value) {
37 this.value = Boolean.valueOf(value);
38 }
39
40 public int getType() {
41 return Value.BOOLEAN;
42 }
43
44 public String getSQL() {
45 return getString();
46 }
47
48 public String getString() {
49 return value.booleanValue() ? "TRUE" : "FALSE";
50 }
51
52 public Value negate() {
53 return (ValueBoolean) (value.booleanValue() ? FALSE : TRUE);
54 }
55
56 public Boolean getBoolean() {
57 return value;
58 }
59
60 protected int compareSecure(Value o, CompareMode mode) {
61 boolean v2 = ((ValueBoolean) o).value.booleanValue();
62 boolean v = value.booleanValue();
63 return (v == v2) ? 0 : (v ? 1 : -1);
64 }
65
66 public long getPrecision() {
67 return PRECISION;
68 }
69
70 public int hashCode() {
71 return value.booleanValue() ? 1 : 0;
72 }
73
74 public Object getObject() {
75 return value;
76 }
77
78 public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
79 prep.setBoolean(parameterIndex, value.booleanValue());
80 }
81
82 /**
83 * Get the boolean value for the given boolean.
84 *
85 * @param b the boolean
86 * @return the value
87 */
88 public static ValueBoolean get(boolean b) {
89 return (ValueBoolean) (b ? TRUE : FALSE);
90 }
91
92 public int getDisplaySize() {
93 return DISPLAY_SIZE;
94 }
95
96 public boolean equals(Object other) {
97 // there are only ever two instances, so the instance must match
98 return this == other;
99 }
100
101 }
102