package FileSystem; /** * You should use this class to generate the strings you need to print as error * messages. Do not modify anything in this class. * */ public class ErrorMessage { public static enum Errors { UNRECOGNIZED_COMMAND, // the first word on the command line isn't one of // the commands to be interpreted. (Note: a blank // command line isn't an error; it should be // ignored.) WRONG_NUMBER_ARGUMENTS, // Wrong number [of] arguments ILLEGAL_FILE_NAME, // an attempt is being made to create a file // using create, mkdir, cp, or mvÑwhose name contains other than // alphanumeric characters. FILE_NOT_FOUND, // an argument, in any command other than create, mkdir, // or pwd, names a file that doesn't exist. (In a path // name argument, the nonexistent file could be one of // the directories on the path.) FILE_NOT_A_DIRECTORY, // an argument to cd, lstree, or rmdir is a text // file rather than a directory, or a component of // a relative or absolute path name argument to // any command but pwd is a text file when it // should be a directory. FILE_NOT_A_TEXT_FILE, // an argument to cat or rm is a directory rather // than a text file. FILE_EXISTS, // an attempt is being made in a create, mkdir, cp, or mv // command to create a file that already exists. NONEMPTY_DIRECTORY, // an attempt is being made to remove a nonempty // directory with rmdir. CURRENT_DIRECTORY, // an attempt to remove the current working directory IDENTICAL_FILES, // the arguments to cp or mv refer to the same file. DESTINATION_WITHIN_SOURCE }; // an attempt is being made to move (mv) or copy (cp) a directory into // one of its subdirectories. public static String message(Errors e, String s) { switch (e) { case UNRECOGNIZED_COMMAND: // s is the unrecognized command, the first word on the command // line. return "Unrecognized command: " + s; case WRONG_NUMBER_ARGUMENTS: // s is the command, the first word on the command line. return "Wrong number of arguments: " + s; case ILLEGAL_FILE_NAME: // s is the part of the argument that contains the illegal file // name, // that is, the word that in a legal file name would consist solely // of alphanumeric characters. return "Illegal file name: " + s; case FILE_NOT_FOUND: // s is the command-line argument that names the unlocatable file. return "File not found: " + s; case FILE_NOT_A_DIRECTORY: // s is the command-line argument that names the text file. return "File not a directory: " + s; case FILE_NOT_A_TEXT_FILE: // s is the command-line argument that names the directory. return "File not a text file: " + s; case FILE_EXISTS: // s is the command-line argument that names the incorrectly // existing file. return "File exists: " + s; case CURRENT_DIRECTORY: // s is the command-line argument that names the directory to // remove, // namely the working directory. return "Can't remove current directory: " + s; case NONEMPTY_DIRECTORY: // s is the command-line argument that names the nonempty directory. return "Nonempty directory: " + s; } return ""; } public static String message(Errors e, String s1, String s2) { switch (e) { case IDENTICAL_FILES: // s1 and s2 are the command-line arguments that name the same file. return "Identical files: " + s1 + " " + s2; case DESTINATION_WITHIN_SOURCE: // s1 is the command-line argument that names the source directory; // s2 is the argument that names the destination that's somewhere // within the source. return "Source contains destination: " + s1 + " " + s2; } return ""; } }