Skip to content
This repository was archived by the owner on Sep 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/ru/fizteh/fivt/students/elina_denisova/j_unit/Commands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.fizteh.fivt.students.elina_denisova.j_unit;

public enum Commands {

CREATECOMMAND("create"),
SIZECOMMAND("size"),
COMMITCOMMAND("commit"),
ROLLBACKCOMMAND("rollback"),
DROPCOMMAND("drop"),
USECOMMAND("use"),
SHOWCOMMAND("show"),
PUTCOMMAND("put"),
GETCOMMAND("get"),
REMOVECOMMAND("remove"),
LISTCOMMAND("list"),
EXITCOMMAND("exit");


private String value;
private Commands(String word) {
value = word;
}

public static Commands getCommand(String word) throws IllegalArgumentException {
for (Commands command : Commands.values()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Положите все команды в Map и доставайте команды из него, а не так

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, я залила старый вариант -_-

if (command.getValue().equals(word)) {
return command;
}
}
throw new IllegalArgumentException(word + " - unknown command");
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.fizteh.fivt.students.elina_denisova.j_unit;

public class HandlerException {
public static void handler(String message, Throwable cause) {
System.err.println(message + ". " + cause.getMessage());
System.exit(1);
}
public static void handler(Throwable cause) {
System.err.println(cause.getMessage());
System.exit(1);
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ru.fizteh.fivt.students.elina_denisova.j_unit;

import ru.fizteh.fivt.students.elina_denisova.j_unit.commands.Commands;

import java.util.NoSuchElementException;
import java.util.Scanner;

public class InteractiveParse {
public static void parse(MyTableProvider directory) {
Scanner in = new Scanner(System.in);
try {
while (true) {
System.out.print("$ ");
String s;
s = in.nextLine();
s = s.trim();
String[] current = s.split("\\s+");
for (int i = 0; i < current.length; ++i) {
current[i].trim();
}
try {
Commands command = Commands.fromString(current);
command.execute(directory);
} catch (NoSuchElementException e) {
System.err.println(e.getMessage());
}
}
} catch (IllegalMonitorStateException e) {
in.close();
System.out.println("Goodbye");
System.exit(0);
} catch (NoSuchElementException e) {
System.err.println(e.getMessage());
} catch (Exception e) {
in.close();
HandlerException.handler(e);
}
in.close();
}
}
Loading