diff options
| author | Kostya <mail@sartin.in> | 2026-08-14 20:54:31 +0000 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-08-14 20:54:31 +0000 |
| commit | d77a70c48865592be9029aeb0c83b36c162ea31a (patch) | |
| tree | 219adfbeb1991b71433d5d36375e93fe73f81dec /ui-console/src | |
| parent | 001f6444fec8fcd5312028cfdae90f4f93424559 (diff) | |
| download | guess-market-d77a70c48865592be9029aeb0c83b36c162ea31a.tar.gz guess-market-d77a70c48865592be9029aeb0c83b36c162ea31a.tar.xz guess-market-d77a70c48865592be9029aeb0c83b36c162ea31a.zip | |
Switch TradingMechanism quantities to int, add yes/no and select prompts
TradingMechanism's q/quantity params move from long/long[] to int/int[]
to match the rest of the domain (Trade.quantity, Option counts, etc.
are already int).
Add InputProcessor.readYesNo and readSelect for upcoming menu commands
that need a confirm prompt or a pick-from-list prompt.
Diffstat (limited to 'ui-console/src')
| -rw-r--r-- | ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java b/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java index 4889c36..fc5422f 100644 --- a/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java +++ b/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | package market.guess.ui.console.io; | 1 | package market.guess.ui.console.io; |
| 2 | 2 | ||
| 3 | import java.util.List; | ||
| 3 | import java.util.Scanner; | 4 | import java.util.Scanner; |
| 5 | import java.util.function.Function; | ||
| 4 | 6 | ||
| 5 | public final class InputProcessor { | 7 | public final class InputProcessor { |
| 6 | private final Scanner scanner = new Scanner(System.in); | 8 | private final Scanner scanner = new Scanner(System.in); |
| @@ -67,6 +69,33 @@ public final class InputProcessor { | |||
| 67 | } | 69 | } |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 72 | public boolean readYesNo(String prompt) { | ||
| 73 | while (true) { | ||
| 74 | var raw = readLine("%s [Y/N]: ".formatted(prompt)).toLowerCase(); | ||
| 75 | |||
| 76 | switch (raw) { | ||
| 77 | case "y", "yes" -> { | ||
| 78 | return true; | ||
| 79 | } | ||
| 80 | case "n", "no" -> { | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | default -> IO.println("Please answer y/yes or n/no."); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | public <T> T readSelect(String prompt, List<T> items, Function<T, String> function) { | ||
| 89 | |||
| 90 | for (var i = 0; i < items.size(); i++) { | ||
| 91 | IO.println(" [%d]->> %s".formatted(i + 1, function.apply(items.get(i)))); | ||
| 92 | } | ||
| 93 | |||
| 94 | var pick = readInt(prompt, 1, items.size()); | ||
| 95 | |||
| 96 | return items.get(pick - 1); | ||
| 97 | } | ||
| 98 | |||
| 70 | private String nextLine() { | 99 | private String nextLine() { |
| 71 | return scanner.hasNextLine() ? scanner.nextLine() : null; | 100 | return scanner.hasNextLine() ? scanner.nextLine() : null; |
| 72 | } | 101 | } |