KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YByte


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 import com.db4o.foundation.*;
24 import com.db4o.reflect.*;
25
26
27 final class YByte extends YapJavaClass
28 {
29
30     static final int LENGTH = 1 + YapConst.ADDED_LENGTH;
31     
32     private static final Byte JavaDoc i_primitive = new Byte JavaDoc((byte)0);
33     
34     public YByte(YapStream stream) {
35         super(stream);
36     }
37     
38     public Object JavaDoc coerce(ReflectClass claxx, Object JavaDoc obj) {
39         return Coercion4.toSByte(obj);
40     }
41
42     public int getID(){
43         return 6;
44     }
45     
46     public Object JavaDoc defaultValue(){
47         return i_primitive;
48     }
49     
50     public int linkLength(){
51         return LENGTH;
52     }
53
54     protected Class JavaDoc primitiveJavaClass(){
55         return byte.class;
56     }
57     
58     Object JavaDoc primitiveNull(){
59         return i_primitive;
60     }
61     
62     Object JavaDoc read1(YapReader a_bytes){
63         if (Deploy.debug){
64             a_bytes.readBegin(YapConst.YAPBYTE);
65         }
66         byte ret = a_bytes.readByte();
67         if (Deploy.debug){
68             a_bytes.readEnd();
69         }
70         return new Byte JavaDoc(ret);
71     }
72     
73     public void write(Object JavaDoc a_object, YapReader a_bytes){
74         if(Deploy.debug){
75             a_bytes.writeBegin(YapConst.YAPBYTE);
76         }
77         a_bytes.append(((Byte JavaDoc)a_object).byteValue());
78         if(Deploy.debug){
79             a_bytes.writeEnd();
80         }
81     }
82     
83     public boolean readArray(Object JavaDoc array, YapReader reader) {
84         if(array instanceof byte[]){
85             reader.readBytes((byte[])array);
86             return true;
87         }
88         
89         return false;
90     }
91
92     public boolean writeArray(Object JavaDoc array, YapReader writer) {
93         if(array instanceof byte[]){
94             writer.append((byte[])array);
95             return true;
96         }
97         return false;
98     }
99     
100
101                     
102     // Comparison_______________________
103

104     private byte i_compareTo;
105     
106     private byte val(Object JavaDoc obj){
107         return ((Byte JavaDoc)obj).byteValue();
108     }
109     
110     void prepareComparison1(Object JavaDoc obj){
111         i_compareTo = val(obj);
112     }
113     
114     public Object JavaDoc current1(){
115         return new Byte JavaDoc(i_compareTo);
116     }
117     
118     boolean isEqual1(Object JavaDoc obj){
119         return obj instanceof Byte JavaDoc && val(obj) == i_compareTo;
120     }
121     
122     boolean isGreater1(Object JavaDoc obj){
123         return obj instanceof Byte JavaDoc && val(obj) > i_compareTo;
124     }
125     
126     boolean isSmaller1(Object JavaDoc obj){
127         return obj instanceof Byte JavaDoc && val(obj) < i_compareTo;
128     }
129 }
130
Popular Tags