org.mapdb.serializer.SerializerDate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapdb Show documentation
Show all versions of mapdb Show documentation
MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap memory. It is a fast, scalable and easy to use embedded Java database.
package org.mapdb.serializer;
import org.mapdb.DataInput2;
import org.mapdb.DataOutput2;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
/**
* Created by jan on 2/28/16.
*/
public class SerializerDate extends SerializerEightByte {
@Override
public void serialize(DataOutput2 out, Date value) throws IOException {
out.writeLong(value.getTime());
}
@Override
public Date deserialize(DataInput2 in, int available) throws IOException {
return new Date(in.readLong());
}
@Override
protected Date unpack(long l) {
return new Date(l);
}
@Override
protected long pack(Date l) {
return l.getTime();
}
@Override
final public int valueArraySearch(Object keys, Date key) {
//TODO valueArraySearch versus comparator test
long time = key.getTime();
return Arrays.binarySearch((long[])keys, time);
}
}