package utask.model.task;

import utask.commons.exceptions.IllegalValueException;

/**
 * Represents the boolean value of the isCompleted attribute in the uTask.
 * Guarantees: immutable; is valid as declared in
 * {@link #isValidBoolean(String)}
 */
// @@author A0138423J
public class IsCompleted {
    public static final String MESSAGE_NAME_CONSTRAINTS = "Task status should be true/false or "
            + "yes/no case insensitive, and it should not be blank";

    /*
     * The first character of the status must not be a whitespace, otherwise " "
     * (a blank string) becomes a valid input.
     */
    public static final String ISCOMPLETED_VALIDATION_REGEX = "^(YES|yes|Y|y|TRUE|true|T|t|NO|no|N|n|FALSE|false|F|f)$";
    //
    public final String value;

    /**
     * Validates given status.
     *
     * @throws IllegalValueException
     *             if given name string is invalid.
     */
    public IsCompleted(String input) throws IllegalValueException {
        assert input != null;
        String trimmedName = input.trim();
        if (!isValidBoolean(trimmedName)) {
            throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS);
        }
        char value = input.toLowerCase().charAt(0);
        Boolean valToBool = false;
        switch (value) {
        case 't':
            valToBool = true;
            break;
        case 'y':
            valToBool = true;
            break;
        case 'f':
            valToBool = false;
            break;
        case 'n':
            valToBool = false;
            break;
        default:
            valToBool = true;
        }
        this.value = valToBool.toString();
    }

    private IsCompleted() {
        this.value = "false";
    }

    public static IsCompleted getEmptyIsCompleted() {
        return new IsCompleted();
    }

    public boolean isEmpty() {
        return "".equals(value);
    }

    /**
     * Returns true if a given string is a valid true/false or yes/no.
     */
    public static boolean isValidBoolean(String test) {
        return test.matches(ISCOMPLETED_VALIDATION_REGEX);
    }

    @Override
    public String toString() {
        return value.toString();
    }

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

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

@@ -324,36 +324,43 @@
  String MESSAGE_
-NAME
+ISCOMPLETED
 _CONSTRAINTS = %22
@@ -1154,12 +1154,19 @@
 AGE_
-NAME
+ISCOMPLETED
 _CON
@@ -1198,21 +1198,21 @@
     
-char 
+this.
 value = 
 inpu
@@ -1211,231 +1211,298 @@
 e = 
+checkValue(
 input
+)
 .to
-LowerCase().charAt(0
+String(
 );%0A    
+%7D%0A%0A
     
-Boolean valToBool = false;%0A        switch (value) %7B%0A        case 't':%0A            valToBool = true;%0A            break;%0A        case 'y':%0A            valToBool = true;%0A            break
+private Boolean checkValue(String strToEvaluate) throws IllegalValueException %7B%0A        char value = strToEvaluate.toLowerCase().charAt(0);%0A        switch (value) %7B%0A        case 't':%0A            return true;%0A        case 'y':%0A            return true
 ;%0A  
@@ -1529,35 +1529,30 @@
         
-valToBool =
+return
  false;%0A
         
@@ -1543,35 +1543,16 @@
  false;%0A
-            break;%0A
         
@@ -1577,145 +1577,126 @@
     
-valToBool = false;%0A            break;%0A        default:%0A            valToBool = true;%0A        %7D%0A        this.value = valToBool.toString();
+return false;%0A        default:%0A            throw new IllegalValueException(MESSAGE_ISCOMPLETED_CONSTRAINTS);%0A        %7D
 %0A   
@@ -2204,27 +2204,16 @@
 rn value
-.toString()
 ;%0A    %7D%0A

Fix issues highlighted by codacy for IsCompleted file