KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YChar


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 final class YChar extends YapJavaClass {
25
26     static final int LENGTH = YapConst.CHAR_BYTES + YapConst.ADDED_LENGTH;
27     
28     private static final Character JavaDoc i_primitive = new Character JavaDoc((char)0);
29     
30     public YChar(YapStream stream) {
31         super(stream);
32     }
33     
34     public Object JavaDoc defaultValue(){
35         return i_primitive;
36     }
37     
38     public int getID() {
39         return 7;
40     }
41
42     public int linkLength() {
43         return LENGTH;
44     }
45
46     protected Class JavaDoc primitiveJavaClass() {
47         return char.class;
48     }
49
50     Object JavaDoc primitiveNull() {
51         return i_primitive;
52     }
53
54     Object JavaDoc read1(YapReader a_bytes) {
55         if (Deploy.debug) {
56             a_bytes.readBegin(YapConst.YAPCHAR);
57         }
58         byte b1 = a_bytes.readByte();
59         byte b2 = a_bytes.readByte();
60         if (Deploy.debug) {
61             a_bytes.readEnd();
62         }
63         char ret = (char) ((b1 & 0xff) | ((b2 & 0xff) << 8));
64         return new Character JavaDoc(ret);
65     }
66
67     public void write(Object JavaDoc a_object, YapReader a_bytes) {
68         if (Deploy.debug) {
69             a_bytes.writeBegin(YapConst.YAPCHAR);
70         }
71         char char_ = ((Character JavaDoc) a_object).charValue();
72         a_bytes.append((byte) (char_ & 0xff));
73         a_bytes.append((byte) (char_ >> 8));
74         if (Deploy.debug) {
75             a_bytes.writeEnd();
76         }
77     }
78
79     // Comparison_______________________
80

81     private char i_compareTo;
82
83     private char val(Object JavaDoc obj) {
84         return ((Character JavaDoc) obj).charValue();
85     }
86
87     void prepareComparison1(Object JavaDoc obj) {
88         i_compareTo = val(obj);
89     }
90     
91     public Object JavaDoc current1(){
92         return new Character JavaDoc(i_compareTo);
93     }
94
95     boolean isEqual1(Object JavaDoc obj) {
96         return obj instanceof Character JavaDoc && val(obj) == i_compareTo;
97     }
98
99     boolean isGreater1(Object JavaDoc obj) {
100         return obj instanceof Character JavaDoc && val(obj) > i_compareTo;
101     }
102
103     boolean isSmaller1(Object JavaDoc obj) {
104         return obj instanceof Character JavaDoc && val(obj) < i_compareTo;
105     }
106
107 }
108
Popular Tags