Package com.gengoai.collection.disk
Class DiskMap<K,V>
- java.lang.Object
-
- com.gengoai.collection.disk.DiskMap<K,V>
-
- Type Parameters:
K
- the key type parameterV
- the value type parameter
- All Implemented Interfaces:
Serializable
,AutoCloseable
,Map<K,V>
public class DiskMap<K,V> extends Object implements Map<K,V>, AutoCloseable, Serializable
A Map implementation that stores its data in a file. Each map file can contain multiple maps where each map is stored in a namespace represented by a unique String name. DiskMaps are monitored to ensure that their file handle is properly closed if the it is no longer in use. However, one can use the
commit
andclose
methods to explicitly commit changes and close the map.DiskMaps are created using a builder in the following way:
var map = DiskMap.builder() .file(Resources.from("/data/map.db") .namespace("people") .compressed(true) .build();
Once an DiskMap instance is constructed it acts like regular Java Map.
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
void
close()
void
commit()
Commits any changes made to disk.boolean
containsKey(Object o)
boolean
containsValue(Object o)
Set<Map.Entry<K,V>>
entrySet()
V
get(Object o)
MapDBHandle
getHandle()
Gets theMapDBHandle
that manages the map databaseboolean
isEmpty()
Set<K>
keySet()
V
put(K k, V v)
void
putAll(Map<? extends K,? extends V> map)
V
remove(Object o)
int
size()
Collection<V>
values()
-
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
-
-
-
-
Method Detail
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
commit
public void commit()
Commits any changes made to disk.
-
containsKey
public boolean containsKey(Object o)
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object o)
- Specified by:
containsValue
in interfaceMap<K,V>
-
getHandle
public MapDBHandle getHandle()
Gets theMapDBHandle
that manages the map database- Returns:
- the handle
-
-