Grep command (task 2) - #2
Conversation
f0b3658 to
6986bbe
Compare
artbez
left a comment
There was a problem hiding this comment.
Не нашел обоснование выбора библиотеки argparse4j
|
|
||
| @Override | ||
| public String execute(List<IToken> args, String inputStream) { | ||
| Namespace namespace = null; |
| regex = regex.toLowerCase(); | ||
| } | ||
|
|
||
|
|
| } | ||
| String regex = namespace.getString("regex"); | ||
| String inputStreamForMatcher = inputStream; | ||
| String[] lines = inputStream.split("\n"); |
There was a problem hiding this comment.
Не работает команда
grep group gradle.build
Не нашел места, где читается файл, который указывается команде grep в качестве аргумента
| return e.toString(); | ||
| } | ||
| String regex = namespace.getString("regex"); | ||
| String inputStreamForMatcher = inputStream; |
| if (printAfter > 0) { | ||
| printAfter--; | ||
| stringBuilder.append(line).append('\n'); | ||
| continue; |
There was a problem hiding this comment.
При вызове функции
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); |
There was a problem hiding this comment.
Хорошо бы проверить что аргумент при -A не отрицателен
b3b5158 to
7e54301
Compare
artbez
left a comment
There was a problem hiding this comment.
Осталось добавить обоснование выбора библиотеки и CI. В остальном все неплохо.
|
|
||
| public class GrepCommand implements IToken, IExecutable { | ||
|
|
||
| private String splitWordsRegex = "^|[ |\\n|\\r|\\t]+"; |
There was a problem hiding this comment.
Для неизменяемых полей следует использовать final модификатор.
|
|
||
| @Test | ||
| public void testExecutionWithoutFlagsWithNotSubsting() { | ||
| GrepCommand command = new GrepCommand(); |
There was a problem hiding this comment.
Такого рода копипаст выносят в @Before
|
|
||
| public class GrepCommandTest { | ||
| String goodFile = "src/test/resources/fileWithTestWord"; | ||
| String badFile = "src/test/resources/fileWithoutTestWord"; |
There was a problem hiding this comment.
Это вообще пакетные неконстантные поля, хотя должны были бы быть private и final
| } | ||
|
|
||
| Pattern pattern = Pattern.compile(regex); | ||
| StringBuilder stringBuilder = new StringBuilder(); |
There was a problem hiding this comment.
А вот в Java 10 это было бы var stringBuilder = new StringBuilder();, что короче и не менее читаемо
No description provided.