org.pepsoft.util.undo.Snapshot Maven / Gradle / Ivy
The newest version!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.pepsoft.util.undo;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author pepijn
*/
public final class Snapshot {
Snapshot(UndoManager undoManager, int frame) {
this.undoManager = undoManager;
this.frame = frame;
}
@SuppressWarnings("unchecked")
public T getBuffer(BufferKey key) {
if (frame == -1) {
throw new IllegalStateException("Undo history frame no longer available");
}
if (bufferCache.containsKey(key)) {
if (logger.isDebugEnabled()) {
logger.debug("Getting buffer " + key + " for reading from buffer cache");
}
return (T) bufferCache.get(key);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Getting buffer " + key + " for reading from history");
}
T buffer = undoManager.findMostRecentCopy(key, frame);
bufferCache.put(key, buffer);
return buffer;
}
}
private final UndoManager undoManager;
int frame;
private final Map, Object> bufferCache = new HashMap<>();
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Snapshot.class);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy