Class KVStore

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.Object>, org.api4.java.datastructure.kvstore.IKVStore
    Direct Known Subclasses:
    OptionsParser

    public class KVStore
    extends java.util.HashMap<java.lang.String,​java.lang.Object>
    implements org.api4.java.datastructure.kvstore.IKVStore, java.io.Serializable
    A KVStore can be used to store arbitrary objects for some string key. The KVStore allows for more convenient data access and some basic operations. Within KVStoreCollections it can be subject to significance tests and it may be transformed into a table representation.
    See Also:
    Serialized Form
    • 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
      KVStore()
      Standard c'tor creating an empty KV store.
      KVStore​(java.lang.String stringRepresentation)
      C'tor creating a KV store loading the data from the provided string representation.
      KVStore​(java.util.Map<java.lang.String,​java.lang.Object> keyValueMap)
      C'tor for creating a shallow copy of another KeyValueStore or to initialize with the provided keyValueMap.
      KVStore​(org.api4.java.datastructure.kvstore.IKVStore keyValueStoreToCopy)
      C'tor for making a deep copy of another KVStore.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      void filter​(java.lang.String key, org.api4.java.datastructure.kvstore.IKVFilter filter)  
      void filter​(java.util.Map<java.lang.String,​org.api4.java.datastructure.kvstore.IKVFilter> filterMap)  
      java.lang.Boolean getAsBoolean​(java.lang.String key)  
      java.util.List<java.lang.Boolean> getAsBooleanList​(java.lang.String key)  
      java.util.List<java.lang.Boolean> getAsBooleanList​(java.lang.String key, java.lang.String separator)  
      java.lang.Byte getAsByte​(java.lang.String key)  
      byte[] getAsBytes​(java.lang.String columnClassifierObject)  
      java.lang.Double getAsDouble​(java.lang.String key)  
      java.util.List<java.lang.Double> getAsDoubleList​(java.lang.String key)  
      java.util.List<java.lang.Double> getAsDoubleList​(java.lang.String key, java.lang.String separator)  
      java.io.File getAsFile​(java.lang.String key)  
      java.lang.Integer getAsInt​(java.lang.String key)  
      java.util.List<java.lang.Integer> getAsIntList​(java.lang.String key)  
      java.util.List<java.lang.Integer> getAsIntList​(java.lang.String key, java.lang.String separator)  
      java.lang.Long getAsLong​(java.lang.String key)  
      <T> T getAsObject​(java.lang.String key, java.lang.Class<T> objectClass)  
      java.lang.Short getAsShort​(java.lang.String key)  
      java.lang.String getAsString​(java.lang.String key)  
      java.util.List<java.lang.String> getAsStringList​(java.lang.String key)  
      java.util.List<java.lang.String> getAsStringList​(java.lang.String key, java.lang.String separator)  
      KVStoreCollection getCollection()  
      java.lang.String getStringRepresentation​(java.lang.String[] projectionFilter)
      Allows to get a string representation of this KVStore incorporating only key value pairs for the named
      int hashCode()  
      boolean isNull​(java.lang.String key)  
      boolean matches​(java.util.Map<java.lang.String,​java.lang.String> selection)  
      void merge​(java.lang.String[] fieldKeys, java.lang.String separator, java.lang.String newKey)  
      void prefixAllKeys​(java.lang.String prefix)  
      void project​(java.lang.String[] filterKeys)  
      void readKVStoreFromDescription​(java.lang.String kvDescription)
      Reads a KVStore from a string description.
      void removeAll​(java.lang.String[] removeKeys)  
      void renameKey​(java.lang.String key, java.lang.String newKeyName)  
      void serializeTo​(java.io.File file)
      Serializes the key value store to the file with the given fileName.
      void serializeTo​(java.lang.String fileName)
      Serializes the key value store to a file with the given fileName.
      void setCollection​(KVStoreCollection collection)
      Assigns the KVStore to a KVStoreCollection.
      java.lang.String toString()  
      • Methods inherited from class java.util.HashMap

        clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
      • Methods inherited from class java.lang.Object

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

        clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
    • Constructor Detail

      • KVStore

        public KVStore()
        Standard c'tor creating an empty KV store.
      • KVStore

        public KVStore​(java.lang.String stringRepresentation)
        C'tor creating a KV store loading the data from the provided string representation.
        Parameters:
        stringRepresentation - A string formatted key value store to be restored.
      • KVStore

        public KVStore​(java.util.Map<java.lang.String,​java.lang.Object> keyValueMap)
        C'tor for creating a shallow copy of another KeyValueStore or to initialize with the provided keyValueMap.
        Parameters:
        keyValueMap - Map of keys and values to initialize this KeyValueStore with.
      • KVStore

        public KVStore​(org.api4.java.datastructure.kvstore.IKVStore keyValueStoreToCopy)
        C'tor for making a deep copy of another KVStore.
        Parameters:
        keyValueStoreToCopy - The KVStore to make a deep copy from.
    • Method Detail

      • getAsString

        public java.lang.String getAsString​(java.lang.String key)
        Specified by:
        getAsString in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsBoolean

        public java.lang.Boolean getAsBoolean​(java.lang.String key)
        Specified by:
        getAsBoolean in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsInt

        public java.lang.Integer getAsInt​(java.lang.String key)
        Specified by:
        getAsInt in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsDouble

        public java.lang.Double getAsDouble​(java.lang.String key)
        Specified by:
        getAsDouble in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsLong

        public java.lang.Long getAsLong​(java.lang.String key)
        Specified by:
        getAsLong in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsShort

        public java.lang.Short getAsShort​(java.lang.String key)
        Specified by:
        getAsShort in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsByte

        public java.lang.Byte getAsByte​(java.lang.String key)
        Specified by:
        getAsByte in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsObject

        public <T> T getAsObject​(java.lang.String key,
                                 java.lang.Class<T> objectClass)
                          throws java.lang.InstantiationException,
                                 java.lang.IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException,
                                 java.lang.NoSuchMethodException
        Specified by:
        getAsObject in interface org.api4.java.datastructure.kvstore.IKVStore
        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
        java.lang.NoSuchMethodException
      • getAsBytes

        public byte[] getAsBytes​(java.lang.String columnClassifierObject)
        Specified by:
        getAsBytes in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsDoubleList

        public java.util.List<java.lang.Double> getAsDoubleList​(java.lang.String key)
        Specified by:
        getAsDoubleList in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsDoubleList

        public java.util.List<java.lang.Double> getAsDoubleList​(java.lang.String key,
                                                                java.lang.String separator)
        Specified by:
        getAsDoubleList in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsIntList

        public java.util.List<java.lang.Integer> getAsIntList​(java.lang.String key)
        Specified by:
        getAsIntList in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsIntList

        public java.util.List<java.lang.Integer> getAsIntList​(java.lang.String key,
                                                              java.lang.String separator)
        Specified by:
        getAsIntList in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsStringList

        public java.util.List<java.lang.String> getAsStringList​(java.lang.String key)
        Specified by:
        getAsStringList in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsStringList

        public java.util.List<java.lang.String> getAsStringList​(java.lang.String key,
                                                                java.lang.String separator)
        Specified by:
        getAsStringList in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsBooleanList

        public java.util.List<java.lang.Boolean> getAsBooleanList​(java.lang.String key)
        Specified by:
        getAsBooleanList in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsBooleanList

        public java.util.List<java.lang.Boolean> getAsBooleanList​(java.lang.String key,
                                                                  java.lang.String separator)
        Specified by:
        getAsBooleanList in interface org.api4.java.datastructure.kvstore.IKVStore
      • getAsFile

        public java.io.File getAsFile​(java.lang.String key)
        Specified by:
        getAsFile in interface org.api4.java.datastructure.kvstore.IKVStore
      • readKVStoreFromDescription

        public void readKVStoreFromDescription​(java.lang.String kvDescription)
        Reads a KVStore from a string description.
        Parameters:
        kvDescription - The string description of the kv store.
      • matches

        public boolean matches​(java.util.Map<java.lang.String,​java.lang.String> selection)
        Specified by:
        matches in interface org.api4.java.datastructure.kvstore.IKVStore
      • project

        public void project​(java.lang.String[] filterKeys)
        Specified by:
        project in interface org.api4.java.datastructure.kvstore.IKVStore
      • removeAll

        public void removeAll​(java.lang.String[] removeKeys)
        Specified by:
        removeAll in interface org.api4.java.datastructure.kvstore.IKVStore
      • filter

        public void filter​(java.util.Map<java.lang.String,​org.api4.java.datastructure.kvstore.IKVFilter> filterMap)
        Specified by:
        filter in interface org.api4.java.datastructure.kvstore.IKVStore
      • filter

        public void filter​(java.lang.String key,
                           org.api4.java.datastructure.kvstore.IKVFilter filter)
        Specified by:
        filter in interface org.api4.java.datastructure.kvstore.IKVStore
      • serializeTo

        public void serializeTo​(java.lang.String fileName)
                         throws java.io.IOException
        Serializes the key value store to a file with the given fileName.
        Parameters:
        fileName - The name of the file, the key value store shall be serialized to.
        Throws:
        java.io.IOException
      • serializeTo

        public void serializeTo​(java.io.File file)
                         throws java.io.IOException
        Serializes the key value store to the file with the given fileName.
        Parameters:
        fileName - The name of the file, the key value store shall be serialized to.
        Throws:
        java.io.IOException
      • merge

        public void merge​(java.lang.String[] fieldKeys,
                          java.lang.String separator,
                          java.lang.String newKey)
        Specified by:
        merge in interface org.api4.java.datastructure.kvstore.IKVStore
      • prefixAllKeys

        public void prefixAllKeys​(java.lang.String prefix)
        Specified by:
        prefixAllKeys in interface org.api4.java.datastructure.kvstore.IKVStore
      • renameKey

        public void renameKey​(java.lang.String key,
                              java.lang.String newKeyName)
        Specified by:
        renameKey in interface org.api4.java.datastructure.kvstore.IKVStore
      • getCollection

        public KVStoreCollection getCollection()
        Returns:
        Get the collection this KVStore belongs to.
      • setCollection

        public void setCollection​(KVStoreCollection collection)
        Assigns the KVStore to a KVStoreCollection.
        Parameters:
        collection - The collection this KVStore belongs to.
      • getStringRepresentation

        public java.lang.String getStringRepresentation​(java.lang.String[] projectionFilter)
        Allows to get a string representation of this KVStore incorporating only key value pairs for the named
        Parameters:
        projectionFilter -
        Returns:
      • toString

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

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<java.lang.String,​java.lang.Object>
        Overrides:
        hashCode in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Map<java.lang.String,​java.lang.Object>
        Overrides:
        equals in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
      • isNull

        public boolean isNull​(java.lang.String key)
        Specified by:
        isNull in interface org.api4.java.datastructure.kvstore.IKVStore