package com.codingchili.core.storage;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

import java.util.Collection;

/**
 * @author Robin Duda
 *         <p>
 *         Reuses the AsyncMap interface from hazelcast.
 */
public interface AsyncStorage<Key, Value> {

    /**
     * get an entry with the given key
     * @param key a unique key identifying an entry
     */
    void get(Key key, Handler<AsyncResult<Value>> handler);

    /**
     * set the entry identified by the given key to the given value
     * @param key a key to uniquely identify the entry
     * @param value the value to be set for the given key
     */
    void put(Key key, Value value, Handler<AsyncResult<Void>> handler);

    /**
     * set the entry identified by the given key to the given value
     * @param key a key to uniquely identify the entry
     * @param value the value to be set for the given key
     * @param ttl the time to live for the entry
     */
    void put(Key key, Value value, long ttl, Handler<AsyncResult<Void>> handler);

    /**
     * set the entry if it does not already exists
     * @param key used to check if the entry exists and to set the value for.
     * @param value the value to be set if the entry does not exist.
     */
    void putIfAbsent(Key key, Value value, Handler<AsyncResult<Void>> handler);

    /**
     * set the entry if it does not already exists
     * @param key used to check if the entry exists and to set the value for.
     * @param value the value to be set if the entry does not exist.
     * @param ttl the time to live for the entry
     */
    void putIfAbsent(Key key, Value value, long ttl, Handler<AsyncResult<Void>> handler);

    /**
     * @param key identifies the entry to be removed.
     */
    void remove(Key key, Handler<AsyncResult<Void>> handler);

    /**
     * replaces the value of the given key if a value already exists.
     * @param key the entry to be replaced if exists
     * @param value the new value of the entry
     */
    void replace(Key key, Value value, Handler<AsyncResult<Void>> handler);

    /**
     * removes all existing entries from the storage.
     */
    void clear(Handler<AsyncResult<Void>> handler);

    /**
     * returns the amount of entries in the storage.
     */
    void size(Handler<AsyncResult<Integer>> handler);

    /**
     * initialize the construction of a query.
     * @param attribute the attribute to be queried.
     * @return a builder object for constructing the query.
     */
    QueryBuilder query(String attribute);
}

@@ -100,36 +100,44 @@
 er;%0A
-%0A
 import 
-java.util.Collection
+io.vertx.core.json.JsonObject
 ;%0A%0A/
@@ -233,16 +233,274 @@
 elcast.%0A
+ *         %3Cp%3E%0A *         Storages implementing this class are recommended to create an index for%0A *         attributes that are queried. It is highly recommended to create an index%0A *         for the ID field, which is used by all %7B@link Storable%7D classes.%0A
  */%0Apubl
@@ -529,23 +529,34 @@
 age%3C
-Key, Valu
+Value extends Storabl
 e%3E %7B%0A
-%0A
     
@@ -590,32 +590,39 @@
 h the given key%0A
+     *%0A
      * @param ke
@@ -678,19 +678,22 @@
 oid get(
-Key
+String
  key, Ha
@@ -815,56 +815,8 @@
    *
- @param key a key to uniquely identify the entry
 %0A   
@@ -887,33 +887,24 @@
    void put(
-Key key, 
 Value value,
@@ -1028,56 +1028,8 @@
    *
- @param key a key to uniquely identify the entry
 %0A   
@@ -1093,32 +1093,34 @@
    * @param ttl 
+  
 the time to live
@@ -1125,32 +1125,184 @@
 ve for the entry
+. Recommended to use%0A     *              only for objects that will never change. As the timers%0A     *              are not cleared on remove or update.
 %0A     */%0A    voi
@@ -1307,25 +1307,16 @@
 oid put(
-Key key, 
 Value va
@@ -1437,79 +1437,8 @@
    *
- @param key used to check if the entry exists and to set the value for.
 %0A   
@@ -1528,33 +1528,24 @@
 putIfAbsent(
-Key key, 
 Value value,
@@ -1634,32 +1634,39 @@
  already exists%0A
+     *%0A
      * @param ke
@@ -1667,70 +1667,61 @@
 ram 
-key used to check if the entry exists and to set the value for
+value the value to be set if the entry does not exist
 .%0A  
@@ -1736,36 +1736,34 @@
 ram 
-value
+ttl  
  the 
-valu
+tim
 e to 
-be set if
+live for
  the
@@ -1772,73 +1772,160 @@
 ntry
- does not exist.%0A     * @param ttl the time to li
+. Recommended to use%0A     *              only for objects that will never change. As the timers%0A     *              are not cleared on remo
 ve 
-f
 or 
-the entry
+update.
 %0A   
@@ -1950,25 +1950,16 @@
 fAbsent(
-Key key, 
 Value va
@@ -2097,19 +2097,22 @@
  remove(
-Key
+String
  key, Ha
@@ -2162,22 +2162,21 @@
 %0A     * 
-replac
+updat
 es the v
@@ -2234,54 +2234,8 @@
    *
- @param key the entry to be replaced if exists
 %0A   
@@ -2299,25 +2299,15 @@
 oid 
-replace(Key key, 
+update(
 Valu
@@ -2651,24 +2651,31 @@
 of a query.%0A
+     *%0A
      * @para
@@ -2740,22 +2740,22 @@
 builder 
-object
+String
  for con
@@ -2799,16 +2799,23 @@
 yBuilder
+%3CValue%3E
  query(S
@@ -2831,11 +2831,195 @@
 ribute);
+%0A%0A    /**%0A     * Constructs a query from a json object%0A     * @param query to build from%0A     * @return a querybuilder object%0A     */%0A    //QueryBuilder%3CValue%3E query(JsonObject query);
 %0A%7D%0A

Update storage interface