package bakatxt.core;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.StringTokenizer;

public class BakaTxtMain {

    enum CommandType {
        ADD, DELETE, DISPLAY, EXIT
    }

    private static Scanner sc;
    private static final String MESSAGE_INVALID_FILE = "Error opening/creating file";
    private static final String MESSAGE_INVALID_FORMAT = "invalid command format";
    private static final String MESSAGE_WELCOME = " Welcome To BakaTxt";
    private static final String MESSAGE_INVALID_COMMAND = "Unrecognized command type";
    private static BakaTxtSession session;

    public static void main(String[] args) throws IOException {

        String filename;
        String command;

        sc = new Scanner(System.in);

        generateStartMessage();
        filename = sc.nextLine();
        session = new BakaTxtSession(filename);
        if (checkFileName(filename) == true) {
            while (true) {

                command = sc.nextLine();
                executeCommand(command);
            }
        } else
            System.out.println(MESSAGE_INVALID_FILE);

    }

    private static void generateStartMessage() {
        System.out.println(MESSAGE_WELCOME);
    }

    private static boolean checkFileName(String filename) {

        if (!Files.isReadable(Paths.get(filename))) {
            return false;
        }
        return true;
    }

    private static String getFirstWord(String command) {
        StringTokenizer tokenizedCommand = new StringTokenizer(command);
        String commandLine = tokenizedCommand.nextToken();

        return commandLine;

    }

    public static String executeCommand(String userCommand) {
        if (userCommand.trim().equals("")) {
            return invalidFormat(userCommand);
        }

        switch (CommandType.valueOf(getFirstWord(userCommand).toUpperCase())) {
            case ADD :
                return session.add(removeFirstWord(userCommand));
            case DELETE :
                return session.delete(removeFirstWord(userCommand));
            case DISPLAY :
                return session.display(removeFirstWord(userCommand));
            case EXIT :
                System.exit(0);
            default :
                // throw an error if the command is not recognized
                throw new Error(MESSAGE_INVALID_COMMAND);
        }

    }

    private static String invalidFormat(String userCommand) {
        return String.format(MESSAGE_INVALID_FORMAT, userCommand);
    }

    private static String removeFirstWord(String command) {
        return command.replace(getFirstWord(command), "").trim();
    }
}

@@ -20,36 +20,8 @@
 e;%0A%0A
-import java.io.IOException;%0A
 impo
@@ -44,16 +44,16 @@
 .Files;%0A
+
 import j
@@ -676,31 +676,11 @@
 rgs)
- throws IOException
  %7B%0A
-%0A
     
@@ -1061,18 +1061,9 @@
    %7D
- else%0A    
+%0A
     
@@ -1108,17 +1108,16 @@
 _FILE);%0A
-%0A
     %7D%0A%0A 
@@ -1613,17 +1613,16 @@
 ndLine;%0A
-%0A
     %7D%0A%0A 
@@ -2170,16 +2170,16 @@
  EXIT :%0A
-
         
@@ -2202,16 +2202,93 @@
 xit(0);%0A
+                //$FALL-THROUGH$ (to remove fall-through warning in eclipse)%0A
         

Remove redundant lines and resolve Eclipse warnings