Package com.github.dagnelies.filemap
Class CachedFileMap<K,V>
- java.lang.Object
-
- com.github.dagnelies.filemap.AbstractFileMap<K,V>
-
- com.github.dagnelies.filemap.CachedFileMap<K,V>
-
- Type Parameters:
K-V-
public class CachedFileMap<K,V> extends AbstractFileMap<K,V>
This thread safe hash map is stored both in memory and on disk. Each insertion/update/removal is saved to the file in a readable JSON format. This offers high throughput, together with crash-safe file persistence. Note that the file works like a log and old entries are not "removed". They will only be overridden. This means that the file only grows.- Author:
- dagnelies
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.dagnelies.filemap.AbstractFileMap
AbstractFileMap.LineEntry
-
-
Field Summary
-
Fields inherited from class com.github.dagnelies.filemap.AbstractFileMap
file, fileio
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<K,V>>entrySet()Vget(Object key)protected voidinit()booleanisEmpty()Set<K>keySet()protected voidloadEntry(long offset, String line)Vput(K key, V value)Vremove(Object key)intsize()Collection<V>values()-
Methods inherited from class com.github.dagnelies.filemap.AbstractFileMap
clearLines, close, diskSize, getEntriesWritten, getFile, getFragmentation, parseKey, parseLine, parseValue, putAll, readLine, writeLine
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
CachedFileMap
public CachedFileMap(File file, Class<K> keyType, Class<V> valueType) throws IOException
- Throws:
IOException
-
-
Method Detail
-
init
protected void init() throws IOException- Specified by:
initin classAbstractFileMap<K,V>- Throws:
IOException
-
loadEntry
protected void loadEntry(long offset, String line) throws IOException- Specified by:
loadEntryin classAbstractFileMap<K,V>- Throws:
IOException
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
containsKey
public boolean containsKey(Object key)
-
containsValue
public boolean containsValue(Object value)
-
clear
public void clear()
-
values
public Collection<V> values()
-
-