org.bigraphs.spring.data.cdo.CDORevisionHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-data-cdo Show documentation
Show all versions of spring-data-cdo Show documentation
CDO support for Spring Data
package org.bigraphs.spring.data.cdo;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* @author Dominik Grzelak
*/
public class CDORevisionHolder {
final ConcurrentHashMap revisionMap = new ConcurrentHashMap<>();
private CDORevisionHolder() {
}
public int getRevisionCount() {
return revisionMap.size();
}
public static CDORevisionHolder create() {
return new CDORevisionHolder<>();
}
public Optional getByVersion(int version) {
return revisionMap.entrySet().stream()
.filter(e -> e.getKey().version.equals(version))
.map(Map.Entry::getValue)
.findFirst();
}
public Optional getCDORevisionByVersion(int version) {
return revisionMap.keySet().stream()
.filter(t -> t.version.equals(version))
.map(t -> t.cdoRevision)
.findFirst();
}
public List getByTimeStamp(Long timestamp) {
return revisionMap.entrySet().stream()
.filter(e -> e.getKey().timestamp.equals(timestamp))
.map(Map.Entry::getValue)
.collect(Collectors.toList());
}
void add(T internalValue, CDORevision cdoRevision) {
revisionMap.put(
new RevisionSlot(cdoRevision.getTimeStamp(), cdoRevision.getVersion(), cdoRevision),
internalValue
);
}
public static class RevisionSlot {
private final Long timestamp;
private final Integer version;
private final CDORevision cdoRevision;
private RevisionSlot(Long timestamp, Integer version, CDORevision cdoRevision) {
this.timestamp = timestamp;
this.version = version;
this.cdoRevision = cdoRevision;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy