Compare commits

..

7 Commits

Author SHA1 Message Date
8279033d74 Fixed name of StockAsset and inserted Sockasset to example 2020-10-23 10:02:30 +02:00
2e1a53789f Added some comments 2020-10-23 09:45:44 +02:00
b084e0a156 Asset folder is lower case 2020-10-23 09:15:42 +02:00
2241822b26 Loads Ivy 2020-10-23 09:15:14 +02:00
d63ee05b5d Added example.json to run with Cli 2020-07-25 03:08:08 +02:00
27c08eee39 Removed interfaces Asset. Refactoring 2020-07-25 01:12:53 +02:00
2443b984cf Added cli sub directory 2020-07-25 01:04:56 +02:00
15 changed files with 82 additions and 51 deletions

View File

@ -130,7 +130,7 @@
<delete file="${store.dir}/temp_final.jar"/> <delete file="${store.dir}/temp_final.jar"/>
</target> </target>
<property name="ivy.install.version" value="2.1.0-rc2" /> <property name="ivy.install.version" value="2.5.0" />
<condition property="ivy.home" value="${env.IVY_HOME}"> <condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME" /> <isset property="env.IVY_HOME" />
</condition> </condition>
@ -142,7 +142,7 @@
<mkdir dir="${ivy.jar.dir}"/> <mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from web site so that it can be used even without any special installation --> <!-- download Ivy from web site so that it can be used even without any special installation -->
<get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" <get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/> dest="${ivy.jar.file}" usetimestamp="true"/>
</target> </target>

View File

@ -1,4 +1,4 @@
#Sat, 25 Jul 2020 00:02:41 +0200 #Sat, 25 Jul 2020 03:07:19 +0200
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processors.list= annotation.processing.processors.list=

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 7u83 <7u83@mail.ru> * Copyright (c) 2020, tube
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -23,40 +23,32 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package opensesim.sesim.interfaces; package opensesim.cli;
import java.util.HashMap; import java.io.IOException;
import javax.swing.JPanel; import java.io.InputStream;
import opensesim.world.RealWorld; import java.util.Scanner;
import opensesim.util.idgenerator.IDGenerator; import opensesim.world.GodWorld;
import opensesim.util.idgenerator.Id; import opensesim.world.World;
/** /**
* *
* @author 7u83 <7u83@mail.ru> * @author tube
*/ */
public interface Asset extends Configurable { public class Main {
static HashMap<Id, Asset> assetsById = new HashMap<>(); public static void main(String[] args) throws IOException {
static HashMap<String, Asset> assetsBySymbol = new HashMap<>(); System.out.println("OpenSeSim Cli");
static IDGenerator assetIdGenerator = new IDGenerator();
public String getSymbol(); InputStream is;
is = Main.class.getResourceAsStream(
"/opensesim/resources/files/example.json"
);
public Id getID(); // We have to bootstrap with a god world because
// there whould be no way to to initialize the world
GodWorld godworld = new GodWorld(is);
public Id setID(Id id); System.out.println("finished");
}
public JPanel getEditGui();
/**
* Indicate if this asset can act as currency
*
* @return true if currency, false no.
*/
public boolean isCurrency();
public String getTypeName();
// public Asset(Id);
} }

View File

@ -0,0 +1,10 @@
{
"version": 0.2,
"assets": [
{
"type": "opensesim.sesim.assets.StockAsset",
"symbol": "MSFT",
"name": "Microsoft"
}
]
}

View File

@ -23,7 +23,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package opensesim.sesim.Assets; package opensesim.sesim.assets;
import opensesim.world.AbstractAsset; import opensesim.world.AbstractAsset;
import opensesim.world.GodWorld; import opensesim.world.GodWorld;

View File

@ -23,7 +23,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package opensesim.sesim.Assets; package opensesim.sesim.assets;
import opensesim.world.AbstractAsset; import opensesim.world.AbstractAsset;
import opensesim.world.GodWorld; import opensesim.world.GodWorld;

View File

@ -23,7 +23,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package opensesim.sesim.Assets; package opensesim.sesim.assets;
import opensesim.world.AbstractAsset; import opensesim.world.AbstractAsset;
import opensesim.world.GodWorld; import opensesim.world.GodWorld;

View File

@ -23,7 +23,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package opensesim.sesim.Assets; package opensesim.sesim.assets;
import javax.swing.JPanel; import javax.swing.JPanel;
import opensesim.world.AbstractAsset; import opensesim.world.AbstractAsset;

View File

