KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YLong


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.ReflectClass;
25
26
27 /**
28  * @exclude
29  */

30 public class YLong extends YapJavaClass
31 {
32
33     private static final Long JavaDoc i_primitive = new Long JavaDoc(0);
34
35     public YLong(YapStream stream) {
36         super(stream);
37     }
38     
39     public Object JavaDoc coerce(ReflectClass claxx, Object JavaDoc obj) {
40         return Coercion4.toLong(obj);
41     }
42     
43     public Object JavaDoc defaultValue(){
44         return i_primitive;
45     }
46     
47     public int getID(){
48         return 2;
49     }
50     
51     protected Class JavaDoc primitiveJavaClass(){
52         return long.class;
53     }
54     
55     public int linkLength(){
56         return YapConst.LONG_LENGTH;
57     }
58     
59     Object JavaDoc primitiveNull(){
60         return i_primitive;
61     }
62     
63     Object JavaDoc read1(YapReader a_bytes){
64         return new Long JavaDoc(readLong(a_bytes));
65     }
66     
67     public static final long readLong(YapReader a_bytes){
68         long l_return = 0;
69         if (Deploy.debug){
70             a_bytes.readBegin(YapConst.YAPLONG);
71             if(Deploy.debugLong){
72                 l_return = Long.parseLong(new YapStringIO().read(a_bytes, YapConst.LONG_BYTES).trim());
73             }else{
74                 for (int i = 0; i < YapConst.LONG_BYTES; i++){
75                     l_return = (l_return << 8) + (a_bytes._buffer[a_bytes._offset++] & 0xff);
76                 }
77             }
78             a_bytes.readEnd();
79         }else{
80             for (int i = 0; i < YapConst.LONG_BYTES; i++){
81                 l_return = (l_return << 8) + (a_bytes._buffer[a_bytes._offset++] & 0xff);
82             }
83         }
84         return l_return;
85     }
86
87     public void write(Object JavaDoc a_object, YapReader a_bytes){
88         writeLong(((Long JavaDoc)a_object).longValue(), a_bytes);
89     }
90     
91     public static final void writeLong(long a_long, YapReader a_bytes){
92         if(Deploy.debug){
93             a_bytes.writeBegin(YapConst.YAPLONG);
94             if(Deploy.debugLong){
95                 String JavaDoc l_s = " " + a_long;
96                 new YapStringIO().write(a_bytes, l_s.substring(l_s.length() - YapConst.LONG_BYTES));
97             }
98             else{
99                 for (int i = 0; i < YapConst.LONG_BYTES; i++){
100                     a_bytes._buffer[a_bytes._offset++] = (byte) (a_long >> ((YapConst.LONG_BYTES - 1 - i) * 8));
101                 }
102             }
103             a_bytes.writeEnd();
104         }else{
105             for (int i = 0; i < YapConst.LONG_BYTES; i++){
106                 a_bytes._buffer[a_bytes._offset++] = (byte) (a_long >> ((YapConst.LONG_BYTES - 1 - i) * 8));
107             }
108         }
109     }
110     
111     static final void writeLong(long a_long, byte[] bytes){
112         for (int i = 0; i < YapConst.LONG_BYTES; i++){
113             bytes[i] = (byte) (a_long >> ((YapConst.LONG_BYTES - 1 - i) * 8));
114         }
115     }
116     
117     
118         
119     // Comparison_______________________
120

121     private long i_compareTo;
122     
123     protected final long currentLong() {
124         return i_compareTo;
125     }
126     
127     long val(Object JavaDoc obj){
128         return ((Long JavaDoc)obj).longValue();
129     }
130     
131     void prepareComparison1(Object JavaDoc obj){
132         i_compareTo = val(obj);
133     }
134     
135     public Object JavaDoc current1(){
136         return new Long JavaDoc(i_compareTo);
137     }
138     
139     boolean isEqual1(Object JavaDoc obj){
140         return obj instanceof Long JavaDoc && val(obj) == i_compareTo;
141     }
142     
143     boolean isGreater1(Object JavaDoc obj){
144         return obj instanceof Long JavaDoc && val(obj) > i_compareTo;
145     }
146     
147     boolean isSmaller1(Object JavaDoc obj){
148         return obj instanceof Long JavaDoc && val(obj) < i_compareTo;
149     }
150     
151 }
152
Popular Tags