1 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 i_primitive = new Short ((short)0); 32 33 public YShort(YapStream stream) { 34 super(stream); 35 } 36 37 public Object coerce(ReflectClass claxx, Object obj) { 38 return Coercion4.toShort(obj); 39 } 40 public Object 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 primitiveJavaClass(){ 53 return short.class; 54 } 55 56 Object primitiveNull(){ 57 return i_primitive; 58 } 59 60 Object read1(YapReader a_bytes){ 61 return new Short (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 a_object, YapReader a_bytes){ 79 writeShort(((Short )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 96 private short i_compareTo; 97 98 private short val(Object obj){ 99 return ((Short )obj).shortValue(); 100 } 101 102 void prepareComparison1(Object obj){ 103 i_compareTo = val(obj); 104 } 105 106 public Object current1(){ 107 return new Short (i_compareTo); 108 } 109 110 boolean isEqual1(Object obj){ 111 return obj instanceof Short && val(obj) == i_compareTo; 112 } 113 114 boolean isGreater1(Object obj){ 115 return obj instanceof Short && val(obj) > i_compareTo; 116 } 117 118 boolean isSmaller1(Object obj){ 119 return obj instanceof Short && val(obj) < i_compareTo; 120 } 121 122 123 } 124 | Popular Tags |