From 9d19a3187789f01d6dbbc73d14c7f90df3e67560 Mon Sep 17 00:00:00 2001 From: Kostya Date: Mon, 10 Aug 2026 20:21:55 +0000 Subject: 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. --- .../market/guess/engine/GuessMarketEngine.java | 7 - .../guess/engine/LocalGuessMarketService.java | 6 +- .../engine/mechanism/LmsrTradingMechanism.java | 5 + .../java/market/guess/engine/model/Comision.java | 94 +++++++++ .../java/market/guess/engine/model/GMEvent.java | 215 +++++++++++++++++++++ .../java/market/guess/engine/model/GMEvents.java | 80 ++++++++ .../java/market/guess/engine/model/GMLMSR.java | 60 ++++++ .../java/market/guess/engine/model/GMMethod.java | 70 +++++++ .../java/market/guess/engine/model/GMOptions.java | 80 ++++++++ .../market/guess/engine/model/GuessMarket.java | 70 +++++++ .../market/guess/engine/model/ObjectFactory.java | 167 ++++++++++++++++ .../guess/engine/provider/GuessMarketContext.java | 17 -- .../engine/provider/LocalGuessMarketContext.java | 81 ++++++++ 13 files changed, 926 insertions(+), 26 deletions(-) delete mode 100644 engine/src/main/java/market/guess/engine/GuessMarketEngine.java create mode 100644 engine/src/main/java/market/guess/engine/model/Comision.java create mode 100644 engine/src/main/java/market/guess/engine/model/GMEvent.java create mode 100644 engine/src/main/java/market/guess/engine/model/GMEvents.java create mode 100644 engine/src/main/java/market/guess/engine/model/GMLMSR.java create mode 100644 engine/src/main/java/market/guess/engine/model/GMMethod.java create mode 100644 engine/src/main/java/market/guess/engine/model/GMOptions.java create mode 100644 engine/src/main/java/market/guess/engine/model/GuessMarket.java create mode 100644 engine/src/main/java/market/guess/engine/model/ObjectFactory.java delete mode 100644 engine/src/main/java/market/guess/engine/provider/GuessMarketContext.java create mode 100644 engine/src/main/java/market/guess/engine/provider/LocalGuessMarketContext.java (limited to 'engine/src/main/java/market/guess') diff --git a/engine/src/main/java/market/guess/engine/GuessMarketEngine.java b/engine/src/main/java/market/guess/engine/GuessMarketEngine.java deleted file mode 100644 index aab3cf4..0000000 --- a/engine/src/main/java/market/guess/engine/GuessMarketEngine.java +++ /dev/null @@ -1,7 +0,0 @@ -package market.guess.engine; - -import market.guess.api.LoadResultDTO; - -public interface GuessMarketEngine { - LoadResultDTO loadEvents(); -} diff --git a/engine/src/main/java/market/guess/engine/LocalGuessMarketService.java b/engine/src/main/java/market/guess/engine/LocalGuessMarketService.java index 5a16750..dafbef6 100644 --- a/engine/src/main/java/market/guess/engine/LocalGuessMarketService.java +++ b/engine/src/main/java/market/guess/engine/LocalGuessMarketService.java @@ -1,7 +1,9 @@ package market.guess.engine; +import java.util.concurrent.CompletableFuture; +import market.guess.api.GuessMarketContext; +import market.guess.api.GuessMarketEngine; import market.guess.api.LoadResultDTO; -import market.guess.engine.provider.GuessMarketContext; public class LocalGuessMarketService implements GuessMarketEngine { private final GuessMarketContext context; @@ -12,7 +14,7 @@ public class LocalGuessMarketService implements GuessMarketEngine { } @Override - public LoadResultDTO loadEvents() { + public CompletableFuture loadEvents() { return context.LoadAsync(); } } diff --git a/engine/src/main/java/market/guess/engine/mechanism/LmsrTradingMechanism.java b/engine/src/main/java/market/guess/engine/mechanism/LmsrTradingMechanism.java index 99a26ab..50a6fd1 100644 --- a/engine/src/main/java/market/guess/engine/mechanism/LmsrTradingMechanism.java +++ b/engine/src/main/java/market/guess/engine/mechanism/LmsrTradingMechanism.java @@ -34,4 +34,9 @@ public class LmsrTradingMechanism implements TradingMechanism { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'settle'"); } + + private BigDecimal getCost(int yayBuys, int nayBuys) { + return BigDecimal.valueOf( + 10.0 * Math.log(Math.pow(Math.E, yayBuys / 10.0) + Math.pow(Math.E, nayBuys / 10.0))); + } } diff --git a/engine/src/main/java/market/guess/engine/model/Comision.java b/engine/src/main/java/market/guess/engine/model/Comision.java new file mode 100644 index 0000000..05b4b7b --- /dev/null +++ b/engine/src/main/java/market/guess/engine/model/Comision.java @@ -0,0 +1,94 @@ +// +// This file was generated by the Eclipse Implementation of JAXB, v4.0.5 +// See https://eclipse-ee4j.github.io/jaxb-ri +// Any modifications to this file will be lost upon recompilation of the source schema. +// + + +package market.guess.engine.model; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlAttribute; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.XmlValue; + + +/** + *

Java class for anonymous complex type

. + * + *

The following schema fragment specifies the expected content contained within this class.

+ * + *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *           
+ *             
+ *             
+ *           
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "value" +}) +@XmlRootElement(name = "comision") +public class Comision { + + @XmlValue + protected int value; + @XmlAttribute(name = "type", required = true) + protected String type; + + /** + * Gets the value of the value property. + * + */ + public int getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + */ + public void setValue(int value) { + this.value = value; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + +} diff --git a/engine/src/main/java/market/guess/engine/model/GMEvent.java b/engine/src/main/java/market/guess/engine/model/GMEvent.java new file mode 100644 index 0000000..9f109d6 --- /dev/null +++ b/engine/src/main/java/market/guess/engine/model/GMEvent.java @@ -0,0 +1,215 @@ +// +// This file was generated by the Eclipse Implementation of JAXB, v4.0.5 +// See https://eclipse-ee4j.github.io/jaxb-ri +// Any modifications to this file will be lost upon recompilation of the source schema. +// + + +package market.guess.engine.model; + +import java.util.ArrayList; +import java.util.List; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlAttribute; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type

. + * + *

The following schema fragment specifies the expected content contained within this class.

+ * + *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *         
+ *         
+ *         
+ *         
+ *       
+ *       
+ *         
+ *           
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "id", + "description", + "comision", + "gmOptions", + "gmMethod" +}) +@XmlRootElement(name = "GM-event") +public class GMEvent { + + protected int id; + @XmlElement(required = true) + protected String description; + @XmlElement(required = true) + protected Comision comision; + @XmlElement(name = "GM-options", required = true) + protected GMOptions gmOptions; + @XmlElement(name = "GM-method", required = true) + protected GMMethod gmMethod; + @XmlAttribute(name = "name", required = true) + protected List name; + + /** + * Gets the value of the id property. + * + */ + public int getId() { + return id; + } + + /** + * Sets the value of the id property. + * + */ + public void setId(int value) { + this.id = value; + } + + /** + * Gets the value of the description property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDescription() { + return description; + } + + /** + * Sets the value of the description property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDescription(String value) { + this.description = value; + } + + /** + * Gets the value of the comision property. + * + * @return + * possible object is + * {@link Comision } + * + */ + public Comision getComision() { + return comision; + } + + /** + * Sets the value of the comision property. + * + * @param value + * allowed object is + * {@link Comision } + * + */ + public void setComision(Comision value) { + this.comision = value; + } + + /** + * Gets the value of the gmOptions property. + * + * @return + * possible object is + * {@link GMOptions } + * + */ + public GMOptions getGMOptions() { + return gmOptions; + } + + /** + * Sets the value of the gmOptions property. + * + * @param value + * allowed object is + * {@link GMOptions } + * + */ + public void setGMOptions(GMOptions value) { + this.gmOptions = value; + } + + /** + * Gets the value of the gmMethod property. + * + * @return + * possible object is + * {@link GMMethod } + * + */ + public GMMethod getGMMethod() { + return gmMethod; + } + + /** + * Sets the value of the gmMethod property. + * + * @param value + * allowed object is + * {@link GMMethod } + * + */ + public void setGMMethod(GMMethod value) { + this.gmMethod = value; + } + + /** + * Gets the value of the name property. + * + *

This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the name property.

+ * + *

+ * For example, to add a new item, do as follows: + *

+ *
+     * getName().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + *

+ * + * + * @return + * The value of the name property. + */ + public List getName() { + if (name == null) { + name = new ArrayList<>(); + } + return this.name; + } + +} diff --git a/engine/src/main/java/market/guess/engine/model/GMEvents.java b/engine/src/main/java/market/guess/engine/model/GMEvents.java new file mode 100644 index 0000000..b40ff0c --- /dev/null +++ b/engine/src/main/java/market/guess/engine/model/GMEvents.java @@ -0,0 +1,80 @@ +// +// This file was generated by the Eclipse Implementation of JAXB, v4.0.5 +// See https://eclipse-ee4j.github.io/jaxb-ri +// Any modifications to this file will be lost upon recompilation of the source schema. +// + + +package market.guess.engine.model; + +import java.util.ArrayList; +import java.util.List; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type

