Class IndexedMap<Value extends Storable>

java.lang.Object
com.codingchili.core.storage.IndexedMap<Value>
Type Parameters:
Value - the value that is stored in the collection.
All Implemented Interfaces:
AsyncStorage<Value>
Direct Known Subclasses:
IndexedMapPersisted, IndexedMapVolatile

public abstract class IndexedMap<Value extends Storable> extends Object implements AsyncStorage<Value>
Implementation of the in-memory/disk indexed collections using CQEngine.

Common base class used for both in-memory and disk storage.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    protected com.googlecode.cqengine.IndexedCollection<Value>
     
    protected com.googlecode.cqengine.attribute.SimpleAttribute<Value,​String>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    IndexedMap​(Function<com.googlecode.cqengine.attribute.SimpleAttribute<Value,​String>,​com.googlecode.cqengine.IndexedCollection<Value>> supplier, StorageContext<Value> context)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addIndex​(String fieldName)
     
    protected abstract void
    addIndexesForAttribute​(com.googlecode.cqengine.attribute.Attribute<Value,​String> attribute)
     
    void
    clear​(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
    removes all existing entries from the storage.
    Get the context for the storage.
    void
    get​(String key, io.vertx.core.Handler<io.vertx.core.AsyncResult<Value>> handler)
    get an entry with the given key, if the key does not match a value fails with #ValueMissingException
    com.googlecode.cqengine.attribute.Attribute<Value,​String>
    getAttribute​(String fieldName, boolean multiValue)
     
    com.googlecode.cqengine.IndexedCollection<Value>
     
    void
    put​(Value value, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
    set the entry identified by the given key to the given value
    void
    putIfAbsent​(Value value, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
    set the entry if it does not already exists.
    initialize the construction of a query.
    void
    remove​(String key, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
    Removes an entry by its key.
    void
    setMapper​(Function<Value,​Value> mapper)
     
    void
    size​(io.vertx.core.Handler<io.vertx.core.AsyncResult<Integer>> handler)
    returns the amount of entries in the storage.
    void
    update​(Value value, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
    updates the value of the given key if a value already exists.
    void
    values​(io.vertx.core.Handler<io.vertx.core.AsyncResult<Stream<Value>>> handler)
    Get all values contained within the storage as a stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.codingchili.core.storage.AsyncStorage

    contains, query
  • Field Details

  • Constructor Details

  • Method Details

    • getDatabase

      public com.googlecode.cqengine.IndexedCollection<Value> getDatabase()
    • getAttribute

      public com.googlecode.cqengine.attribute.Attribute<Value,​String> getAttribute(String fieldName, boolean multiValue)
    • addIndex

      public void addIndex(String fieldName)
      Specified by:
      addIndex in interface AsyncStorage<Value extends Storable>
      Parameters:
      fieldName - the path to the attribute to index, must include the array token in #CoreStrings.STORAGE_ARRAY.
    • addIndexesForAttribute

      protected abstract void addIndexesForAttribute(com.googlecode.cqengine.attribute.Attribute<Value,​String> attribute)
      Parameters:
      attribute - the attribute to add an index for based on implementation.
    • setMapper

      public void setMapper(Function<Value,​Value> mapper)
      Parameters:
      mapper - a mapper that is executed on all values returned from the map.
    • get

      public void get(String key, io.vertx.core.Handler<io.vertx.core.AsyncResult<Value>> handler)
      Description copied from interface: AsyncStorage
      get an entry with the given key, if the key does not match a value fails with #ValueMissingException
      Specified by:
      get in interface AsyncStorage<Value extends Storable>
      Parameters:
      key - a unique key identifying an entry
      handler - callback
    • put

      public void put(Value value, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
      Description copied from interface: AsyncStorage
      set the entry identified by the given key to the given value
      Specified by:
      put in interface AsyncStorage<Value extends Storable>
      Parameters:
      value - the value to be set for the given key
      handler - callback
    • putIfAbsent

      public void putIfAbsent(Value value, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
      Description copied from interface: AsyncStorage
      set the entry if it does not already exists. fails with #ValueAlreadyPresentException if the key already has a value.
      Specified by:
      putIfAbsent in interface AsyncStorage<Value extends Storable>
      Parameters:
      value - the value to be set if the entry does not exist.
      handler - callback
    • remove

      public void remove(String key, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
      Description copied from interface: AsyncStorage
      Removes an entry by its key.
      Specified by:
      remove in interface AsyncStorage<Value extends Storable>
      Parameters:
      key - identifies the entry to be removed.
      handler - callback
    • update

      public void update(Value value, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
      Description copied from interface: AsyncStorage
      updates the value of the given key if a value already exists.
      Specified by:
      update in interface AsyncStorage<Value extends Storable>
      Parameters:
      value - the new value of the entry
      handler - callback
    • values

      public void values(io.vertx.core.Handler<io.vertx.core.AsyncResult<Stream<Value>>> handler)
      Description copied from interface: AsyncStorage
      Get all values contained within the storage as a stream. Not recommended to use on large maps.
      Specified by:
      values in interface AsyncStorage<Value extends Storable>
      Parameters:
      handler - callback
    • clear

      public void clear(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
      Description copied from interface: AsyncStorage
      removes all existing entries from the storage.
      Specified by:
      clear in interface AsyncStorage<Value extends Storable>
      Parameters:
      handler - callback
    • size

      public void size(io.vertx.core.Handler<io.vertx.core.AsyncResult<Integer>> handler)
      Description copied from interface: AsyncStorage
      returns the amount of entries in the storage.
      Specified by:
      size in interface AsyncStorage<Value extends Storable>
      Parameters:
      handler - callback
    • query

      public QueryBuilder<Value> query()
      Description copied from interface: AsyncStorage
      initialize the construction of a query.
      Specified by:
      query in interface AsyncStorage<Value extends Storable>
      Returns:
      a builder String for constructing the query.
    • context

      public StorageContext<Value> context()
      Description copied from interface: AsyncStorage
      Get the context for the storage.
      Specified by:
      context in interface AsyncStorage<Value extends Storable>
      Returns:
      a storage context.