Skip to content

Golikov - 3 tasks complite.#41

Open
Golikov-DO wants to merge 8 commits intodemologin:mainfrom
Golikov-DO:main
Open

Golikov - 3 tasks complite.#41
Golikov-DO wants to merge 8 commits intodemologin:mainfrom
Golikov-DO:main

Conversation

@Golikov-DO
Copy link

No description provided.

Copy link
Owner

@demologin demologin left a comment

Choose a reason for hiding this comment

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

AI Generated Review

public static final String DEFAULT_FOLDER = System.getProperty("user.dir") + File.separator + "text" + File.separator;

public static final List<Character> ALPHABET_LIST = new ArrayList<>();

Copy link
Owner

Choose a reason for hiding this comment

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

Вместо ручного заполнения списка в static-блоке используйте Stream API: ruAlphabet.toLowerCase().chars().mapToObj(c -> (char)c).toList(). Это короче и использует современные возможности Java.


import com.javarush.golikov.entite.Result;

public interface MenuCommands {
Copy link
Owner

Choose a reason for hiding this comment

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

Используйте sealed interface для MenuCommands. Это гарантирует, что список команд ограничен и известен заранее, что улучшает безопасность и дизайн приложения (Java 17+).

fileWriter.write(Constants.ALPHABET[index]);
} else if (character == '\n') {
fileWriter.write(character);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Для вычисления индекса при отрицательных сдвигах используйте Math.floorMod(index + key, length). Это чище и надежнее, чем ручные манипуляции с Math.abs.


public Actions() {
actionMap.put(0, new Encryption());
actionMap.put(1, new Decoding());
Copy link
Owner

Choose a reason for hiding this comment

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

Используйте Map.of(0, new Encryption(), ...) для создания неизменяемой карты. Это более современный и лаконичный способ инициализации коллекций в Java.

while ((value = reader.read()) > -1) {
char character = (char) value;
if (Constants.ALPHABET_LIST.contains(character)) {
int index = Constants.ALPHABET_LIST.indexOf(character);
Copy link
Owner

Choose a reason for hiding this comment

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

Вызов Files.newBufferedReader внутри цикла приводит к многократному открытию файла. Прочитайте содержимое файла один раз перед циклом для повышения производительности.

public Result run() {
int menuIndex = showMenu.getMenuItem();
String[] parametrises = showMenu.getParameterises(menuIndex == 0 || menuIndex == 1);
return controller.doAction(menuIndex, parametrises);
Copy link
Owner

Choose a reason for hiding this comment

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

Условие menuIndex == 0 || menuIndex == 1 является 'хрупким'. Если порядок в меню изменится, логика сломается. Используйте полиморфизм для определения необходимости ключа.

return actionMap.get(actionIndex);
} catch (IllegalArgumentException e) {
throw new ApplicationExceptions("Пункт меню не реализован!", e);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Метод actionMap.get() не выбрасывает IllegalArgumentException. Блок try-catch здесь бесполезен. Достаточно проверки на null или containsKey.

Path sourceFile = Path.of(source);
Path targetFile = Path.of(target);

try (BufferedReader fileReader = Files.newBufferedReader(sourceFile);
Copy link
Owner

Choose a reason for hiding this comment

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

Вместо конкатенации путей через +=, используйте Path.resolve() или Path.of(dir, filename). Это кроссплатформенный и безопасный способ работы с путями.

@@ -0,0 +1,12 @@
package com.javarush.golikov.entite;

public record Result(String message, String resultCode) {
Copy link
Owner

Choose a reason for hiding this comment

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

Record автоматически генерирует toString. Переопределяйте его только если вам нужен специфический формат вывода, отличный от стандартного.

if (isKeyNeeded){
System.out.println("Введите ключ шифрования/дешифрования");
parameterises[2] = scanner.nextLine();
}
Copy link
Owner

Choose a reason for hiding this comment

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

Использование System.in напрямую через Scanner в ShowMenu затрудняет юнит-тестирование. Передавайте Scanner или InputStream через конструктор.

Copy link
Owner

@demologin demologin left a comment

Choose a reason for hiding this comment

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

поставила оценку C преимущественно из-за сроков, но и объем проекта тоже меньше ожидаемого

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants