1 21 package com.db4o; 22 23 26 public abstract class YapTypeAbstract extends YapJavaClass implements YapType{ 27 28 public YapTypeAbstract(YapStream stream) { 29 super(stream); 30 } 31 32 private int i_linkLength; 33 34 private Object i_compareTo; 35 36 public abstract int compare(Object compare, Object with); 37 38 public String dotNetClassName(){ 39 String className = this.getClass().getName(); 40 int pos = className.indexOf(".Net") ; 41 if(pos >=0){ 42 return "System." + className.substring(pos + 4) + ", mscorlib"; 43 } 44 return defaultValue().getClass().getName(); 45 } 46 47 public abstract boolean isEqual(Object compare, Object with); 48 49 void initialize(){ 50 byte[] bytes = new byte[65]; 51 for (int i = 0; i < bytes.length; i++) { 52 bytes[i] = 55; } 54 write(primitiveNull(), bytes, 0); 55 for (int i = 0; i < bytes.length; i++) { 56 if(bytes[i] == 55){ 57 i_linkLength = i; 58 break; 59 } 60 } 61 } 62 63 public int getID() { 64 return typeID(); 65 } 66 67 public String getName() { 71 return dotNetClassName(); 72 } 73 74 public int linkLength() { 75 return i_linkLength; 76 } 77 78 protected Class primitiveJavaClass(){ 79 return null; 80 } 81 82 Object primitiveNull() { 83 return defaultValue(); 84 } 85 86 public abstract Object read(byte[] bytes, int offset); 87 88 Object read1(YapReader a_bytes) throws CorruptionException { 89 int offset = a_bytes._offset; 90 Object ret = read(a_bytes._buffer, a_bytes._offset); 91 a_bytes._offset = offset + linkLength(); 92 return ret; 93 } 94 95 public abstract int typeID(); 96 97 public abstract void write(Object obj, byte[] bytes, int offset); 98 99 public void write(Object a_object, YapReader a_bytes) { 100 int offset = a_bytes._offset; 101 if(a_object != null){ 102 write(a_object, a_bytes._buffer, a_bytes._offset); 103 } 104 a_bytes._offset = offset + linkLength(); 105 } 106 107 void prepareComparison1(Object obj) { 108 i_compareTo = obj; 109 } 110 111 public Object current1(){ 112 return i_compareTo; 113 } 114 115 boolean isEqual1(Object obj) { 116 return isEqual(i_compareTo, obj); 117 } 118 119 boolean isGreater1(Object obj) { 120 if(classReflector().isInstance(obj) && ! isEqual(i_compareTo, obj)){ 121 return compare(i_compareTo, obj) > 0; 122 } 123 return false; 124 } 125 126 boolean isSmaller1(Object obj) { 127 if(classReflector().isInstance(obj) && ! isEqual(i_compareTo, obj)){ 128 return compare(i_compareTo, obj) < 0; 129 } 130 return false; 131 } 132 } 133 | Popular Tags |