KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YBoolean


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o;
22
23 /**
24  * @exclude
25  */

26 public final class YBoolean extends YapJavaClass
27 {
28
29     static final int LENGTH = 1 + YapConst.ADDED_LENGTH;
30     
31     private static final byte TRUE = (byte) 'T';
32     private static final byte FALSE = (byte) 'F';
33     
34     private static final Boolean JavaDoc i_primitive = new Boolean JavaDoc(false);
35     
36     public YBoolean(YapStream stream) {
37         super(stream);
38     }
39     
40     public int getID(){
41         return 4;
42     }
43     
44     public Object JavaDoc defaultValue(){
45         return i_primitive;
46     }
47     
48     public int linkLength(){
49         return LENGTH;
50     }
51     
52     protected Class JavaDoc primitiveJavaClass(){
53         return boolean.class;
54     }
55     
56     Object JavaDoc primitiveNull(){
57         return i_primitive;
58     }
59
60     Object JavaDoc read1(YapReader a_bytes){
61         if (Deploy.debug){
62             a_bytes.readBegin(YapConst.YAPBOOLEAN);
63         }
64         byte ret = a_bytes.readByte();
65         if (Deploy.debug){
66             a_bytes.readEnd();
67         }
68         
69         if(ret == TRUE){
70             return new Boolean JavaDoc(true);
71         }
72         if(ret == FALSE){
73             return new Boolean JavaDoc(false);
74         }
75         
76         return null;
77     }
78     
79     public void write(Object JavaDoc a_object, YapReader a_bytes){
80         if(Deploy.debug){
81             a_bytes.writeBegin(YapConst.YAPBOOLEAN);
82         }
83         byte set;
84         if(((Boolean JavaDoc)a_object).booleanValue()){
85             set = TRUE;
86         }else{
87             set = FALSE;
88         }
89         a_bytes.append(set);
90         if(Deploy.debug){
91             a_bytes.writeEnd();
92         }
93     }
94
95     
96     // Comparison_______________________
97

98     private boolean i_compareTo;
99     
100     private boolean val(Object JavaDoc obj){
101         return ((Boolean JavaDoc)obj).booleanValue();
102     }
103     
104     void prepareComparison1(Object JavaDoc obj){
105         i_compareTo = val(obj);
106     }
107     
108     public Object JavaDoc current1(){
109         return new Boolean JavaDoc(i_compareTo);
110     }
111     
112     boolean isEqual1(Object JavaDoc obj){
113         return obj instanceof Boolean JavaDoc && val(obj) == i_compareTo;
114     }
115     
116     boolean isGreater1(Object JavaDoc obj){
117         if(i_compareTo){
118             return false;
119         }
120         return obj instanceof Boolean JavaDoc && val(obj);
121     }
122     
123     boolean isSmaller1(Object JavaDoc obj){
124         if(! i_compareTo){
125             return false;
126         }
127         return obj instanceof Boolean JavaDoc && ! val(obj);
128     }
129 }
130
Popular Tags