KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YShort


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 final class YShort extends YapJavaClass
28 {
29     static final int LENGTH = YapConst.SHORT_BYTES + YapConst.ADDED_LENGTH;
30     
31     private static final Short JavaDoc i_primitive = new Short JavaDoc((short)0);
32     
33     public YShort(YapStream stream) {
34         super(stream);
35     }
36     
37     public Object JavaDoc coerce(ReflectClass claxx, Object JavaDoc obj) {
38         return Coercion4.toShort(obj);
39     }
40     public Object JavaDoc defaultValue(){
41         return i_primitive;
42     }
43     
44     public int getID(){
45         return 8;
46     }
47     
48     public int linkLength(){
49         return LENGTH;
50     }
51     
52     protected Class JavaDoc primitiveJavaClass(){
53         return short.class;
54     }
55     
56     Object JavaDoc primitiveNull(){
57         return i_primitive;
58     }
59     
60     Object JavaDoc read1(YapReader a_bytes){
61         return new Short JavaDoc(readShort(a_bytes));
62     }
63     
64     static final short readShort(YapReader a_bytes){
65         int ret = 0;
66         if (Deploy.debug){
67             a_bytes.readBegin(YapConst.YAPSHORT);
68         }
69         for (int i = 0; i < YapConst.SHORT_BYTES; i++){
70             ret = (ret << 8) + (a_bytes._buffer[a_bytes._offset++] & 0xff);
71         }
72         if (Deploy.debug){
73             a_bytes.readEnd();
74         }
75         return (short)ret;
76     }
77
78     public void write(Object JavaDoc a_object, YapReader a_bytes){
79         writeShort(((Short JavaDoc)a_object).shortValue(), a_bytes);
80     }
81     
82     static final void writeShort(int a_short, YapReader a_bytes){
83         if(Deploy.debug){
84             a_bytes.writeBegin(YapConst.YAPSHORT);
85         }
86         for (int i = 0; i < YapConst.SHORT_BYTES; i++){
87             a_bytes._buffer[a_bytes._offset++] = (byte) (a_short >> ((YapConst.SHORT_BYTES - 1 - i) * 8));
88         }
89         if(Deploy.debug){
90             a_bytes.writeEnd();
91         }
92     }
93     
94     // Comparison_______________________
95

96     private short i_compareTo;
97     
98     private short val(Object JavaDoc obj){
99         return ((Short JavaDoc)obj).shortValue();
100     }
101     
102     void prepareComparison1(Object JavaDoc obj){
103         i_compareTo = val(obj);
104     }
105     
106     public Object JavaDoc current1(){
107         return new Short JavaDoc(i_compareTo);
108     }
109     
110     boolean isEqual1(Object JavaDoc obj){
111         return obj instanceof Short JavaDoc && val(obj) == i_compareTo;
112     }
113     
114     boolean isGreater1(Object JavaDoc obj){
115         return obj instanceof Short JavaDoc && val(obj) > i_compareTo;
116     }
117     
118     boolean isSmaller1(Object JavaDoc obj){
119         return obj instanceof Short JavaDoc && val(obj) < i_compareTo;
120     }
121     
122     
123 }
124
Popular Tags