package seedu.address.model.tag;

import seedu.address.commons.exceptions.IllegalValueException;

/**
 * Represents a Tag in the address book.
 * Guarantees: immutable; name is valid as declared in {@link #isValidTagName(String)}
 */
public class Tag {

    public static final String MESSAGE_TAG_CONSTRAINTS = "Tags names should be alphanumeric";
    public static final String TAG_VALIDATION_REGEX = "\\p{Alnum}+";

    public final String tagName;

    /**
     * Validates given tag name.
     *
     * @throws IllegalValueException if the given tag name string is invalid.
     */
    public Tag(String name) throws IllegalValueException {
        assert name != null;
        String trimmedName = name.trim();
        if (!isValidTagName(trimmedName)) {
            throw new IllegalValueException(MESSAGE_TAG_CONSTRAINTS);
        }
        this.tagName = trimmedName;
    }

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

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

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

    /**
     * Format state as text for viewing.
     */
    public String toString() {
        return '[' + tagName + ']';
    }

}

@@ -27,16 +27,46 @@
 l.tag;%0A%0A
+import java.util.Comparator;%0A%0A
 import s
@@ -119,16 +119,54 @@
 ception;
+%0Aimport seedu.address.model.task.Task;
 %0A%0A/**%0A *
@@ -295,16 +295,16 @@
 g)%7D%0A */%0A
-
 public c
@@ -311,16 +311,60 @@
 lass Tag
+ implements Comparable%3CTag%3E, Comparator%3CTag%3E
  %7B%0A%0A    
@@ -1664,10 +1664,338 @@
 %0A    %7D%0A%0A
+    @Override%0A    public int compareTo(Tag compareTag) %7B%0A        return this.tagName.compareTo(compareTag.tagName);%0A    %7D%0A    %0A    public static Comparator%3CTag%3E TagComparator%0A        = new Comparator%3CTag%3E() %7B%0A %0A        public int compare(Tag tag1, Tag tag2) %7B%0A             return tag1.compareTo(tag2);%0A        %7D%0A        %0A    %7D;%0A
 %7D%0A

implement Comparable, Comparator in Tag.java