1 21 package com.db4o; 22 23 import com.db4o.foundation.*; 24 import com.db4o.reflect.ReflectClass; 25 26 27 30 public class YInt extends YapJavaClass { 31 32 private static final Integer i_primitive = new Integer (0); 33 34 public YInt(YapStream stream) { 35 super(stream); 36 } 37 38 public Object coerce(ReflectClass claxx, Object obj) { 39 return Coercion4.toInt(obj); 40 } 41 42 public Object defaultValue(){ 43 return i_primitive; 44 } 45 46 public int getID() { 47 return 1; 48 } 49 50 protected Class primitiveJavaClass() { 51 return int.class; 52 } 53 54 public int linkLength() { 55 return YapConst.INT_LENGTH; 56 } 57 58 public static int max(int x, int y){ 59 return (x < y) ? y : x; 60 } 61 62 Object primitiveNull() { 63 return i_primitive; 64 } 65 66 Object read1(YapReader a_bytes) { 67 return new Integer (a_bytes.readInt()); 68 } 69 70 static final int readInt(YapReader a_bytes) { 71 if (Deploy.debug) { 72 int ret = 0; 73 a_bytes.readBegin(YapConst.YAPINTEGER); 74 if (Deploy.debugLong) { 75 ret = 76 Integer.valueOf(new YapStringIO().read(a_bytes, YapConst.INTEGER_BYTES).trim()) 77 .intValue(); 78 } else { 79 for (int i = 0; i < YapConst.INTEGER_BYTES; i++) { 80 ret = (ret << 8) + (a_bytes._buffer[a_bytes._offset++] & 0xff); 81 } 82 } 83 a_bytes.readEnd(); 84 return ret; 85 } 86 return a_bytes.readInt(); 87 } 88 89 public void write(Object obj, YapReader writer) { 90 write(((Integer ) obj).intValue(), writer); 91 } 92 93 public void write(int intValue, YapReader writer) { 94 writeInt(intValue, writer); 95 } 96 97 static final void writeInt(int a_int, YapReader a_bytes) { 98 if (Deploy.debug) { 99 a_bytes.writeBegin(YapConst.YAPINTEGER); 100 if (Deploy.debugLong) { 101 String l_s = " " + new Integer (a_int).toString(); 102 new YapStringIO().write( 103 a_bytes, 104 l_s.substring(l_s.length() - YapConst.INTEGER_BYTES)); 105 } else { 106 for (int i = YapConst.WRITE_LOOP; i >= 0; i -= 8) { 107 a_bytes._buffer[a_bytes._offset++] = (byte) (a_int >> i); 108 } 109 } 110 a_bytes.writeEnd(); 111 } else { 112 a_bytes.writeInt(a_int); 113 } 114 } 115 116 118 private int i_compareTo; 119 120 protected final int val(Object obj) { 121 return ((Integer ) obj).intValue(); 122 } 123 124 public int compareTo(int other){ 125 return other - i_compareTo; 126 } 127 128 public void prepareComparison(int i) { 129 i_compareTo = i; 130 } 131 132 void prepareComparison1(Object obj) { 133 prepareComparison(val(obj)); 134 } 135 136 public Object current1(){ 137 return new Integer (currentInt()); 138 } 139 140 public int currentInt(){ 141 return i_compareTo; 142 } 143 144 boolean isEqual1(Object obj) { 145 return obj instanceof Integer && val(obj) == i_compareTo; 146 } 147 148 boolean isGreater1(Object obj) { 149 return obj instanceof Integer && val(obj) > i_compareTo; 150 } 151 152 boolean isSmaller1(Object obj) { 153 return obj instanceof Integer && val(obj) < i_compareTo; 154 } 155 156 public void defragIndexEntry(ReaderPair readers) { 157 readers.incrementIntSize(); 158 } 159 } | Popular Tags |