package org.ethereum.datasource;

/**
 * Created by Anton Nashatyrev on 06.12.2016.
 */
public abstract class AbstractChainedSource<Key, Value, SourceKey, SourceValue> implements Source<Key, Value> {

    protected Source<SourceKey, SourceValue> source;
    protected boolean flushSource;

    protected AbstractChainedSource() {
    }

    public AbstractChainedSource(Source<SourceKey, SourceValue> source) {
        this.source = source;
    }

    protected void setSource(Source<SourceKey, SourceValue> src) {
        source = src;
    }

    public Source<SourceKey, SourceValue> getSource() {
        return source;
    }

    public void setFlushSource(boolean flushSource) {
        this.flushSource = flushSource;
    }

    @Override
    public final synchronized boolean flush() {
        if (flushSource) {
            getSource().flush();
        }
        return flushImpl();
    }

    protected abstract boolean flushImpl();
}

@@ -31,16 +31,177 @@
 e;%0A%0A/**%0A
+ * Abstract Source implementation with underlying backing Source%0A * The class has control whether the backing Source should be flushed%0A * in 'cascade' manner%0A *%0A
  * Creat
@@ -361,23 +361,21 @@
 %0A%0A    pr
-otec
+iva
 te
-d
  Source%3C
@@ -412,23 +412,21 @@
 ;%0A    pr
-otec
+iva
 te
-d
  boolean
@@ -440,16 +440,152 @@
 ource;%0A%0A
+    /**%0A     * Intended for subclasses which wishes to initialize the source%0A     * later via %7B@link #setSource(Source)%7D method%0A     */%0A
     prot
@@ -726,32 +726,123 @@
  source;%0A    %7D%0A%0A
+    /**%0A     * Intended for subclasses which wishes to initialize the source later%0A     */%0A
     protected vo
@@ -1104,24 +1104,178 @@
 rce;%0A    %7D%0A%0A
+    /**%0A     * Invokes %7B@link #flushImpl()%7D and does backing Source flush if required%0A     * @return true if this or source flush did any changes%0A     */%0A
     @Overrid
@@ -1320,24 +1320,59 @@
 n flush() %7B%0A
+        boolean ret = flushImpl();%0A
         if (
@@ -1397,16 +1397,23 @@
         
+ ret %7C=
  getSour
@@ -1455,27 +1455,89 @@
 urn 
-flushImpl();
+ret;%0A    %7D%0A%0A    /**%0A     * Should be overridden to do actual source flush
 %0A    
-%7D%0A
+ */
 %0A   

Fix flush implementation: first own flush() should be performed. Add docs