package seedu.tasklist.model.task;

import seedu.tasklist.commons.exceptions.IllegalValueException;

public class Priority {
    public static final String MESSAGE_PRIORITY_CONSTRAINTS =
            "Task priorities should only contain 'high', 'medium', or 'low', and it should not be blank";

    /*
     * The first character of the address must not be a whitespace,
     * otherwise " " (a blank string) becomes a valid input.
     */
    public static final String PRIORITY_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";

    public final String priority;

    /**
     * Validates given priority.
     *
     * @throws IllegalValueException if given name string is invalid.
     */
    public Priority(String priority) throws IllegalValueException {
        assert priority != null;
        String trimmedPriority = priority.trim();
        if (!isValidPriority(trimmedPriority)) {
            throw new IllegalValueException(MESSAGE_PRIORITY_CONSTRAINTS);
        }
        this.priority = trimmedPriority;
    }

    /**
     * Returns true if a given string is a valid Task name.
     */
    public static boolean isValidPriority(String test) {
        return test.matches(PRIORITY_VALIDATION_REGEX);
    }

    @Override
    public String toString() {
        return priority;
    }

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

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

package seedu.tasklist.model.task;

import com.google.common.base.Optional;

import seedu.tasklist.commons.exceptions.IllegalValueException;

public class Priority {
    public static final String MESSAGE_PRIORITY_CONSTRAINTS =
            "Task priorities should only contain 'high', 'medium', or 'low', and it should not be blank";

    /*
     * The first character of the address must not be a whitespace,
     * otherwise " " (a blank string) becomes a valid input.
     */
    public static final String PRIORITY_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
    public static final String PRIORITY_LOW = "low";
    public static final String PRIORITY_MEDIUM = "medium";
    public static final String PRIORITY_HIGH = "high";

    public final String priority;

    /**
     * Validates given priority.
     *
     * @throws IllegalValueException if given name string is invalid.
     */
    public Priority(String priority) throws IllegalValueException {
        assert priority != null;
        String trimmedPriority = priority.trim();
        if (!isValidPriority(trimmedPriority)) {
            throw new IllegalValueException(MESSAGE_PRIORITY_CONSTRAINTS);
        }
        this.priority = trimmedPriority;
    }

    public Priority(Optional<String> priority) throws IllegalValueException {
        if (priority.isPresent()) {
            String priorityString = priority.get();
            assert priority != null;
            if (!isValidPriority(priorityString)) {
                throw new IllegalValueException(MESSAGE_PRIORITY_CONSTRAINTS);
            }
            this.priority = getPriorityType(priorityString);
        } else {
            this.priority = null;
        }
    }

    /**
     * Returns true if Priority is present
     */
    public boolean isPriorityPresent(Optional<String> priority) {
        return priority.isPresent();
    }

    /**
     * Returns true if a given string is a valid Priority.
     */
    public static boolean isValidPriority(String test) {
        return test.matches(PRIORITY_VALIDATION_REGEX);
    }

    /**
     * Returns the priority type. Throws IllegalArgumentException if not available
     */
    public static String getPriorityType(String priority) throws IllegalArgumentException {
        String lowerCasePriority = priority.toLowerCase();
        if (lowerCasePriority.equals(PRIORITY_LOW)) {
            return PRIORITY_LOW;
        } else if (lowerCasePriority.equals(PRIORITY_MEDIUM)) {
            return PRIORITY_MEDIUM;
        } else if (lowerCasePriority.equals(PRIORITY_HIGH)) {
            return PRIORITY_HIGH;
        } else {
            throw new IllegalArgumentException(MESSAGE_PRIORITY_CONSTRAINTS);
        }
    }

    @Override
    public String toString() {
        return priority;
    }

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

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

add constructor for Priority.java