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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ru.fizteh.fivt.storage.structured.ColumnFormatException;
import ru.fizteh.fivt.storage.structured.Storeable;
import ru.fizteh.fivt.storage.structured.Table;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.Helper;

/**
* Represents the data table containing pairs key-value. The keys must be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ru.fizteh.fivt.storage.structured.Storeable;
import ru.fizteh.fivt.storage.structured.Table;
import ru.fizteh.fivt.storage.structured.TableProvider;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.Helper;

/**
* Management class for working with the {link Table tables}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class TableManagerFactory implements TableProviderFactory, AutoClos
private boolean invalid;

public TableManagerFactory() {
// Do nothing, only for implemented imterface.
// Do nothing, only for implemented interface.
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;

import ru.fizteh.fivt.storage.structured.Storeable;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.Helper;

/**
* Class represents a single file of type *.dir/*.dat.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
import ru.fizteh.fivt.storage.structured.Table;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.DataBaseIOException;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.DbTable;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.Helper;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.TableManager;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.Helper;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.TestHelper;

@SuppressWarnings("resource")
public class DbTableTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import org.junit.Before;
import org.junit.Test;

import ru.fizteh.fivt.students.vadim_mazaev.DataBase.Helper;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.TableManagerFactory;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.Helper;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.TestHelper;

@SuppressWarnings("resource")
public class TableManagerFactoryTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import ru.fizteh.fivt.storage.structured.Storeable;
import ru.fizteh.fivt.storage.structured.Table;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.DataBaseIOException;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.Helper;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.TableManager;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.Helper;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.TestHelper;

@SuppressWarnings("resource")
public class TableManagerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,35 @@ public final class Interpreter {
public static final String PROMPT = "$ ";
public static final String NO_SUCH_COMMAND_MSG = "No such command declared: ";
private static final String IGNORE_IN_DOUBLE_QUOTES_REGEX = "(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
private static final String SPLIT_BY_SPACES_NOT_IN_BRACKETS_REGEX
= "\\s*(\".*\"|\\(.*\\)|\\[.*\\]|[^\\s]+)\\s*";
private static final String SPLIT_BY_SPACES_NOT_IN_BRACKETS_REGEX = "\\s*(\".*\"|\\(.*\\)|\\[.*\\]|[^\\s]+)\\s*";
public static final String COMMAND_SEPARATOR = ";";
private InputStream in;
private PrintStream out;
private Object connector;
private Object state;
private Map<String, Command> commands;
private Callable<Boolean> exitHandler;
public Interpreter(Object connector, Command[] commands, InputStream in, PrintStream out) {

public Interpreter(Object state, Command[] commands, InputStream in, PrintStream out) {
if (in == null || out == null) {
throw new IllegalArgumentException("Input or Output stream is null");
}
this.commands = new HashMap<>();
this.in = in;
this.out = out;
this.connector = connector;
this.state = state;
for (Command cmd : commands) {
this.commands.put(cmd.getName(), cmd);
}
}

public Interpreter(Object connector, Command[] commands) {
this(connector, commands, System.in, System.out);
}


public int run() throws Exception {
return run(new String[0]);
}

public int run(String[] args) throws Exception {
int exitStatus;
try {
Expand All @@ -55,11 +58,15 @@ public int run(String[] args) throws Exception {
}
return exitStatus;
}

public void setExitHandler(Callable<Boolean> callable) {
exitHandler = callable;
}


public void printMessage(String message) {
out.println(message);
}

private int batchMode(String[] args) throws Exception {
int exitStatus = executeLine(String.join(" ", args));
if (exitHandler != null) {
Expand All @@ -86,7 +93,7 @@ private int interactiveMode() throws Exception {
}
return exitStatus;
}

private int executeLine(String line) throws Exception {
String[] cmds = line.split(COMMAND_SEPARATOR + IGNORE_IN_DOUBLE_QUOTES_REGEX);
Pattern p = Pattern.compile(SPLIT_BY_SPACES_NOT_IN_BRACKETS_REGEX);
Expand All @@ -102,11 +109,11 @@ private int executeLine(String line) throws Exception {
}
return 0;
} catch (StopLineInterpretationException e) {
out.println(e.getMessage());
printMessage(e.getMessage());
return 1;
}
}

private void parse(String[] commandWithArgs) throws Exception {
if (commandWithArgs.length > 0 && !commandWithArgs[0].isEmpty()) {
String commandName = commandWithArgs[0];
Expand All @@ -125,7 +132,8 @@ private void parse(String[] commandWithArgs) throws Exception {
throw new StopLineInterpretationException(NO_SUCH_COMMAND_MSG + commandName);
} else {
String[] args = new String[commandWithArgs.length - 1];
//Exclude quotes along the edges of the string, if they presents.
// Exclude quotes along the edges of the string, if they
// presents.
for (int i = 1; i < commandWithArgs.length; i++) {
if (commandWithArgs[i].charAt(0) == '"'
&& commandWithArgs[i].charAt(commandWithArgs[i].length() - 1) == '"') {
Expand All @@ -135,7 +143,7 @@ private void parse(String[] commandWithArgs) throws Exception {
}
}
try {
command.execute(connector, args);
command.execute(state, args);
} catch (RuntimeException e) {
throw new StopLineInterpretationException(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

import ru.fizteh.fivt.storage.structured.TableProvider;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.DbTable;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.Helper;
import ru.fizteh.fivt.students.vadim_mazaev.DataBase.TableManagerFactory;
import ru.fizteh.fivt.students.vadim_mazaev.DataBaseTest.TestHelper;
import ru.fizteh.fivt.students.vadim_mazaev.Logging.LoggingProxyFactoryImpl;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.Helper;
import ru.fizteh.fivt.students.vadim_mazaev.Utility.TestHelper;

public class LoggingProxyFactoryImplTest {
private TableManagerFactory test;
Expand Down
Loading