@Override public int getMemory(Object obj) { StorageDataType t = getType(obj); if (t == this) { return averageSize; } return t.getMemory(obj); }
@Override public void writeValue(DataBuffer buff, Value v) { throw newInternalError(); }
@SuppressWarnings("unchecked") @Override public int compare(Object aObj, Object bObj) { if (aObj == bObj) { return 0; } StorageDataType ta = getType(aObj); StorageDataType tb = getType(bObj); if (ta != this || tb != this) { if (ta == tb) { return ta.compare(aObj, bObj); } } // TODO ensure comparable type (both may be comparable but not // with each other) if (aObj instanceof Comparable) { if (aObj.getClass().isAssignableFrom(bObj.getClass())) { return ((Comparable<Object>) aObj).compareTo(bObj); } } if (bObj instanceof Comparable) { if (bObj.getClass().isAssignableFrom(aObj.getClass())) { return -((Comparable<Object>) bObj).compareTo(aObj); } } byte[] a = serialize(aObj); byte[] b = serialize(bObj); return ObjectDataType.compareNotNull(a, b); }
@Override public Object read(ByteBuffer buff, int tag) { int len = DataUtils.readVarInt(buff); byte[] data = DataUtils.newBytes(len); buff.get(data); return deserialize(data); }
return new ObjectArrayType(); case TYPE_SERIALIZED_OBJECT: return new SerializedObjectType();
@Override public void write(DataBuffer buff, Object obj) { StorageDataType t = getType(obj); if (t != this) { t.write(buff, obj); return; } byte[] data = serialize(obj); // we say they are larger, because these objects // use quite a lot of disk space int size = data.length * 2; // adjust the average size // using an exponential moving average averageSize = (size + 15 * averageSize) / 16; buff.put((byte) TYPE_SERIALIZED_OBJECT).putVarInt(data.length).put(data); }