@ -23,7 +23,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package opensesim.sesim.Assets; package opensesim.sesim.assets;
/** /**
* *

View File

@ -23,7 +23,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package opensesim.sesim.Assets; package opensesim.sesim.assets;
import opensesim.world.AbstractAsset; import opensesim.world.AbstractAsset;
import opensesim.world.GodWorld; import opensesim.world.GodWorld;
@ -34,9 +34,9 @@ import org.json.JSONObject;
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
*/ */
public class StockAssett extends AbstractAsset{ public class StockAsset extends AbstractAsset{
public StockAssett(GodWorld world, JSONObject cfg) { public StockAsset(GodWorld world, JSONObject cfg) {
super(world, cfg); super(world, cfg);
} }

View File

@ -23,7 +23,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package opensesim.sesim.Assets; package opensesim.sesim.assets;
import opensesim.world.AbstractAsset; import opensesim.world.AbstractAsset;
import opensesim.world.GodWorld; import opensesim.world.GodWorld;

View File

@ -25,6 +25,8 @@
*/ */
package opensesim.world; package opensesim.world;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Collection; import java.util.Collection;
@ -32,6 +34,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.Scanner;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -75,8 +78,12 @@ public class GodWorld implements GetJson, World {
public static final String ASSET_SYMBOL = "symbol"; public static final String ASSET_SYMBOL = "symbol";
public static final String ASSET_TYPE = "type"; public static final String ASSET_TYPE = "type";
public static final String VERSION = "version";
} }
public static double VERSION = 0.2;
/* HashSet<AbstractAsset> assetsById = new HashSet<>(); /* HashSet<AbstractAsset> assetsById = new HashSet<>();
HashMap<String, AbstractAsset> assetsBySymbol = new HashMap<>(); HashMap<String, AbstractAsset> assetsBySymbol = new HashMap<>();
*/ */
@ -91,9 +98,25 @@ public class GodWorld implements GetJson, World {
*/ */
public GodWorld(JSONObject cfg) { public GodWorld(JSONObject cfg) {
init(cfg, false); init(cfg, false);
} }
public GodWorld(InputStream is) throws IOException{
String s = new Scanner(is, "UTF-8").useDelimiter("\\A").next();
JSONObject cfg = new JSONObject(s);
Double version = cfg.getDouble(GodWorld.JKEYS.VERSION);
if (version != GodWorld.VERSION) {
throw new IOException("File has wrong version.");
}
init(cfg,false);
}
private void init(JSONObject cfg, boolean mt) {
// this.scheduler = new Scheduler();
// this.scheduler.start();
putJson(cfg);
}
public Scheduler getScheduler() { public Scheduler getScheduler() {
return scheduler; return scheduler;
} }
@ -106,11 +129,6 @@ public class GodWorld implements GetJson, World {
this(new JSONObject("{}")); this(new JSONObject("{}"));
} }
private void init(JSONObject cfg, boolean mt) {
this.scheduler = new Scheduler();
this.scheduler.start();
putJson(cfg);
}
private void putJson(JSONObject cfg) { private void putJson(JSONObject cfg) {
// Read assets // Read assets
@ -170,11 +188,19 @@ public class GodWorld implements GetJson, World {
return cfg; return cfg;
} }
/**
* Create an asset from a JSON object
*
* @param cfg the JSON object to create the asset from
* @return the created asset
* @throws SeSimException
*/
public AbstractAsset createAsset(JSONObject cfg) throws SeSimException { public AbstractAsset createAsset(JSONObject cfg) throws SeSimException {
AbstractAsset a; AbstractAsset a;
String class_name; String class_name;
Class<AbstractAsset> cls; Class<AbstractAsset> cls;
// get asset name
try { try {
class_name = cfg.getString(JKEYS.ASSET_TYPE); class_name = cfg.getString(JKEYS.ASSET_TYPE);
} catch (JSONException jex) { } catch (JSONException jex) {
@ -182,11 +208,14 @@ public class GodWorld implements GetJson, World {
return null; return null;
} }
// create class from name
try { try {
cls = (Class<AbstractAsset>) Class.forName(class_name); cls = (Class<AbstractAsset>) Class.forName(class_name);
a = cls.getConstructor(GodWorld.class, JSONObject.class).newInstance(this, cfg); a = cls.getConstructor(GodWorld.class, JSONObject.class).newInstance(this, cfg);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { } catch (ClassNotFoundException | NoSuchMethodException | SecurityException
Logger.getLogger(GodWorld.class.getName()).log(Level.SEVERE, null, ex); | InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException ex) {
Logger.getLogger(GodWorld.class.getName()).log(Level.SEVERE, class_name, ex);
return null; return null;
} }

View File

@ -26,8 +26,8 @@
package opensesim.world; package opensesim.world;
import java.util.Map; import java.util.Map;
import opensesim.sesim.Assets.CurrencyAsset; import opensesim.sesim.assets.CurrencyAsset;
import opensesim.sesim.Assets.DummyAsset; import opensesim.sesim.assets.DummyAsset;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;

View File

@ -26,7 +26,7 @@
package opensesim.world; package opensesim.world;
import java.util.Set; import java.util.Set;
import opensesim.sesim.Assets.CurrencyAsset; import opensesim.sesim.assets.CurrencyAsset;
import opensesim.util.scheduler.EventListener; import opensesim.util.scheduler.EventListener;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;