
com.opencredo.concursus.domain.events.indexing.InMemoryTimestampedTable Maven / Gradle / Ivy
The newest version!
package com.opencredo.concursus.domain.events.indexing;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
final class InMemoryTimestampedTable> {
public static > InMemoryTimestampedTable create() {
return new InMemoryTimestampedTable<>(
new ConcurrentHashMap<>(),
InMemoryIndex.create()
);
}
private InMemoryTimestampedTable(Map> tableData, InMemoryIndex index) {
this.tableData = tableData;
this.index = index;
}
private final Map> tableData;
private final InMemoryIndex index;
public void update(K key, V value, T timestamp) {
TimestampedValue newTv = new TimestampedValue<>(timestamp, value);
tableData.compute(key, (k, oldTv) -> {
if (oldTv == null) {
index.add(value, key);
return newTv;
}
if (oldTv.isBefore(newTv)) {
index.remove(oldTv.getValue(), key);
index.add(value, key);
return newTv;
}
return oldTv;
});
}
public Set getIndexed(V value) {
return index.get(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy