示例#1
0
 @Override
 public Object read(ByteBuffer buff) {
   Object[] array = new Object[arrayLength];
   for (int i = 0; i < arrayLength; i++) {
     DataType t = elementTypes[i];
     if (buff.get() == 1) {
       array[i] = t.read(buff);
     }
   }
   return array;
 }
示例#2
0
 @Override
 public int getMemory(Object obj) {
   Object[] array = (Object[]) obj;
   int size = 0;
   for (int i = 0; i < arrayLength; i++) {
     DataType t = elementTypes[i];
     Object o = array[i];
     if (o != null) {
       size += t.getMemory(o);
     }
   }
   return size;
 }
示例#3
0
 @Override
 public ByteBuffer write(ByteBuffer buff, Object obj) {
   Object[] array = (Object[]) obj;
   for (int i = 0; i < arrayLength; i++) {
     DataType t = elementTypes[i];
     Object o = array[i];
     if (o == null) {
       buff.put((byte) 0);
     } else {
       buff.put((byte) 1);
       buff = t.write(buff, o);
     }
   }
   return buff;
 }
示例#4
0
 @Override
 public int compare(Object aObj, Object bObj) {
   if (aObj == bObj) {
     return 0;
   }
   Object[] a = (Object[]) aObj;
   Object[] b = (Object[]) bObj;
   for (int i = 0; i < arrayLength; i++) {
     DataType t = elementTypes[i];
     int comp = t.compare(a[i], b[i]);
     if (comp != 0) {
       return comp;
     }
   }
   return 0;
 }
示例#5
0
 /**
  * Check whether the two values are equal.
  *
  * @param a the first value
  * @param b the second value
  * @return true if they are equal
  */
 public boolean areValuesEqual(Object a, Object b) {
   if (a == b) {
     return true;
   } else if (a == null || b == null) {
     return false;
   }
   return valueType.compare(a, b) == 0;
 }
示例#6
0
 /**
  * Compare two keys.
  *
  * @param a the first key
  * @param b the second key
  * @return -1 if the first key is smaller, 1 if bigger, 0 if equal
  */
 int compare(Object a, Object b) {
   return keyType.compare(a, b);
 }