package edu.berkeley.eecs.cfc_tracker.usercache;

import org.json.JSONObject;

/**
 * Abstract superclass for the client side component of the user cache.
 */
public interface UserCache {

    class TimeQuery {
        int keyRes;
        long startTs;
        long endTs;

        public TimeQuery(int keyRes, long startTs, long endTs) {
            this.keyRes = keyRes;
            this.startTs = startTs;
            this.endTs = endTs;
        }
    }

    /**
      The value should be an object that is serializable using GSON.
      Most objects are, but it would be good to confirm, probably by
      adding a serialization/deserialization test to WrapperTest.
     */
    public abstract void putMessage(int keyRes, Object value);

    public abstract void putReadWriteDocument(int keyRes, Object value);

    // TODO: Should this return a JSON object or an actual object retrieved via gson?

    public abstract <T> T[] getMessagesForInterval(int keyRes, TimeQuery tq, Class<T> classOfT);
    public abstract <T> T[] getLastMessages(int keyRes, int nEntries, Class<T> classOfT);

        /**
         * Return the document that matches the specified key.
         * The class of T needs to be passed in, and an appropriate type will be reconstructed
         * and returned.
         */
    public abstract <T> T getDocument(int keyRes, Class<T> classOfT);
    public abstract <T> T getUpdatedDocument(int keyRes, Class<T> classOfT);

    /**
     * Delete documents that match the specified time query.
     * This allows us to support eventual consistency without locking.
     */
    public abstract void clearMessages(TimeQuery tq);
}

@@ -47,37 +47,8 @@
 e;%0A%0A
-import org.json.JSONObject;%0A%0A
 /**%0A
@@ -414,16 +414,123 @@
        %7D
+%0A%0A        public String toString() %7B%0A            return startTs + %22 %3C %22 + keyRes + %22 %3C %22 + endTs;%0A        %7D
 %0A    %7D%0A%0A

Create a simple toString method for the time query