import java.io.*; import java.util.*; class Command implements Runnable { FileSystem fSystem; String comd, theCommand; // Constructor to initialize the command Command( String c, FileSystem file_system) { comd = c; fSystem = file_system; } // start up the command public void run(){ // if the comd is other than du, parse it further Parser another_parser = new Parser(); another_parser.parse(comd, " "); ArrayList tmpList = another_parser.getTokens(); theCommand = (String)tmpList.get(0); // type exit to exit if (comd.compareTo("exit") == 0) fSystem.exitSystem(); else if (comd.compareTo("du") == 0) fSystem.DiskUsage(); else if ((theCommand.compareTo("ln")==0)&&(tmpList.size()==4)){ String secComd = (String)tmpList.get(1); String firstFileName = (String)tmpList.get(2); String secFileName = (String)tmpList.get(3); fSystem.MakeLink(firstFileName,secFileName); } else if ((theCommand.compareTo("rmdir")==0)&&(tmpList.size()==2)){ String file_name = (String)tmpList.get(1); fSystem.RemoveDir(file_name); } else if((theCommand.compareTo("rm") == 0)&&(tmpList.size()==2)){ String file_name = (String)tmpList.get(1); fSystem.RemoveSmFile(file_name); } else if((theCommand.compareTo("touch") == 0) &&(tmpList.size()==2)){ String file_name = (String)tmpList.get(1); fSystem.CreatEmpFile(file_name); } else if ((theCommand.compareTo("mkdir")==0)&&(tmpList.size()==2)) fSystem.MakeDirectory((String)tmpList.get(1)); else if ((theCommand.compareTo("cd")==0)&&(tmpList.size()==2)) { String postCommand = (String)tmpList.get(1); if (postCommand.compareTo("..") == 0) { fSystem.ChangeDirectoryUp(); } else fSystem.ChangeDirectoryDown(postCommand); } else System.out.println(comd + ": Command not found."); } // end of run(); } // end of class command