diff options
| author | Kostya <mail@sartin.in> | 2026-08-10 20:21:55 +0000 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-08-10 20:21:55 +0000 |
| commit | 9d19a3187789f01d6dbbc73d14c7f90df3e67560 (patch) | |
| tree | f93b0727ef25ef046e7f4d90c195cdd4bcf19348 /ui-console/src/main/java/market | |
| parent | 34deee1c5ef2df5ba2514f77ec4dfd4a684a9d13 (diff) | |
| download | guess-market-9d19a3187789f01d6dbbc73d14c7f90df3e67560.tar.gz guess-market-9d19a3187789f01d6dbbc73d14c7f90df3e67560.tar.xz guess-market-9d19a3187789f01d6dbbc73d14c7f90df3e67560.zip | |
Move engine contracts to api module, add I/O provider abstraction and PicoContainer wiring
Relocates GuessMarketEngine/GuessMarketContext into market.guess.api so
engine and ui-console depend on a shared contract instead of engine
internals, and makes context loading async (CompletableFuture). Adds
InputProvider/OutputProvider interfaces with console implementations,
wires the console app's Menu through a PicoContainer, and adds the
generated model classes plus vendored picocontainer jar needed to build it.
Diffstat (limited to 'ui-console/src/main/java/market')
6 files changed, 121 insertions, 1 deletions
diff --git a/ui-console/src/main/java/market/guess/ui/console/App.java b/ui-console/src/main/java/market/guess/ui/console/App.java index 06be86d..5158478 100644 --- a/ui-console/src/main/java/market/guess/ui/console/App.java +++ b/ui-console/src/main/java/market/guess/ui/console/App.java | |||
| @@ -1,7 +1,31 @@ | |||
| 1 | package market.guess.ui.console; | 1 | package market.guess.ui.console; |
| 2 | 2 | ||
| 3 | import org.picocontainer.DefaultPicoContainer; | ||
| 4 | import org.picocontainer.behaviors.Caching; | ||
| 5 | |||
| 3 | public class App { | 6 | public class App { |
| 4 | public static void main() { | 7 | public static void main() { |
| 5 | IO.println("Hello World"); | 8 | var pico = new DefaultPicoContainer(new Caching()); |
| 9 | |||
| 10 | pico.addComponent(ConsoleInputProviderFactory.class); | ||
| 11 | pico.addComponent(ConsoleOutputProviderFactory.class); | ||
| 12 | pico.addComponent(Menu.class); | ||
| 13 | |||
| 14 | pico.start(); | ||
| 15 | // var context = new LocalGuessMarketContext(); | ||
| 16 | // var factory = new ConsoleInputProviderFactory(); | ||
| 17 | // var oFactory = new ConsoleOutputProviderFactory(); | ||
| 18 | // | ||
| 19 | // context.LoadAsync(); | ||
| 20 | // printMenu(oFactory.create()); | ||
| 21 | // | ||
| 22 | // try (var provider = factory.create()) { | ||
| 23 | // var input = provider.nextInt(); | ||
| 24 | // while (input != 0) { | ||
| 25 | // input = provider.nextInt(); | ||
| 26 | // } | ||
| 27 | // } catch (Exception ex) { | ||
| 28 | // ex.printStackTrace(); | ||
| 29 | // | ||
| 6 | } | 30 | } |
| 7 | } | 31 | } |
diff --git a/ui-console/src/main/java/market/guess/ui/console/ConsoleInputProvider.java b/ui-console/src/main/java/market/guess/ui/console/ConsoleInputProvider.java new file mode 100644 index 0000000..71de3be --- /dev/null +++ b/ui-console/src/main/java/market/guess/ui/console/ConsoleInputProvider.java | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | package market.guess.ui.console; | ||
| 2 | |||
| 3 | import java.util.Scanner; | ||
| 4 | import market.guess.InputProvider; | ||
| 5 | |||
| 6 | public class ConsoleInputProvider implements InputProvider { | ||
| 7 | private final Scanner scanner = new Scanner(System.in); | ||
| 8 | |||
| 9 | @Override | ||
| 10 | public int nextInt() { | ||
| 11 | while (!scanner.hasNextInt()) { | ||
| 12 | scanner.next(); | ||
| 13 | } | ||
| 14 | |||
| 15 | return scanner.nextInt(); | ||
| 16 | } | ||
| 17 | |||
| 18 | @Override | ||
| 19 | public void close() throws Exception { | ||
| 20 | scanner.close(); | ||
| 21 | } | ||
| 22 | } | ||
diff --git a/ui-console/src/main/java/market/guess/ui/console/ConsoleInputProviderFactory.java b/ui-console/src/main/java/market/guess/ui/console/ConsoleInputProviderFactory.java new file mode 100644 index 0000000..d122549 --- /dev/null +++ b/ui-console/src/main/java/market/guess/ui/console/ConsoleInputProviderFactory.java | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | package market.guess.ui.console; | ||
| 2 | |||
| 3 | import market.guess.InputProvider; | ||
| 4 | import market.guess.InputProviderFactory; | ||
| 5 | |||
| 6 | public class ConsoleInputProviderFactory implements InputProviderFactory { | ||
| 7 | |||
| 8 | @Override | ||
| 9 | public InputProvider create() { | ||
| 10 | return new ConsoleInputProvider(); | ||
| 11 | } | ||
| 12 | } | ||
diff --git a/ui-console/src/main/java/market/guess/ui/console/ConsoleOutputProvider.java b/ui-console/src/main/java/market/guess/ui/console/ConsoleOutputProvider.java new file mode 100644 index 0000000..eb9f31b --- /dev/null +++ b/ui-console/src/main/java/market/guess/ui/console/ConsoleOutputProvider.java | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | package market.guess.ui.console; | ||
| 2 | |||
| 3 | import market.guess.OutputProvider; | ||
| 4 | |||
| 5 | public class ConsoleOutputProvider implements OutputProvider { | ||
| 6 | |||
| 7 | @Override | ||
| 8 | public void print(Object object) { | ||
| 9 | IO.print(object); | ||
| 10 | } | ||
| 11 | |||
| 12 | @Override | ||
| 13 | public void println(Object object) { | ||
| 14 | IO.println(object); | ||
| 15 | } | ||
| 16 | } | ||
diff --git a/ui-console/src/main/java/market/guess/ui/console/ConsoleOutputProviderFactory.java b/ui-console/src/main/java/market/guess/ui/console/ConsoleOutputProviderFactory.java new file mode 100644 index 0000000..6db91fc --- /dev/null +++ b/ui-console/src/main/java/market/guess/ui/console/ConsoleOutputProviderFactory.java | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | package market.guess.ui.console; | ||
| 2 | |||
| 3 | import market.guess.OutputProvider; | ||
| 4 | import market.guess.OutputProviderFactory; | ||
| 5 | |||
| 6 | public class ConsoleOutputProviderFactory implements OutputProviderFactory { | ||
| 7 | |||
| 8 | @Override | ||
| 9 | public OutputProvider create() { | ||
| 10 | return new ConsoleOutputProvider(); | ||
| 11 | } | ||
| 12 | } | ||
diff --git a/ui-console/src/main/java/market/guess/ui/console/Menu.java b/ui-console/src/main/java/market/guess/ui/console/Menu.java new file mode 100644 index 0000000..a5217a4 --- /dev/null +++ b/ui-console/src/main/java/market/guess/ui/console/Menu.java | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | package market.guess.ui.console; | ||
| 2 | |||
| 3 | import market.guess.OutputProvider; | ||
| 4 | import market.guess.OutputProviderFactory; | ||
| 5 | import org.picocontainer.Startable; | ||
| 6 | |||
| 7 | public class Menu implements Startable { | ||
| 8 | private final OutputProvider outputProvider; | ||
| 9 | |||
| 10 | public Menu(OutputProviderFactory factory) { | ||
| 11 | this.outputProvider = factory.create(); | ||
| 12 | } | ||
| 13 | |||
| 14 | @Override | ||
| 15 | public void start() { | ||
| 16 | printMenu(outputProvider); | ||
| 17 | } | ||
| 18 | |||
| 19 | @Override | ||
| 20 | public void stop() { | ||
| 21 | // TODO Auto-generated method stub | ||
| 22 | throw new UnsupportedOperationException("Unimplemented method 'stop'"); | ||
| 23 | } | ||
| 24 | |||
| 25 | private static void printMenu(OutputProvider provider) { | ||
| 26 | provider.println("[1] Load Marketplace"); | ||
| 27 | provider.println("[2] Save Marketplace"); | ||
| 28 | provider.println("[3] Show All Events"); | ||
| 29 | provider.println("[4] Event Info"); | ||
| 30 | provider.println("[5] Participate In Event"); | ||
| 31 | provider.println("[6] Close Event"); | ||
| 32 | provider.println("[7] Exit"); | ||
| 33 | } | ||
| 34 | } | ||