<commit_before>package seedu.tasklist.logic.commands;

import java.io.IOException;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;

public class SaveCommand extends Command {
    
    public static final String COMMAND_WORD = "save";
    
    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Change the directory and file name of the data that is being saved.\n"
            + "Parameters: FILE_PATH/FILE_NAME.xml\n"
            + "Example: " + COMMAND_WORD + " data/mytasklist.xml";
    
    public static final String MESSAGE_SUCCESS = "File is successfully saved to: %1$s";
    public static final String MESSAGE_INVALID_PATH = "Invalid file path: %1$s";
    public static final String MESSAGE_FAILURE = "Unable to save file at specified path: %1$s";
    
    private final String filePath;
    private static final String XML = ".xml";
    
    public SaveCommand(String filePath){
        this.filePath = filePath;
    }
    
    @Override
    public CommandResult execute() {
        assert filePath != null; 
        assert model != null;
        
        if (!isValidPath(filePath)) {
            return new CommandResult(String.format(MESSAGE_INVALID_PATH, filePath));
        }

        try{
            model.saveTaskList(filePath);
            return new CommandResult(String.format(MESSAGE_SUCCESS, filePath));
        }catch (IOException e){
            return new CommandResult(String.format(MESSAGE_FAILURE, filePath));
        }
        
    }
    

    /**
     * Returns true if the given path is a valid path
     */
    private boolean isValidPath(String path) {
        try {
            Paths.get(path);
            return isXML(path);
        } catch (InvalidPathException e) {
            return false;
        }
    }

    /**
     * Returns true if the given path ends with the .xml extension.
     */
    private static boolean isXML(String path) {
        return path.endsWith(XML);
    }


}<commit_msg>correct checkstyle errors<commit_after>package seedu.tasklist.logic.commands;

import java.io.IOException;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;

public class SaveCommand extends Command {

    public static final String COMMAND_WORD = "save";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Change the directory and file name of the data that is being saved.\n"
            + "Parameters: FILE_PATH/FILE_NAME.xml\n"
            + "Example: " + COMMAND_WORD + " data/mytasklist.xml";

    public static final String MESSAGE_SUCCESS = "File is successfully saved to: %1$s";
    public static final String MESSAGE_INVALID_PATH = "Invalid file path: %1$s";
    public static final String MESSAGE_FAILURE = "Unable to save file at specified path: %1$s";

    private final String filePath;
    private static final String XML = ".xml";

    public SaveCommand(String filePath) {
        this.filePath = filePath;
    }

    @Override
    public CommandResult execute() {
        assert filePath != null;
        assert model != null;

        if (!isValidPath(filePath)) {
            return new CommandResult(String.format(MESSAGE_INVALID_PATH, filePath));
        }

        try {
            model.saveTaskList(filePath);
            return new CommandResult(String.format(MESSAGE_SUCCESS, filePath));
        } catch (IOException e) {
            return new CommandResult(String.format(MESSAGE_FAILURE, filePath));
        }

    }


    /**
     * Returns true if the given path is a valid path
     */
    private boolean isValidPath(String path) {
        try {
            Paths.get(path);
            return isXML(path);
        } catch (InvalidPathException e) {
            return false;
        }
    }

    /**
     * Returns true if the given path ends with the .xml extension.
     */
    private static boolean isXML(String path) {
        return path.endsWith(XML);
    }


}
{'fraction_non_alphanumeric': 0.08777749425873947, 'fraction_numerical': 0.0015310028068384791, 'mean_word_length': 2.408695652173913, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7248051', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1052, 'n_words': 324}