This repository was archived by the owner on Sep 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
Parallel1.1 #602
Open
MaximGotovchits
wants to merge
25
commits into
dkomanov:master
Choose a base branch
from
MaximGotovchits:Parallel1.1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Parallel1.1 #602
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7fea5b6
Готовчиц Максим, 396, Storeable
MaximGotovchits cf2d795
Готовчиц Максим, 396, Storeable
MaximGotovchits f915545
Готовчиц Максим, 396, Storable
MaximGotovchits f8567f3
Готовчиц Макисм, 396, Storable
MaximGotovchits 421371d
Готовчиц Максим, Storeable, 396
MaximGotovchits 78f2eff
Готовчиц Максим, Storeable, 396
MaximGotovchits 7795b38
Готовчиц Максим, Storeable, 396
MaximGotovchits e613dc2
Готовчиц Максим, 396, Storable
MaximGotovchits bd030d1
Готовчиц Максим, 396, Storable
MaximGotovchits 509e893
Edite
MaximGotovchits 24bcb5e
Готовчиц Максим, 396, Parallel
MaximGotovchits 2736957
Parallel
MaximGotovchits 674eeec
New structure
MaximGotovchits 4f2444c
Merge branch 'fix-web-tasks' of https://github.com/dkomanov/fizteh-ja…
MaximGotovchits df9e427
Максим Готовчиц, Parallel, 396
MaximGotovchits 768c00f
Готовчиц Максим, Parallel, 396
MaximGotovchits 0e7eae8
Готовчиц Максим, Parallel, 396
MaximGotovchits 3138e18
Готовчиц Максим, 396, Parallel
MaximGotovchits 10616cf
Готовчиц Максим, 396, Parallel
MaximGotovchits 16a1b22
Parallel
MaximGotovchits 14ca53e
Parallel
MaximGotovchits 3985e62
Parallel
MaximGotovchits a846f09
Parallel
MaximGotovchits 9f8fa63
Parallel
MaximGotovchits 0cf94d8
Parallel
MaximGotovchits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/Main.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands.*; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Interpreter; | ||
| import java.io.File; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| public class Main { // Using JSON format. | ||
| public static void main(final String[] args) throws Exception { | ||
| boolean fromCmdLine; | ||
| if (args.length == 0) { | ||
| fromCmdLine = false; | ||
| launchInterpreter(fromCmdLine, null); | ||
| } else { | ||
| fromCmdLine = true; | ||
| String cmd = String.join(" ", args).replaceAll("\\s+", " "); | ||
| launchInterpreter(fromCmdLine, cmd); | ||
| new Exit().execute(null); | ||
| } | ||
| } | ||
|
|
||
| private static void launchInterpreter(boolean fromCmdLine, String cmd) { | ||
| Set<Command> commandSet = new HashSet<>(); | ||
| makeDirs(); | ||
| fillCommandSet(commandSet); | ||
| Interpreter interpreter = new Interpreter(commandSet); | ||
| interpreter.startUp(cmd, fromCmdLine); | ||
| } | ||
|
|
||
| private static void fillCommandSet(Set<Command> commandSet) { | ||
| commandSet.add(new Commit()); | ||
| commandSet.add(new Create()); | ||
| commandSet.add(new Drop()); | ||
| commandSet.add(new Exit()); | ||
| commandSet.add(new Get()); | ||
| commandSet.add(new List()); | ||
| commandSet.add(new Put()); | ||
| commandSet.add(new Remove()); | ||
| commandSet.add(new Rollback()); | ||
| commandSet.add(new ShowTables()); | ||
| commandSet.add(new Use()); | ||
| } | ||
|
|
||
| private static void makeDirs() { | ||
| File file = new File(CommandTools.DATA_BASE_NAME); | ||
| if (!file.exists()) { | ||
| file.mkdirs(); | ||
| } else { | ||
| if (!file.isDirectory()) { | ||
| System.err.println(CommandTools.DATA_BASE_NAME + " is not a directory"); | ||
| System.exit(1); | ||
| } else { | ||
| for (File sub : file.listFiles()) { | ||
| if (!sub.isDirectory() && !sub.isHidden()) { | ||
| System.err.println(CommandTools.DATA_BASE_NAME + File.separator | ||
| + sub.getName() + " is not a directory"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/CommandTools.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTable; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTableProvider; | ||
|
|
||
| public class CommandTools { | ||
| static boolean tableIsChosen = false; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Убрать эту переменную. Она однозначно вычисляется по |
||
| public static final String DATA_BASE_NAME = System.getProperty("fizteh.db.dir"); | ||
| private static ObjectTable currentTableObject; | ||
| static ObjectTableProvider currentTableProvider = new ObjectTableProvider(System.getProperty("fizteh.db.dir")); | ||
| static void informToChooseTable() { | ||
| System.err.println("table is not chosen"); | ||
| } | ||
|
|
||
| public static ObjectTable getUsingTable() { | ||
| return currentTableObject; | ||
| } | ||
|
|
||
| static boolean amountOfArgumentsIs(int argsAmount, String[] cmd) { | ||
| return argsAmount == cmd.length; | ||
| } | ||
|
|
||
| static boolean amountOfArgumentsIsMoreThan(int argsAmount, String[] cmd) { | ||
| return argsAmount < cmd.length; | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
...izteh/fivt/students/MaximGotovchits/Parallel/base/commands/CommandWithCheckedNumArgs.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
|
|
||
| public abstract class CommandWithCheckedNumArgs extends Command { | ||
| @Override | ||
| public boolean execute(String[] cmd, int args) { | ||
| if (CommandTools.amountOfArgumentsIs(args, cmd)) { | ||
| executeWithCompleteArgs(cmd); | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| abstract void executeWithCompleteArgs(String[] cmd); | ||
| } | ||
|
|
13 changes: 13 additions & 0 deletions
13
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/Commit.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| public class Commit extends CommandWithCheckedNumArgs { | ||
| @Override | ||
| void executeWithCompleteArgs(String[] cmd) { | ||
| CommandTools.getUsingTable().commit(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "commit"; | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/Create.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTable; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTableProvider; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
|
|
||
| public class Create extends Command { | ||
| private static final String SPLIT_BY_RIGHT_BRACKET = "\\s*\\)\\s*"; | ||
| private static final String SPLIT_BY_LEFT_BRACKET = "\\s*\\(\\s*"; | ||
| private static final String SPLIT_BY_SPACE = "\\s+"; | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "create"; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean execute(String[] cmd, int args) { | ||
| if (CommandTools.amountOfArgumentsIsMoreThan(2, cmd)) { | ||
| String createParameter; // (...) - type list. | ||
| String tableName = cmd[1]; | ||
| createParameter = String.join(" ", Arrays.copyOfRange(cmd, 2, cmd.length)); | ||
| List<Class<?>> typeList; | ||
| try { | ||
| typeList = getTypeList(createParameter); | ||
| if (typeList != null) { | ||
| if (new ObjectTableProvider().createTable(tableName, typeList) != null) { | ||
| System.out.println("created"); | ||
| } else { | ||
| System.out.println(tableName + " exists"); | ||
| } | ||
| } else { | ||
| return false; | ||
| } | ||
| } catch (IOException e) { | ||
| System.err.println(e); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public List<Class<?>> getTypeList(String line) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я просил написать тесты на этот метод
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ObjectTable temp = new ObjectTable(); | ||
| List<Class<?>> typeList = new LinkedList<>(); | ||
| line = line.replaceAll(SPLIT_BY_RIGHT_BRACKET, ""); | ||
| line = line.replaceAll(SPLIT_BY_LEFT_BRACKET, ""); | ||
| String[] tmp = line.split(SPLIT_BY_SPACE); | ||
| for (String str : tmp) { | ||
| Class<?> type = temp.getType(str); | ||
| if (type != null) { | ||
| typeList.add(type); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| return typeList; | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/Drop.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTableProvider; | ||
|
|
||
| public class Drop extends CommandWithCheckedNumArgs { | ||
| @Override | ||
| void executeWithCompleteArgs(String[] cmd) { | ||
| try { | ||
| new ObjectTableProvider().removeTable(cmd[1]); | ||
| System.out.println("dropped"); | ||
| } catch (Exception e) { | ||
| System.err.println(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "drop"; | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/Exit.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
|
|
||
| public class Exit extends Command { | ||
| @Override | ||
| public boolean execute(String[] cmd, int args) { | ||
| if (CommandTools.getUsingTable() != null && exitAndUseAvailable()) { | ||
| CommandTools.currentTableProvider.fillTable(); | ||
| } else { | ||
| return false; | ||
| } | ||
| System.exit(0); | ||
| return true; | ||
| } | ||
|
|
||
| public boolean exitAndUseAvailable() { | ||
| if (CommandTools.getUsingTable() != null) { | ||
| int uncommitedChanges = CommandTools.currentTableProvider.getChangesNumber(); | ||
| if (uncommitedChanges == 0 || !CommandTools.tableIsChosen) { | ||
| return true; | ||
| } | ||
| System.out.println(uncommitedChanges + " uncommited changes"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "exit"; | ||
| } | ||
| } | ||
|
|
||
|
|
30 changes: 30 additions & 0 deletions
30
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/Get.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectStoreable; | ||
|
|
||
| public class Get extends CommandWithCheckedNumArgs { | ||
| @Override | ||
| void executeWithCompleteArgs(String[] cmd) { | ||
| try { | ||
| if (CommandTools.tableIsChosen) { | ||
| ObjectStoreable temp = (ObjectStoreable) CommandTools.getUsingTable() | ||
| .get(cmd[1]); | ||
| if (temp == null) { | ||
| System.err.println("not found"); | ||
| } else { | ||
| System.out.println("found"); | ||
| System.out.println(temp.getSerialisedValue()); | ||
| } | ||
| } else { | ||
| CommandTools.informToChooseTable(); | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "get"; | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/List.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectStoreable; | ||
|
|
||
| public class List extends CommandWithCheckedNumArgs { | ||
| @Override | ||
| void executeWithCompleteArgs(String[] cmd) { | ||
| try { | ||
| if (CommandTools.tableIsChosen) { | ||
| ObjectStoreable temp = (ObjectStoreable) CommandTools.getUsingTable() | ||
| .get(cmd[1]); | ||
| if (temp == null) { | ||
| System.err.println("not found"); | ||
| } else { | ||
| System.out.println("found"); | ||
| System.out.println(temp.getSerialisedValue()); | ||
| } | ||
| } else { | ||
| CommandTools.informToChooseTable(); | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "list"; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/Put.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectStoreable; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTableProvider; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public class Put extends Command { | ||
| public boolean execute(String[] cmd, int args) { | ||
| if (CommandTools.amountOfArgumentsIsMoreThan(2, cmd)) { | ||
| if (CommandTools.tableIsChosen) { | ||
| String putParameter; | ||
| String key = cmd[1]; | ||
| putParameter = String.join(" " , Arrays.copyOfRange(cmd, 2, cmd.length)); | ||
| try { | ||
| ObjectStoreable value = (ObjectStoreable) new ObjectTableProvider(). | ||
| deserialize(CommandTools.getUsingTable(), putParameter); | ||
| ObjectStoreable temp = (ObjectStoreable) CommandTools.getUsingTable() | ||
| .put(key, value); | ||
| if (temp == null) { | ||
| System.out.println("new"); | ||
| } else { | ||
| System.out.println("overwrite"); | ||
| } | ||
| } catch (Exception e) { | ||
| System.err.println(e); | ||
| } | ||
| } else { | ||
| CommandTools.informToChooseTable(); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "put"; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/Remove.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectStoreable; | ||
|
|
||
| public class Remove extends CommandWithCheckedNumArgs { | ||
| @Override | ||
| void executeWithCompleteArgs(String[] cmd) { | ||
| if (CommandTools.tableIsChosen) { | ||
| try { | ||
| ObjectStoreable temp = (ObjectStoreable) CommandTools.getUsingTable().remove(cmd[1]); | ||
| if (temp == null) { | ||
| System.out.println("not found"); | ||
| } else { | ||
| System.out.println("removed"); | ||
| } | ||
| } catch (Exception e) { | ||
| System.err.println(e); | ||
| } | ||
| } else { | ||
| CommandTools.informToChooseTable(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "remove"; | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/Rollback.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| public class Rollback extends CommandWithCheckedNumArgs { | ||
| @Override | ||
| void executeWithCompleteArgs(String[] cmd) { | ||
| CommandTools.getUsingTable().rollback(); | ||
| } | ||
| @Override | ||
| public String getCmdName() { | ||
| return "rollback"; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
заменить сигнатуру на
private static Set<Command> commandSet getCommandSet() {сет нужно создавать внутри этой функции