package de.fau.cs.mad.fablab.android.viewmodel.common.commands;

public abstract class Command<T> {

    private CommandListener commandListener;
    private boolean isAvailable = true;
    private boolean isExecutable = true;

    public void setListener(CommandListener commandListener) {
        this.commandListener = commandListener;
    }

    public boolean isAvailable() {
        return isAvailable;
    }

    public boolean isExecutable() {
        return isExecutable && isAvailable();
    }

    public void setIsAvailable(boolean isAvailable) {
        if (isAvailable != this.isAvailable) {
            this.isAvailable = isAvailable;
            commandListener.onIsAvailableChanged(isAvailable);
        }

    }

    public void setIsExecutable(boolean isExecutable) {
        if (isExecutable != this.isExecutable) {
            this.isExecutable = isExecutable;
            commandListener.onIsExecutableChanged(isExecutable);
        }
    }

    public abstract void execute(T parameter);
}




@@ -114,33 +114,34 @@
 CommandListener 
-c
+mC
 ommandListener;%0A
@@ -152,33 +152,34 @@
 private boolean 
-i
+mI
 sAvailable = tru
@@ -193,33 +193,34 @@
 private boolean 
-i
+mI
 sExecutable = tr
@@ -299,14 +299,10 @@
     
-this.c
+mC
 omma
@@ -392,96 +392,10 @@
 urn 
-isAvailable;%0A    %7D%0A%0A    public boolean isExecutable() %7B%0A        return isExecutable && i
+mI
 sAva
@@ -400,18 +400,16 @@
 vailable
-()
 ;%0A    %7D%0A
@@ -490,22 +490,18 @@
 able != 
-this.i
+mI
 sAvailab
@@ -518,22 +518,18 @@
         
-this.i
+mI
 sAvailab
@@ -550,33 +550,82 @@
 le;%0A            
-c
+if (mCommandListener != null) %7B%0A                mC
 ommandListener.o
@@ -654,24 +654,28 @@
 Available);%0A
+    
         %7D%0A%0A 
@@ -668,24 +668,123 @@
           %7D%0A
+        %7D%0A    %7D%0A%0A    public boolean isExecutable() %7B%0A        return mIsExecutable && isAvailable();
 %0A    %7D%0A%0A    
@@ -863,22 +863,18 @@
 able != 
-this.i
+mI
 sExecuta
@@ -896,14 +896,10 @@
     
-this.i
+mI
 sExe
@@ -934,17 +934,66 @@
         
-c
+if (mCommandListener != null) %7B%0A                mC
 ommandLi
@@ -1032,24 +1032,38 @@
 xecutable);%0A
+            %7D%0A
         %7D%0A  
@@ -1116,11 +1116,8 @@
 ter);%0A%7D%0A
-%0A%0A%0A

Add null checks