package io.paperdb;

import android.content.Context;
import com.esotericsoftware.kryo.Serializer;

import java.util.HashMap;
import java.util.List;

public class Book {

    private final Storage mStorage;

    protected Book(Context context, String dbName, HashMap<Class, Serializer> serializers) {
        mStorage = new DbStoragePlainFile(context.getApplicationContext(), dbName, serializers);
    }

    /**
     * Destroys all data saved in Book.
     */
    public void destroy() {
        mStorage.destroy();
    }

    /**
     * Saves any types of POJOs or collections in Book storage.
     *
     * @param key   object key is used as part of object's file name
     * @param value object to save, must have no-arg constructor, can't be null.
     * @param <T>   object type
     * @return this Book instance
     */
    public <T> Book write(String key, T value) {
        if (value == null) {
            throw new PaperDbException("Paper doesn't support writing null root values");
        } else {
            mStorage.insert(key, value);
        }
        return this;
    }

    /**
     * Instantiates saved object using original object class (e.g. LinkedList). Support limited
     * backward and forward compatibility: removed fields are ignored, new fields have their
     * default values.
     * <p/>
     * All instantiated objects must have no-arg constructors.
     *
     * @param key object key to read
     * @return the saved object instance or null
     */
    public <T> T read(String key) {
        return read(key, null);
    }

    /**
     * Instantiates saved object using original object class (e.g. LinkedList). Support limited
     * backward and forward compatibility: removed fields are ignored, new fields have their
     * default values.
     * <p/>
     * All instantiated objects must have no-arg constructors.
     *
     * @param key          object key to read
     * @param defaultValue will be returned if key doesn't exist
     * @return the saved object instance or null
     */
    public <T> T read(String key, T defaultValue) {
        T value = mStorage.select(key);
        return value == null ? defaultValue : value;
    }

    /**
     * Check if an object with the given key is saved in Book storage.
     *
     * @param key object key
     * @return true if object with given key exists in Book storage, false otherwise
     */
    public boolean exist(String key) {
        return mStorage.exist(key);
    }

    /**
     * Returns lastModified timestamp of last write
     *
     * @param key object key
     * @return timestamp of last write for given key if it exists, otherwise -1
     */
    public long lastModified(String key){
        return mStorage.lastModified(key);
    }

    /**
     * Delete saved object for given key if it is exist.
     *
     * @param key object key
     */
    public void delete(String key) {
        mStorage.deleteIfExists(key);
    }

    /**
     * Returns all keys for objects in book.
     *
     * @return all keys
     */
    public List<String> getAllKeys() {
        return mStorage.getAllKeys();
    }

}

@@ -46,16 +46,17 @@
 ontext;%0A
+%0A
 import c
@@ -2526,16 +2526,175 @@
 st write
+ in ms.%0A     * NOTE: only seconds granularity is guaranteed as many file system don't support%0A     * milliseconds granularity for file's last-modification time
 %0A     *%0A
@@ -2771,24 +2771,30 @@
 r given key 
+in ms 
 if it exists

Add note that only seconds granularity is guaranteed for `book.lastModified` API