Package com.github.dagnelies.filemap
Class IndexedFileMap<K,V>
- java.lang.Object
-
- com.github.dagnelies.filemap.AbstractFileMap<K,V>
-
- com.github.dagnelies.filemap.IndexedFileMap<K,V>
-
- Type Parameters:
K-V-
public class IndexedFileMap<K,V> extends AbstractFileMap<K,V>
This thread safe hash map stores its key/values on disk. Only the keys are are in memory, along with the value's position in the file. This allows to store much more data than would normally fit in memory. Each insertion/update/removal is saved to the file in a readable JSON format. 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)Iterable<AbstractFileMap.LineEntry>entries()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
-
IndexedFileMap
public IndexedFileMap(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()
-
entries
public Iterable<AbstractFileMap.LineEntry> entries()
-
-