package seedu.typed.logic.parser;

import static seedu.typed.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.typed.logic.parser.CliSyntax.KEYWORDS_ARGS_FORMAT;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;

import seedu.typed.logic.commands.Command;
import seedu.typed.logic.commands.FindCommand;
import seedu.typed.logic.commands.IncorrectCommand;

/**
 * Parses input arguments and creates a new FindCommand object
 */
public class FindCommandParser {

    /**
     * Parses the given {@code String} of arguments in the context of the
     * FindCommand and returns an FindCommand object for execution.
     */
    public Command parse(String args) {
        final Matcher matcher = KEYWORDS_ARGS_FORMAT.matcher(args.trim());
        if (!matcher.matches()) {
            return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
        }

        // keywords delimited by whitespace
        final String[] keywords = matcher.group("keywords").split("\\s+");
        final Set<String> keywordSet = new HashSet<>(Arrays.asList(keywords));
        return new FindCommand(keywordSet);
    }

}

@@ -534,16 +534,137 @@
 rser %7B%0A%0A
+    private static final int MAX_EDIT_DISTANCE = 2;%0A    private static final int POSITIVE_INFINITY = Integer.MAX_VALUE;%0A%0A
     /**%0A
@@ -1337,10 +1337,1326 @@
 %0A    %7D%0A%0A
+    private boolean isFuzzyMatch(String str1, String str2) %7B%0A        return computeMinEditDistance(str1, str2) %3C= MAX_EDIT_DISTANCE;%0A    %7D%0A%0A    private int computeMinEditDistance(String str1, String str2) %7B%0A        int lenStr1 = str1.length();%0A        int lenStr2 = str2.length();%0A        return computeLevenshtein(initDistance(lenStr1, lenStr2), str1, str2);%0A    %7D%0A%0A    private int%5B%5D%5B%5D initDistance(int len1, int len2) %7B%0A        int%5B%5D%5B%5D editDistance = new int%5Blen1 + 1%5D%5Blen2 + 2%5D;%0A        for (int c = 0; c %3C len2 + 1; c++) %7B%0A            editDistance%5B0%5D%5Bc%5D = c;%0A        %7D%0A        for (int r = 0; r %3C len1 + 1; r++) %7B%0A            editDistance%5Br%5D%5B0%5D = r;%0A        %7D%0A        return editDistance;%0A    %7D%0A%0A    private int computeLevenshtein(int%5B%5D%5B%5D distance, String str1, String str2) %7B%0A        int bestMin = POSITIVE_INFINITY;%0A        for (int i = 1; i %3C distance.length; i++) %7B%0A            for (int j = 1; j %3C distance%5B0%5D.length; j++) %7B%0A                int a = distance%5Bi - 1%5D%5Bj%5D + 1;%0A                int b = distance%5Bi%5D%5Bj - 1%5D + 1;%0A                int c = distance%5Bi - 1%5D%5Bj - 1%5D;%0A                if (str1.charAt(i - 1) == str2.charAt(j - 1)) %7B%0A                    c += 1;%0A                %7D%0A                bestMin = Math.min(bestMin, Math.min(a, Math.min(b, c)));%0A            %7D%0A        %7D%0A        return bestMin;%0A    %7D%0A%0A
 %7D%0A

implement fuzzy find algorithm (Levenshtein distance) //TODO: add support to enable fuzzy find