. + * + *

The following schema fragment specifies the expected content contained within this class.

+ * + *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "gmEvent" +}) +@XmlRootElement(name = "GM-events") +public class GMEvents { + + @XmlElement(name = "GM-event", required = true) + protected List gmEvent; + + /** + * Gets the value of the gmEvent property. + * + *

This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the gmEvent property.

+ * + *

+ * For example, to add a new item, do as follows: + *

+ *
+     * getGMEvent().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link GMEvent } + *

+ * + * + * @return + * The value of the gmEvent property. + */ + public List getGMEvent() { + if (gmEvent == null) { + gmEvent = new ArrayList<>(); + } + return this.gmEvent; + } + +} diff --git a/engine/src/main/java/market/guess/engine/model/GMLMSR.java b/engine/src/main/java/market/guess/engine/model/GMLMSR.java new file mode 100644 index 0000000..1f8eb45 --- /dev/null +++ b/engine/src/main/java/market/guess/engine/model/GMLMSR.java @@ -0,0 +1,60 @@ +// +// This file was generated by the Eclipse Implementation of JAXB, v4.0.5 +// See https://eclipse-ee4j.github.io/jaxb-ri +// Any modifications to this file will be lost upon recompilation of the source schema. +// + + +package market.guess.engine.model; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type

