Skip to content

Эмирзаков - 3 tasks (С)#40

Open
Damir-Em wants to merge 17 commits intodemologin:mainfrom
Damir-Em:main
Open

Эмирзаков - 3 tasks (С)#40
Damir-Em wants to merge 17 commits intodemologin:mainfrom
Damir-Em:main

Conversation

@Damir-Em
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 class Result {
public final int key;
public final String text;
Copy link
Owner

Choose a reason for hiding this comment

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

Используйте Java 16+ Records вместо вложенного статического класса Result. Это сократит код и сделает данные иммутабельными (Data Transfer Object).


public final class StopWords {
public static final Set<String> RUSSIAN = new HashSet<>(Arrays.asList(
"и", "в", "на", "не", "что", "как", "я", "он", "она", "но", "с",
Copy link
Owner

Choose a reason for hiding this comment

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

Используйте Set.of(...) вместо HashSet(Arrays.asList(...)). В Java 9+ это создает немодифицируемое множество и выглядит чище.

char shifted = alphabet.getCharByIndex(index + key);
return isUpper ? Character.toUpperCase(shifted) : shifted;
}

Copy link
Owner

Choose a reason for hiding this comment

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

В Java 21+ для выбора реализации или обработки данных стоит использовать Pattern Matching для switch, если планируется расширение типов действий.

}
return count;
}

Copy link
Owner

Choose a reason for hiding this comment

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

Используйте Stream API для подсчета слов: tokens.stream().filter(stopSet::contains).count(). Это декларативно и читаемо.


public Alphabet(String text) {
if (text.matches(".*[а-яА-ЯёЁ].*")) {
ALPHABET = RUSSIAN;
Copy link
Owner

Choose a reason for hiding this comment

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

Логика выбора алфавита в конструкторе нарушает SRP. Лучше использовать паттерн Factory или статические фабричные методы, возвращающие разные экземпляры Alphabet.

int matches = Math.max(rusMatches, engMatches);

if (matches > bestScore) {
bestScore = matches;
Copy link
Owner

Choose a reason for hiding this comment

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

Магическое число 1000 для shortenForAnalysis следует вынести в именованную константу (static final).

public class TextUtils {
private static final Pattern WORD_PATTERN = Pattern.compile("\\b[а-яёА-ЯЁa-zA-Z']+\\b");

public static String normalize(String text) {
Copy link
Owner

Choose a reason for hiding this comment

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

Регулярное выражение компилируется каждый раз при вызове replaceAll. Используйте предварительно скомпилированный статический Pattern.

package com.javarush.emirzakov.model;

public class Alphabet {
private final char[] ALPHABET;
Copy link
Owner

Choose a reason for hiding this comment

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

Поле ALPHABET нарушает naming convention. Поля экземпляра должны быть в camelCase (alphabet), даже если они final.


int bestScore = -1;
Result best = null;

Copy link
Owner

Choose a reason for hiding this comment

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

Метод findBestByStopWords слишком длинный. Разбейте его на мелкие методы: calculateScore, processCandidate.


import com.javarush.emirzakov.model.Alphabet;

public abstract class CryptoAction {
Copy link
Owner

Choose a reason for hiding this comment

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

Сделайте CryptoAction sealed интерфейсом, разрешая только конкретные реализации (Encrypt/Decrypt). Это обеспечит безопасность иерархии в Java 21.

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.

Поставил оценку С из-за сроков, так было бы конечно больше.

@demologin demologin changed the title Эмирзаков - 3 tasks Эмирзаков - 3 tasks (С) Jan 4, 2026
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.

2 participants