Class DiskMap<K,​V>

  • Type Parameters:
    K - the key type parameter
    V - 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 and close 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 Detail

      • clear

        public void clear()
        Specified by:
        clear in interface Map<K,​V>
      • commit

        public void commit()
        Commits any changes made to disk.
      • get

        public V get​(Object o)
        Specified by:
        get in interface Map<K,​V>
      • getHandle

        public MapDBHandle getHandle()
        Gets the MapDBHandle that manages the map database
        Returns:
        the handle
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Map<K,​V>
      • keySet

        public Set<K> keySet()
        Specified by:
        keySet in interface Map<K,​V>
      • put

        public V put​(K k,
                     V v)
        Specified by:
        put in interface Map<K,​V>
      • putAll

        public void putAll​(Map<? extends K,​? extends V> map)
        Specified by:
        putAll in interface Map<K,​V>
      • size

        public int size()
        Specified by:
        size in interface Map<K,​V>