. + * + *

The following schema fragment specifies the expected content contained within this class.

+ * + *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "b" +}) +@XmlRootElement(name = "GM-LMSR") +public class GMLMSR { + + protected int b; + + /** + * Gets the value of the b property. + * + */ + public int getB() { + return b; + } + + /** + * Sets the value of the b property. + * + */ + public void setB(int value) { + this.b = value; + } + +} diff --git a/engine/src/main/java/market/guess/engine/model/GMMethod.java b/engine/src/main/java/market/guess/engine/model/GMMethod.java new file mode 100644 index 0000000..4841af9 --- /dev/null +++ b/engine/src/main/java/market/guess/engine/model/GMMethod.java @@ -0,0 +1,70 @@ +// +// This file was generated by the Eclipse Implementation of JAXB, v4.0.5 +// See https://eclipse-ee4j.github.io/jaxb-ri +// Any modifications to this file will be lost upon recompilation of the source schema. +// + + +package market.guess.engine.model; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type

. + * + *

The following schema fragment specifies the expected content contained within this class.

+ * + *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "gmlmsr" +}) +@XmlRootElement(name = "GM-method") +public class GMMethod { + + @XmlElement(name = "GM-LMSR", required = true) + protected GMLMSR gmlmsr; + + /** + * Gets the value of the gmlmsr property. + * + * @return + * possible object is + * {@link GMLMSR } + * + */ + public GMLMSR getGMLMSR() { + return gmlmsr; + } + + /** + * Sets the value of the gmlmsr property. + * + * @param value + * allowed object is + * {@link GMLMSR } + * + */ + public void setGMLMSR(GMLMSR value) { + this.gmlmsr = value; + } + +} diff --git a/engine/src/main/java/market/guess/engine/model/GMOptions.java b/engine/src/main/java/market/guess/engine/model/GMOptions.java new file mode 100644 index 0000000..666e57a --- /dev/null +++ b/engine/src/main/java/market/guess/engine/model/GMOptions.java @@ -0,0 +1,80 @@ +// +// This file was generated by the Eclipse Implementation of JAXB, v4.0.5 +// See https://eclipse-ee4j.github.io/jaxb-ri +// Any modifications to this file will be lost upon recompilation of the source schema. +// + + +package market.guess.engine.model; + +import java.util.ArrayList; +import java.util.List; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type

