package edu.deanza.calendar.util;

/**
 * Created by karinaantonio on 9/1/16.
 */

public abstract class Callback<ArgumentT> implements Runnable {

    private ArgumentT data;
    private Callback<?> callback;

    public Callback() {}

    public Callback(ArgumentT data) {
        setArgument(data);
    }

    public Callback(Callback<?> callback) {
        this.callback = callback;
    }

    public Callback(ArgumentT data, Callback<?> callback) {
        this.data = data;
        this.callback = callback;
    }

    public final void setArgument(ArgumentT data) {
        this.data = data;
    }

    public final Callback<?> setCallback(Callback<?> callback) {
        this.callback = callback;
        return callback;
    }

    @Override
    public final void run() {
        if (data != null) {
            call(data);
            if (callback != null) {
                callback.run();
            }
        }
        else if (callback != null) {
            callback.run();
        }
    }

    protected abstract void call(ArgumentT data);

}

@@ -181,36 +181,40 @@
 private 
-Callback%3C?%3E callback
+boolean nullableArgument
 ;%0A%0A    p
@@ -249,210 +249,45 @@
 lic 
-Callback(ArgumentT data) %7B%0A        setArgument(data);%0A    %7D%0A%0A    public Callback(Callback%3C?%3E callback) %7B%0A        this.callback = callback;%0A    %7D%0A%0A    public Callback(ArgumentT data, Callback%3C?%3E callback
+final void setArgument(ArgumentT data
 ) %7B%0A
@@ -324,478 +324,170 @@
     
-this.callback = callback;
+if (data == null) %7B
 %0A    
-%7D%0A%0A
     
-public final void setArgument(ArgumentT data) %7B%0A        this.data = data;%0A    %7D%0A%0A    public final Callback%3C?%3E setCallback(Callback%3C?%3E callback) %7B%0A        this.callback = callback;%0A        return callback;%0A    %7D%0A%0A    @Override%0A    public final void run() %7B%0A        if (data != null) %7B%0A            call(data);%0A            if (callback != null) %7B%0A                callback.run();%0A            %7D%0A        %7D%0A        else if (callback != null
+    nullableArgument = true;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public final void run() %7B%0A        if (data != null %7C%7C nullableArgument
 ) %7B%0A
@@ -506,17 +506,13 @@
 call
-back.run(
+(data
 );%0A 

Remove Callback chaining and allow explicitly null Callback arguments