org.boon.slumberdb.entries.VersionedEntry Maven / Gradle / Ivy
package org.boon.slumberdb.entries;
import org.boon.concurrent.Timer;
import java.util.Map;
/**
* Created by Richard on 9/23/14.
*/
public class VersionedEntry extends Entry {
private long createTimestamp;
private long updateTimestamp;
private long version;
public VersionedEntry(){
}
public VersionedEntry(Map.Entry entry) {
super(entry);
}
public VersionedEntry(K k, V v) {
super(k, v);
}
public long updatedOn() {
return updateTimestamp;
}
public long version() {
return version;
}
public long createdOn() {
return createTimestamp;
}
public VersionedEntry setVersion(long version) {
this.version = version;
return this;
}
public VersionedEntry setCreateTimestamp(long createTimestamp) {
this.createTimestamp = createTimestamp;
return this;
}
public VersionedEntry setUpdateTimestamp(long updateTimestamp) {
this.updateTimestamp = updateTimestamp;
return this;
}
public VersionedEntry setVersionMeta(VersionKey versionMeta) {
if (versionMeta.version()==-1L) {
this.setVersion(0L);
} else {
this.setVersion(versionMeta.version());
}
if (versionMeta.createdOn()==-1) {
this.setCreateTimestamp(Timer.timer().now());
} else {
this.setCreateTimestamp(versionMeta.createdOn());
}
if (versionMeta.updatedOn()==-1) {
this.setUpdateTimestamp(Timer.timer().now());
} else {
this.setUpdateTimestamp(versionMeta.updatedOn());
}
return this;
}
@Override
public String toString() {
return "VersionedEntry{" +
"createTimestamp=" + createTimestamp +
", updateTimestamp=" + updateTimestamp +
", version=" + version +
"} " + super.toString();
}
public VersionedEntry value(V v) {
this.setValue(v);
return this;
}
}