package seedu.stask.model.task;


//@@author A0139145E
/**
 * Represents a task's status in the to-do-list.
 * Guarantees: immutable
 */
public class Status {

    public static enum State {
        DONE, OVERDUE, NONE, EXPIRE
    }

    public State status;

    public Status(State status) {
        assert status != null;
        this.status = status;
    }
    
    public Status(String statusStr) {
        assert statusStr != null;
        
        this.status = getStatusFromString(statusStr);
    }

    /**
     * Guarantees valid input
     * @param statusStr
     * @return respective enum State
     */
    private State getStatusFromString(String statusStr) {
        
        switch (statusStr) {
        case "DONE":
            return State.DONE;
            
        case "NONE":
            return State.NONE;
            
        case "OVERDUE":
            return State.OVERDUE;
        
        case "EXPIRE":
            return State.EXPIRE;
         
        default:
            return null; //not possible
        }
    }

    @Override
    public String toString() {
        String toReturn;
        
        switch (status) {
        case DONE:
            toReturn = "DONE";
            break;
            
        case NONE:
            toReturn = "NONE";
            break;
            
        case OVERDUE:
            toReturn = "OVERDUE";
            break;
            
        case EXPIRE:
            toReturn = "EXPIRE";
            break;
        
        default:
            toReturn = ""; //Not possible
            break;
        }
        
        return toReturn;
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof Status // instanceof handles nulls
                && this.status.equals(((Status) other).status)); // state check
    }

    @Override
    public int hashCode() {
        return status.hashCode();
    }

}
//@@author

@@ -26,17 +26,16 @@
 .task;%0A%0A
-%0A
 //@@auth
@@ -269,16 +269,17 @@
 c Status
+ 
 (State s
@@ -376,16 +376,17 @@
 c Status
+ 
 (String 
@@ -432,25 +432,16 @@
 = null;%0A
-        %0A
         
@@ -637,16 +637,17 @@
 omString
+ 
 (String 
@@ -712,24 +712,25 @@
  case %22DONE%22
+ 
 :%0A          
@@ -746,37 +746,24 @@
 State.DONE;%0A
-            %0A
         case
@@ -769,16 +769,17 @@
 e %22NONE%22
+ 
 :%0A      
@@ -803,29 +803,16 @@
 e.NONE;%0A
-            %0A
         
@@ -825,16 +825,17 @@
 OVERDUE%22
+ 
 :%0A      
@@ -862,25 +862,16 @@
 VERDUE;%0A
-        %0A
         
@@ -883,16 +883,17 @@
 %22EXPIRE%22
+ 
 :%0A      
@@ -919,26 +919,16 @@
 EXPIRE;%0A
-         %0A
         
@@ -952,35 +952,69 @@
     
-return null; //not possible
+assert false : %22State not possible%22;%0A            return null;
 %0A   
@@ -1149,16 +1149,17 @@
 ase DONE
+ 
 :%0A      
@@ -1198,37 +1198,24 @@
      break;%0A
-            %0A
         case
@@ -1219,16 +1219,17 @@
 ase NONE
+ 
 :%0A      
@@ -1268,37 +1268,24 @@
      break;%0A
-            %0A
         case
@@ -1292,16 +1292,17 @@
  OVERDUE
+ 
 :%0A      
@@ -1352,21 +1352,8 @@
 ak;%0A
-            %0A
     
@@ -1367,16 +1367,17 @@
 e EXPIRE
+ 
 :%0A      
@@ -1430,33 +1430,75 @@
         
-%0A        default:
+default :%0A            assert false : %22Status not possible%22;
 %0A       
@@ -1520,23 +1520,8 @@
  %22%22;
- //Not possible
 %0A   
@@ -1546,25 +1546,16 @@
       %7D%0A
-        %0A
         
@@ -1936,17 +1936,16 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A//@@au

Refactor code quality