1 21 package com.db4o; 22 23 import com.db4o.foundation.*; 24 import com.db4o.reflect.ReflectClass; 25 26 27 30 public class YLong extends YapJavaClass 31 { 32 33 private static final Long i_primitive = new Long (0); 34 35 public YLong(YapStream stream) { 36 super(stream); 37 } 38 39 public Object coerce(ReflectClass claxx, Object obj) { 40 return Coercion4.toLong(obj); 41 } 42 43 public Object defaultValue(){ 44 return i_primitive; 45 } 46 47 public int getID(){ 48 return 2; 49 } 50 51 protected Class primitiveJavaClass(){ 52 return long.class; 53 } 54 55 public int linkLength(){ 56 return YapConst.LONG_LENGTH; 57 } 58 59 Object primitiveNull(){ 60 return i_primitive; 61 } 62 63 Object read1(YapReader a_bytes){ 64 return new Long (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 a_object, YapReader a_bytes){ 88 writeLong(((Long )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 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 121 private long i_compareTo; 122 123 protected final long currentLong() { 124 return i_compareTo; 125 } 126 127 long val(Object obj){ 128 return ((Long )obj).longValue(); 129 } 130 131 void prepareComparison1(Object obj){ 132 i_compareTo = val(obj); 133 } 134 135 public Object current1(){ 136 return new Long (i_compareTo); 137 } 138 139 boolean isEqual1(Object obj){ 140 return obj instanceof Long && val(obj) == i_compareTo; 141 } 142 143 boolean isGreater1(Object obj){ 144 return obj instanceof Long && val(obj) > i_compareTo; 145 } 146 147 boolean isSmaller1(Object obj){ 148 return obj instanceof Long && val(obj) < i_compareTo; 149 } 150 151 } 152 | Popular Tags |