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 15 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

This file was deleted.

23 changes: 0 additions & 23 deletions src/ru/fizteh/fivt/students/AndrewTimokhin/DataBase/MainClass.java

This file was deleted.

68 changes: 0 additions & 68 deletions src/ru/fizteh/fivt/students/AndrewTimokhin/DataBase/ModeWork.java

This file was deleted.

57 changes: 0 additions & 57 deletions src/ru/fizteh/fivt/students/AndrewTimokhin/DataBase/Reader.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/ru/fizteh/fivt/students/AndrewTimokhin/DataBase/Write.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.fizteh.fivt.students.AndrewTimokhin.FileMap.DataBase;

import java.io.IOException;

/**
* Класс @class FactoryImplements отвечает за фабрику по созданию таблиц.
* Имплиментируя интерфейс TableProviderFactory, переопределяет метод по
* созданию провайдера базы данных.
*
* @author Timokhin Andrew
*/
public class FactoryImplements implements TableProviderFactory {

@Override
public TableProvider create(String dir) {
if (dir == null) {
throw new IllegalArgumentException(
"String representing directory is null");
}
try {
return new TableProviderImplements(dir);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.fizteh.fivt.students.AndrewTimokhin.FileMap.DataBase;

public class KeyNullAndNotFound extends Exception {

public KeyNullAndNotFound(String description) {
super(description);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package ru.fizteh.fivt.students.AndrewTimokhin.FileMap.DataBase;

import java.io.DataInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Класс @class Reader отвечает за физическое чтение данных из файловой системы.
*
*
* @author Timokhin Andrew
*/
public class Reader {

static final int TOTAL_SUB_STRING = 16;
static final String DIRECT = ".dir";
Copy link
Collaborator

Choose a reason for hiding this comment

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

DIRECTORY_SUFFIX

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f

private final String directory;

public Reader(String directory) {
this.directory = directory;
}

private void readKeyValue(DataInputStream rd, StringBuilder string) throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Параметры-значения лишь усложняют использование функции. Убери второй параметр. Эта функция должна возвращать прочитанное значение.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f

int length = rd.readInt();
for (int k = 0; k < length; k++) {
string
.append(rd.readChar());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Лишний перевод строки

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f

}
}

public void read(TableProviderImplements tp) throws IOException {
StringBuilder keyBuilder = new StringBuilder();
StringBuilder valueBuilder = new StringBuilder();
int length;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Лишняя локальная переменная. Если NetBeans тебе их не подкрашивает, то перейди на более функциональную IDE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f

String path = tp.getDir();
boolean dbExist = false;
File testDir = new File(path);
if (testDir.list() != null) {
for (String time : testDir.list()) {
Path pathToFile = Paths.get(path, time);
File checkDir = new File(pathToFile.toString());
if (checkDir.isDirectory()) {
dbExist = true;
tp.createTable(time);
TableImplement dataBase = (TableImplement) tp.getTable(time);
dataBase.setPath(tp.getDir());
for (int i = 0; i < TOTAL_SUB_STRING; i++) {
Integer numberDir = new Integer(i);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Эта переменная не нужна. Просто прибавляй число к строке:
i + DIRECTORY_SUFFIX

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f

Path pathToDb = Paths.get(path, time,
numberDir.toString() + DIRECT);
File locDB = new File(pathToDb.toString());
if (locDB.exists()) {
for (String file : locDB.list()) {
Path pathToLocalDb = Paths.get(
locDB.getAbsolutePath(), file);
try (DataInputStream rd = new DataInputStream(
new FileInputStream(
pathToLocalDb.toString()))) {
while (true) {
try {
readKeyValue(rd, keyBuilder);
readKeyValue(rd, valueBuilder);

dataBase.put(
keyBuilder.toString(),
valueBuilder.toString());
dataBase.getBackup().put(
keyBuilder.toString(),
valueBuilder.toString());
keyBuilder.replace(0,
keyBuilder.length(), "");
valueBuilder.replace(0,
valueBuilder.length(), "");
} catch (EOFException e) {
rd.close();
break;
}

}
} catch (FileNotFoundException exceptionFileNotFound) {
throw new RuntimeException(
exceptionFileNotFound);
}
}
}
}
}
}
}
if (!dbExist) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Последние пять строчек функции - лишние

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f

return;
}

return;
}
}
Loading