Skip to content

Grep command (task 2) - #2

Open
ValchukDmitry wants to merge 17 commits into
masterfrom
grep_command
Open

Grep command (task 2)#2
ValchukDmitry wants to merge 17 commits into
masterfrom
grep_command

Conversation

@ValchukDmitry

Copy link
Copy Markdown
Owner

No description provided.

@artbez artbez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не нашел обоснование выбора библиотеки argparse4j

@artbez artbez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Хорошо бы добавить CI


@Override
public String execute(List<IToken> args, String inputStream) {
Namespace namespace = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно не писать ... = null

regex = regex.toLowerCase();
}


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

}
String regex = namespace.getString("regex");
String inputStreamForMatcher = inputStream;
String[] lines = inputStream.split("\n");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не работает команда
grep group gradle.build

Не нашел места, где читается файл, который указывается команде grep в качестве аргумента

return e.toString();
}
String regex = namespace.getString("regex");
String inputStreamForMatcher = inputStream;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

inputStreamForMatcher не используется

if (printAfter > 0) {
printAfter--;
stringBuilder.append(line).append('\n');
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

При вызове функции
cat build.gradle | grep -A 2 apply
Программа выдает результат
apply plugin: 'java'
apply plugin: 'application'
Что не верно

ArgumentParser parser = ArgumentParsers.newFor("Grep").build();
parser.addArgument("-w").dest("whole word").action(Arguments.storeTrue());
parser.addArgument("-i").dest("ignore case").action(Arguments.storeTrue());
parser.addArgument("-A").dest("after").setDefault(0).type(Integer.class);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Хорошо бы проверить что аргумент при -A не отрицателен

@artbez artbez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Осталось добавить обоснование выбора библиотеки и CI. В остальном все неплохо.


public class GrepCommand implements IToken, IExecutable {

private String splitWordsRegex = "^|[ |\\n|\\r|\\t]+";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Для неизменяемых полей следует использовать final модификатор.

@yurii-litvinov yurii-litvinov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В целом всё ок, зачтена


@Test
public void testExecutionWithoutFlagsWithNotSubsting() {
GrepCommand command = new GrepCommand();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Такого рода копипаст выносят в @Before


public class GrepCommandTest {
String goodFile = "src/test/resources/fileWithTestWord";
String badFile = "src/test/resources/fileWithoutTestWord";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это вообще пакетные неконстантные поля, хотя должны были бы быть private и final

}

Pattern pattern = Pattern.compile(regex);
StringBuilder stringBuilder = new StringBuilder();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А вот в Java 10 это было бы var stringBuilder = new StringBuilder();, что короче и не менее читаемо

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