Class PersistentMap<V>

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.util.Map<java.lang.String,​V>

    public class PersistentMap<V>
    extends java.util.AbstractMap<java.lang.String,​V>
    implements java.io.Closeable
    Implements a low performance but easy to use map that is backed on a directory. All objects are stored as JSON objects and therefore should be DTOs. Each key is a file name and the contents is the value encoded in JSON. The PersistentMap will attempt to lock the directory. This is a non-concurrent implementation so you must ensure it is only used in a single thread. It cannot of course also not share the data directory.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      PersistentMap​(java.io.File dir, java.lang.Class<V> type)  
      PersistentMap​(java.io.File dir, java.lang.Class<V> type, java.util.Map<java.lang.String,​V> map)  
      PersistentMap​(java.io.File dir, java.lang.reflect.Type type)  
      PersistentMap​(java.io.File dir, java.lang.reflect.Type type, java.util.Map<java.lang.String,​V> map)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      void clear​(long whenOlder)  
      void close()  
      java.util.Set<java.util.Map.Entry<java.lang.String,​V>> entrySet()  
      java.util.Set<java.lang.String> keySet()  
      V put​(java.lang.String key, V value)  
      V remove​(java.lang.String key)  
      java.lang.String toString()  
      • Methods inherited from class java.util.AbstractMap

        clone, containsKey, containsValue, equals, get, hashCode, isEmpty, putAll, remove, size, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • PersistentMap

        public PersistentMap​(java.io.File dir,
                             java.lang.reflect.Type type)
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • PersistentMap

        public PersistentMap​(java.io.File dir,
                             java.lang.Class<V> type)
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • PersistentMap

        public PersistentMap​(java.io.File dir,
                             java.lang.Class<V> type,
                             java.util.Map<java.lang.String,​V> map)
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • PersistentMap

        public PersistentMap​(java.io.File dir,
                             java.lang.reflect.Type type,
                             java.util.Map<java.lang.String,​V> map)
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
    • Method Detail

      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.String,​V>
        Specified by:
        entrySet in class java.util.AbstractMap<java.lang.String,​V>
      • put

        public V put​(java.lang.String key,
                     V value)
        Specified by:
        put in interface java.util.Map<java.lang.String,​V>
        Overrides:
        put in class java.util.AbstractMap<java.lang.String,​V>
      • remove

        public V remove​(java.lang.String key)
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,​V>
        Overrides:
        clear in class java.util.AbstractMap<java.lang.String,​V>
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.String,​V>
        Overrides:
        keySet in class java.util.AbstractMap<java.lang.String,​V>
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractMap<java.lang.String,​V>
      • clear

        public void clear​(long whenOlder)