KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > value > ValueBoolean


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.value;
6
7 import java.sql.PreparedStatement JavaDoc;
8 import java.sql.SQLException JavaDoc;
9
10 /**
11  * @author Thomas
12  */

13 public class ValueBoolean extends Value {
14     public static final int PRECISION = 1;
15
16     private Boolean JavaDoc value;
17
18     private static final ValueBoolean TRUE = new ValueBoolean(true);
19     private static final ValueBoolean FALSE = new ValueBoolean(false);
20
21     private ValueBoolean(boolean value) {
22         this.value = Boolean.valueOf(""+value);
23     }
24
25     public int getType() {
26         return Value.BOOLEAN;
27     }
28
29     public String JavaDoc getSQL() {
30         return getString();
31     }
32
33     public String JavaDoc getString() {
34         return value.booleanValue() ? "TRUE" : "FALSE";
35     }
36
37     public Value negate() throws SQLException JavaDoc {
38         return value.booleanValue() ? FALSE : TRUE;
39     }
40
41     public Boolean JavaDoc getBoolean() {
42         return value;
43     }
44
45     protected int compareSecure(Value o, CompareMode mode) {
46         boolean v2 = ((ValueBoolean) o).value.booleanValue();
47         boolean v = value.booleanValue();
48         return (v == v2) ? 0 : (v ? 1 : -1);
49     }
50
51     public long getPrecision() {
52         return PRECISION;
53     }
54
55     public int hashCode() {
56         return value.booleanValue() ? 1 : 0;
57     }
58
59     public Object JavaDoc getObject() {
60         return value;
61     }
62
63     public void set(PreparedStatement JavaDoc prep, int parameterIndex) throws SQLException JavaDoc {
64         prep.setBoolean(parameterIndex, value.booleanValue());
65     }
66
67     public static ValueBoolean get(boolean b) {
68         return b ? TRUE : FALSE;
69     }
70
71 // public String getJavaString() {
72
// return value.booleanValue() ? "true" : "false";
73
// }
74

75     public int getDisplaySize() {
76         return "FALSE".length();
77     }
78
79     protected boolean isEqual(Value v) {
80         return v instanceof ValueBoolean && value.booleanValue() == ((ValueBoolean)v).value.booleanValue();
81     }
82
83 }
84
Popular Tags