. + * + *

The following schema fragment specifies the expected content contained within this class.

+ * + *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "gmOption" +}) +@XmlRootElement(name = "GM-options") +public class GMOptions { + + @XmlElement(name = "GM-option", required = true) + protected List gmOption; + + /** + * Gets the value of the gmOption property. + * + *

This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the gmOption property.

+ * + *

+ * For example, to add a new item, do as follows: + *

+ *
+     * getGMOption().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + *

+ * + * + * @return + * The value of the gmOption property. + */ + public List getGMOption() { + if (gmOption == null) { + gmOption = new ArrayList<>(); + } + return this.gmOption; + } + +} diff --git a/engine/src/main/java/market/guess/engine/model/GuessMarket.java b/engine/src/main/java/market/guess/engine/model/GuessMarket.java new file mode 100644 index 0000000..983b306 --- /dev/null +++ b/engine/src/main/java/market/guess/engine/model/GuessMarket.java @@ -0,0 +1,70 @@ +// +// This file was generated by the Eclipse Implementation of JAXB, v4.0.5 +// See https://eclipse-ee4j.github.io/jaxb-ri +// Any modifications to this file will be lost upon recompilation of the source schema. +// + + +package market.guess.engine.model; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type

. + * + *

The following schema fragment specifies the expected content contained within this class.

+ * + *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "gmEvents" +}) +@XmlRootElement(name = "Guess-Market") +public class GuessMarket { + + @XmlElement(name = "GM-events", required = true) + protected GMEvents gmEvents; + + /** + * Gets the value of the gmEvents property. + * + * @return + * possible object is + * {@link GMEvents } + * + */ + public GMEvents getGMEvents() { + return gmEvents; + } + + /** + * Sets the value of the gmEvents property. + * + * @param value + * allowed object is + * {@link GMEvents } + * + */ + public void setGMEvents(GMEvents value) { + this.gmEvents = value; + } + +} diff --git a/engine/src/main/java/market/guess/engine/model/ObjectFactory.java b/engine/src/main/java/market/guess/engine/model/ObjectFactory.java new file mode 100644 index 0000000..b2a403a --- /dev/null +++ b/engine/src/main/java/market/guess/engine/model/ObjectFactory.java @@ -0,0 +1,167 @@ +// +// This file was generated by the Eclipse Implementation of JAXB, v4.0.5 +// See https://eclipse-ee4j.github.io/jaxb-ri +// Any modifications to this file will be lost upon recompilation of the source schema. +// + + +package market.guess.engine.model; + +import javax.xml.namespace.QName; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.annotation.XmlElementDecl; +import jakarta.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the market.guess.engine.model package. + *

