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
Готовчиц Максим, 396, Parallel #585
Open
MaximGotovchits
wants to merge
19
commits into
dkomanov:master
Choose a base branch
from
MaximGotovchits:Parallel
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
Changes from all commits
Commits
Show all changes
19 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 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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
| 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 ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTable; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| public class Main { // Using JSON format. | ||
| public static void main(final String[] args) throws Exception { | ||
| new MakeDirs().execute(null); | ||
| Set<Command> commandSet = new HashSet<>(); | ||
| ObjectTable currentTableObject = null; | ||
| boolean fromCmdLine; | ||
| if (args.length == 0) { | ||
| fromCmdLine = false; | ||
| fillCommandSet(commandSet, currentTableObject, fromCmdLine); | ||
| Interpreter interpreter = new Interpreter(commandSet); | ||
| interpreter.startUp(null, false); | ||
| } else { | ||
| fromCmdLine = true; | ||
| fillCommandSet(commandSet, currentTableObject, fromCmdLine); | ||
| Interpreter interpreter = new Interpreter(commandSet); | ||
| String cmd = String.join(" ", args); | ||
| cmd = cmd.replaceAll("\\s+", " "); | ||
| System.out.println(cmd); | ||
| interpreter.startUp(cmd, fromCmdLine); | ||
| new Exit().execute(null); | ||
| } | ||
| } | ||
|
|
||
| private static void fillCommandSet(Set<Command> commandSet, ObjectTable currentTableObject, boolean fromCmdLine) { | ||
| commandSet.add(new Commit()); | ||
| commandSet.add(new Create()); | ||
| commandSet.add(new Drop()); | ||
| commandSet.add(new Exit()); | ||
| commandSet.add(new FillTable()); | ||
| commandSet.add(new Get()); | ||
| commandSet.add(new List()); | ||
| commandSet.add(new MakeDirs()); | ||
| commandSet.add(new Put()); | ||
| commandSet.add(new Remove()); | ||
| commandSet.add(new Rollback()); | ||
| commandSet.add(new ShowTables()); | ||
| commandSet.add(new Use()); | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTable; | ||
|
|
||
| import java.nio.charset.Charset; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| public class CommandTools { | ||
| protected static final String DATA_BASE_NAME = System.getProperty("fizteh.db.dir"); | ||
| static boolean tableIsChosen = false; | ||
| static final int DIR_NUM = 16; | ||
| static final int FILE_NUM = 16; | ||
| static final String DIR_EXT = ".dir"; | ||
| static final String FILE_EXT = ".dat"; | ||
| static String usingTableName; | ||
| public static final Charset UTF = StandardCharsets.UTF_8; | ||
| static ObjectTable currentTable; | ||
| public static void informToChooseTable() { | ||
| System.err.println("table is not chosen"); | ||
| } | ||
|
|
||
| public static boolean amountOfArgumentsIs(int argsAmount, String[] cmd) { | ||
| return argsAmount == cmd.length; | ||
| } | ||
|
|
||
| public static boolean amountOfArgumentsIsMoreThan(int argsAmount, String[] cmd) { | ||
| return argsAmount < cmd.length; | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
|
|
||
| public class Commit extends Command { | ||
|
|
||
| @Override | ||
|
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. Есть |
||
| public boolean execute(String[] cmd) { | ||
| if (CommandTools.amountOfArgumentsIs(1, cmd)) { | ||
| CommandTools.currentTable.commit(); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "commit"; | ||
| } | ||
| } | ||
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTable; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTableProvider; | ||
|
|
||
| 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) { | ||
| 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); | ||
| } catch (Exception e) { | ||
| System.err.println(e); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public List<Class<?>> getTypeList(String line) { | ||
| 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; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
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,25 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectTableProvider; | ||
|
|
||
| public class Drop extends Command { | ||
| @Override | ||
| public boolean execute(String[] cmd) { | ||
| if (CommandTools.amountOfArgumentsIs(2, cmd)) { | ||
| try { | ||
| new ObjectTableProvider().removeTable(cmd[1]); | ||
| System.out.println("dropped"); | ||
| } catch (Exception e) { | ||
| System.err.println(e); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "drop"; | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
| 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) { | ||
| if (CommandTools.currentTable != null && exitAndUseAvailable()) { | ||
| new FillTable().execute(null); | ||
| } else { | ||
| return false; | ||
| } | ||
| System.exit(0); | ||
| return true; | ||
| } | ||
|
|
||
| public boolean exitAndUseAvailable() { | ||
| if (CommandTools.currentTable != null) { | ||
| int uncommitedChanges = CommandTools.currentTable.storage.get().size() | ||
| - CommandTools.currentTable.commitStorage.size(); | ||
| if (uncommitedChanges == 0 || !CommandTools.tableIsChosen) { | ||
| return true; | ||
| } | ||
| System.out.println(uncommitedChanges + " uncommited changes"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "exit"; | ||
| } | ||
| } | ||
|
|
||
|
|
55 changes: 55 additions & 0 deletions
55
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/FillTable.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,55 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectStoreable; | ||
| import java.io.DataOutputStream; | ||
| import java.io.File; | ||
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
| import java.nio.charset.Charset; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.Map; | ||
|
|
||
| public class FillTable extends Command { | ||
| private final Charset coding = StandardCharsets.UTF_8; | ||
|
|
||
| @Override | ||
| public boolean execute(String[] cmd) { | ||
| for (Map.Entry<String, ObjectStoreable> entry : CommandTools.currentTable.commitStorage.entrySet()) { | ||
| int hashCode = entry.getKey().hashCode(); | ||
|
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. Это выгрузка базы? Тогда:
|
||
| Integer nDirectory = hashCode % CommandTools.DIR_NUM; | ||
| Integer nFile = hashCode / CommandTools.DIR_NUM % CommandTools.FILE_NUM; | ||
| Path fileName = Paths.get(CommandTools.DATA_BASE_NAME, CommandTools.currentTable.getName(), nDirectory | ||
| + CommandTools.DIR_EXT); | ||
| File file = new File(fileName.toString()); | ||
| if (!file.exists()) { | ||
| file.mkdir(); | ||
| } | ||
| fileName = Paths.get(fileName.toString(), nFile + CommandTools.FILE_EXT); | ||
| file = new File(fileName.toString()); | ||
| try { | ||
| if (!file.exists()) { | ||
| file.createNewFile(); | ||
| } | ||
| byte[] bytesKey = (" " + entry.getKey() + " ").getBytes(coding); | ||
| DataOutputStream stream = new DataOutputStream(new FileOutputStream(fileName.toString(), true)); | ||
| stream.write(bytesKey.length); | ||
| stream.write(bytesKey); | ||
| byte[] bytesVal = ((" " + entry.getValue().serialisedValue + " ").getBytes(coding)); | ||
| stream.write(bytesVal.length - 1); | ||
| stream.write(bytesVal); | ||
| stream.close(); | ||
| } catch (IOException e) { | ||
| System.err.println(e); | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "fill table"; | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.objects.ObjectStoreable; | ||
|
|
||
| public class Get extends Command { | ||
| @Override | ||
| public boolean execute(String[] cmd) { | ||
| if (CommandTools.amountOfArgumentsIs(2, cmd)) { | ||
| try { | ||
| if (CommandTools.tableIsChosen) { | ||
| ObjectStoreable temp = (ObjectStoreable) CommandTools.currentTable.get(cmd[1]); | ||
| if (temp == null) { | ||
| System.err.println("not found"); | ||
| } else { | ||
| System.out.println("found"); | ||
| System.out.println(temp.serialisedValue); | ||
| } | ||
| } else { | ||
| CommandTools.informToChooseTable(); | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println(e); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| @Override | ||
| public String getCmdName() { | ||
| return "get"; | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
|
|
||
| public class List extends Command { | ||
| @Override | ||
| public boolean execute(String[] cmd) { | ||
| if (CommandTools.amountOfArgumentsIs(1, cmd)) { | ||
| if (CommandTools.tableIsChosen) { | ||
| java.util.List<String> list = CommandTools.currentTable.list(); | ||
| int size = 0; | ||
| for (Object iter : list) { | ||
| if (size < CommandTools.currentTable.storage.get().size() - 1) { | ||
| System.out.print(iter + ", "); | ||
| } else { | ||
| System.out.print(iter); | ||
| } | ||
| ++size; | ||
| } | ||
| if (size != 0) { | ||
| System.out.println(); | ||
| } | ||
| } else { | ||
| CommandTools.informToChooseTable(); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "list"; | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
src/ru/fizteh/fivt/students/MaximGotovchits/Parallel/base/commands/MakeDirs.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,33 @@ | ||
| package ru.fizteh.fivt.students.MaximGotovchits.Parallel.base.commands; | ||
|
|
||
| import ru.fizteh.fivt.students.MaximGotovchits.Parallel.interpreter.Command; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| public class MakeDirs extends Command { | ||
| @Override | ||
| public boolean execute(String[] cmd) { | ||
| File file = new File(CommandTools.DATA_BASE_NAME); | ||
| if (!file.exists()) { | ||
| file.mkdirs(); | ||
|
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. Этот код нужен при использовании базы сторонним приложением в обход интерпретатора? Если да, то часть кода должна уехать в класс базы |
||
| } 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"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCmdName() { | ||
| return "make"; | ||
| } | ||
| } | ||
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.
Повтор кода со строками 18-19. Вынести до ифа
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.
Там нужно определить значение fromCmdLine, поэтому строку 18 нельзя вынести вверх, а строку 19 можно написать только после 18, поэтому ее тоже нельзя вверх выносить