Skip to content

Commit

Permalink
🪲 Ask the question before waiting for the input
Browse files Browse the repository at this point in the history
  • Loading branch information
evrignaud committed Oct 23, 2016
1 parent b44f9d1 commit c0b3d3e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/fim/model/DuplicateResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ protected void selectFilesToRemove(List<FileState> duplicatedFiles) {
}

while (true) {
Logger.out.printf(" Preserve files [1 - %d, all or a, none or n]: ", duplicatedFiles.size());
String inputLine = readInputLine();
if (manageAnswers(duplicatedFiles, inputLine)) {
break;
Expand All @@ -145,13 +146,11 @@ protected void selectFilesToRemove(List<FileState> duplicatedFiles) {

protected boolean manageAnswers(List<FileState> duplicatedFiles, String inputLine) {
boolean gotCorrectAnswer = false;
int count = duplicatedFiles.size();

for (FileState fileState : duplicatedFiles) {
fileState.setToRemove(true);
}

Logger.out.printf(" Preserve files [1 - %d, all or a, none or n]: ", count);
try (Scanner scanner = new Scanner(inputLine)) {
while (scanner.hasNext()) {
String answer = scanner.next();
Expand All @@ -168,7 +167,7 @@ protected boolean manageAnswers(List<FileState> duplicatedFiles, String inputLin

int index = safeParseInt(answer);

if (index >= 1 && index <= count) {
if (index >= 1 && index <= duplicatedFiles.size()) {
duplicatedFiles.get(index - 1).setToRemove(false);
gotCorrectAnswer = true;
}
Expand Down

0 comments on commit c0b3d3e

Please sign in to comment.