An ObjectFactory allows you to programmatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private static final QName _Id_QNAME = new QName("", "id"); + private static final QName _Description_QNAME = new QName("", "description"); + private static final QName _B_QNAME = new QName("", "b"); + private static final QName _GMOption_QNAME = new QName("", "GM-option"); + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: market.guess.engine.model + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Comision } + * + * @return + * the new instance of {@link Comision } + */ + public Comision createComision() { + return new Comision(); + } + + /** + * Create an instance of {@link GuessMarket } + * + * @return + * the new instance of {@link GuessMarket } + */ + public GuessMarket createGuessMarket() { + return new GuessMarket(); + } + + /** + * Create an instance of {@link GMEvents } + * + * @return + * the new instance of {@link GMEvents } + */ + public GMEvents createGMEvents() { + return new GMEvents(); + } + + /** + * Create an instance of {@link GMEvent } + * + * @return + * the new instance of {@link GMEvent } + */ + public GMEvent createGMEvent() { + return new GMEvent(); + } + + /** + * Create an instance of {@link GMOptions } + * + * @return + * the new instance of {@link GMOptions } + */ + public GMOptions createGMOptions() { + return new GMOptions(); + } + + /** + * Create an instance of {@link GMMethod } + * + * @return + * the new instance of {@link GMMethod } + */ + public GMMethod createGMMethod() { + return new GMMethod(); + } + + /** + * Create an instance of {@link GMLMSR } + * + * @return + * the new instance of {@link GMLMSR } + */ + public GMLMSR createGMLMSR() { + return new GMLMSR(); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Integer }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link Integer }{@code >} + */ + @XmlElementDecl(namespace = "", name = "id") + public JAXBElement createId(Integer value) { + return new JAXBElement<>(_Id_QNAME, Integer.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link String }{@code >} + */ + @XmlElementDecl(namespace = "", name = "description") + public JAXBElement createDescription(String value) { + return new JAXBElement<>(_Description_QNAME, String.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Integer }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link Integer }{@code >} + */ + @XmlElementDecl(namespace = "", name = "b") + public JAXBElement createB(Integer value) { + return new JAXBElement<>(_B_QNAME, Integer.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link String }{@code >} + */ + @XmlElementDecl(namespace = "", name = "GM-option") + public JAXBElement createGMOption(String value) { + return new JAXBElement<>(_GMOption_QNAME, String.class, null, value); + } + +} diff --git a/engine/src/main/java/market/guess/engine/provider/GuessMarketContext.java b/engine/src/main/java/market/guess/engine/provider/GuessMarketContext.java deleted file mode 100644 index 2306c93..0000000 --- a/engine/src/main/java/market/guess/engine/provider/GuessMarketContext.java +++ /dev/null @@ -1,17 +0,0 @@ -package market.guess.engine.provider; - -import market.guess.api.LoadResultDTO; - -public interface GuessMarketContext { - LoadResultDTO LoadAsync(); - - void SaveChangesAsync(); - - void GetAllEventsAsync(); - - void GetEventInfoByIdAsync(); - - void CreateEventAsync(); - - void UpdateEventAsync(); -} diff --git a/engine/src/main/java/market/guess/engine/provider/LocalGuessMarketContext.java b/engine/src/main/java/market/guess/engine/provider/LocalGuessMarketContext.java new file mode 100644 index 0000000..628038d --- /dev/null +++ b/engine/src/main/java/market/guess/engine/provider/LocalGuessMarketContext.java @@ -0,0 +1,81 @@ +package market.guess.engine.provider; + +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.Marshaller; +import java.io.File; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import market.guess.api.CommissionChargeType; +import market.guess.api.EventDTO; +import market.guess.api.EventStatus; +import market.guess.api.GuessMarketContext; +import market.guess.api.LoadResultDTO; +import market.guess.engine.model.GuessMarket; + +public class LocalGuessMarketContext implements GuessMarketContext { + private GuessMarket context; + + @Override + public CompletableFuture LoadAsync() { + try { + var file = new File("test-data/ex-1/multiple.xml"); + var ctx = JAXBContext.newInstance(GuessMarket.class); + var unmarshaller = ctx.createUnmarshaller(); + + context = (GuessMarket) unmarshaller.unmarshal(file); + + } catch (Exception e) { + e.printStackTrace(); + } + return CompletableFuture.completedFuture(new LoadResultDTO()); + } + + @Override + public void SaveChangesAsync() { + try { + + var ctx = JAXBContext.newInstance(GuessMarket.class); + var marshaller = ctx.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + + var file = new File("test-data/ex-1/output.xml"); + marshaller.marshal(context, file); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Override + public List GetAllEventsAsync() { + var events = context.getGMEvents(); + return events.getGMEvent().stream() + .map( + o -> + new EventDTO( + o.getId(), + String.join(" ", o.getName()), + o.getDescription(), + o.getComision().getValue(), + CommissionChargeType.ON_CLOSE, + EventStatus.ACTIVE)) + .toList(); + } + + @Override + public void GetEventInfoByIdAsync() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'GetEventInfoByIdAsync'"); + } + + @Override + public void CreateEventAsync() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'CreateEventAsync'"); + } + + @Override + public void UpdateEventAsync() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'UpdateEventAsync'"); + } +} -- cgit v1.2.3