Some code cleaning
This commit is contained in:
parent
f62a385eab
commit
254d57d834
@ -1,4 +1,4 @@
|
|||||||
#Sun, 09 Dec 2018 18:41:43 +0100
|
#Mon, 10 Dec 2018 11:28:07 +0100
|
||||||
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=
|
||||||
|
@ -278,7 +278,7 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
|||||||
public boolean save(GodWorld worldadm ){
|
public boolean save(GodWorld worldadm ){
|
||||||
JSONObject jo = Json.get(this);
|
JSONObject jo = Json.get(this);
|
||||||
|
|
||||||
System.out.printf("ASSETGETTER: %s\n",jo.toString(5));
|
|
||||||
|
|
||||||
if (jo.getString(GodWorld.JKEYS.ASSET_SYMBOL).length()==0){
|
if (jo.getString(GodWorld.JKEYS.ASSET_SYMBOL).length()==0){
|
||||||
javax.swing.JOptionPane.showMessageDialog(this, "Symbol must not be empty.",
|
javax.swing.JOptionPane.showMessageDialog(this, "Symbol must not be empty.",
|
||||||
|
@ -56,6 +56,7 @@ import opensesim.old_sesim.AutoTraderLoader;
|
|||||||
import opensesim.old_sesim.IndicatorLoader;
|
import opensesim.old_sesim.IndicatorLoader;
|
||||||
import opensesim.util.XClassLoader.ClassCache;
|
import opensesim.util.XClassLoader.ClassCache;
|
||||||
import opensesim.world.GodWorld;
|
import opensesim.world.GodWorld;
|
||||||
|
import opensesim.world.Trader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -213,10 +214,10 @@ public class Globals {
|
|||||||
static public ArrayList<Class<AbstractAsset>> getAvailableAssetsTypes(boolean sort) {
|
static public ArrayList<Class<AbstractAsset>> getAvailableAssetsTypes(boolean sort) {
|
||||||
|
|
||||||
// if class_cache is not initialized return an empty list
|
// if class_cache is not initialized return an empty list
|
||||||
if (class_cache == null){
|
if (class_cache == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<Class> asset_types_raw;
|
Collection<Class> asset_types_raw;
|
||||||
asset_types_raw = class_cache.getClassCollection(AbstractAsset.class);
|
asset_types_raw = class_cache.getClassCollection(AbstractAsset.class);
|
||||||
|
|
||||||
@ -251,9 +252,8 @@ public class Globals {
|
|||||||
return class_cache.getClassByName(name);
|
return class_cache.getClassByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void installLookAndFeels() {
|
static private void installLookAndFeels() {
|
||||||
Collection<Class> lafs;
|
Collection<Class> lafs;
|
||||||
// lafs = opensesim.util.XClassLoader.getClassesList(urllist, LookAndFeel.class);
|
|
||||||
lafs = class_cache.getClassCollection(LookAndFeel.class);
|
lafs = class_cache.getClassCollection(LookAndFeel.class);
|
||||||
if (lafs == null) {
|
if (lafs == null) {
|
||||||
return;
|
return;
|
||||||
@ -267,69 +267,52 @@ public class Globals {
|
|||||||
Thread.currentThread().setContextClassLoader(cl);
|
Thread.currentThread().setContextClassLoader(cl);
|
||||||
|
|
||||||
for (Class<?> cls : lafs) {
|
for (Class<?> cls : lafs) {
|
||||||
/* System.out.println("Class:");
|
|
||||||
System.out.println(cls.getName());*/
|
|
||||||
|
|
||||||
Class<LookAndFeel> lafc;
|
Class<LookAndFeel> lafc;
|
||||||
lafc = (Class<LookAndFeel>) cls;
|
lafc = (Class<LookAndFeel>) cls;
|
||||||
LookAndFeel laf;
|
LookAndFeel laf;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
laf = lafc.newInstance();
|
laf = lafc.getConstructor().newInstance();
|
||||||
} catch (InstantiationException | IllegalAccessException | InternalError ex) {
|
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||||
Logger.getLogger(SeSimApplication.class.getName()).log(Level.SEVERE, null, ex);
|
//Logger.getLogger(Globals.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* System.out.println("LAF:");
|
|
||||||
System.out.println(laf.getName());*/
|
|
||||||
UIManager.installLookAndFeel(laf.getName() + " - " + laf.getDescription(), lafc.getName());
|
UIManager.installLookAndFeel(laf.getName() + " - " + laf.getDescription(), lafc.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader(currentThreadClassLoader);
|
Thread.currentThread().setContextClassLoader(currentThreadClassLoader);
|
||||||
|
|
||||||
// UIManager.installLookAndFeel(laf.getName(), lafc.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ClassCache class_cache;
|
private static ClassCache class_cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize Globals object.
|
||||||
|
*
|
||||||
|
* This function initializes a Preferences object where preferences are
|
||||||
|
* stored. Furthermore a search trough all class paths is performed to find
|
||||||
|
* available LookAndFeels, Traders and Assets.
|
||||||
|
*
|
||||||
|
* @param c The class which uses this Globals object
|
||||||
|
*/
|
||||||
static void initGlobals(Class<?> c) {
|
static void initGlobals(Class<?> c) {
|
||||||
|
|
||||||
prefs = Preferences.userNodeForPackage(c);
|
prefs = Preferences.userNodeForPackage(c);
|
||||||
|
|
||||||
// world = new World();
|
|
||||||
// initialize urllist used by class loader
|
// initialize urllist used by class loader
|
||||||
updateUrlList();
|
updateUrlList();
|
||||||
|
|
||||||
class_cache = new ClassCache(urllist, new Class[]{
|
class_cache = new ClassCache(urllist, new Class[]{
|
||||||
LookAndFeel.class,
|
LookAndFeel.class,
|
||||||
AbstractAsset.class
|
AbstractAsset.class,
|
||||||
|
Trader.class
|
||||||
});
|
});
|
||||||
|
|
||||||
installLookAndFeels();
|
installLookAndFeels();
|
||||||
|
|
||||||
/*
|
|
||||||
ArrayList<Class<LookAndFeelInfo>> res;
|
|
||||||
|
|
||||||
res = cl.getInstalledClasses(default_pathlist);
|
|
||||||
|
|
||||||
for (Class<LookAndFeelInfo> laf : res) {
|
|
||||||
System.out.print(laf.getCanonicalName());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/* System.out.print("PATH LIST\n");
|
|
||||||
System.out.print(default_pathlist);
|
|
||||||
System.out.print("END PL\n");
|
|
||||||
*/
|
|
||||||
tloader = new AutoTraderLoader(default_pathlist);
|
|
||||||
|
|
||||||
iloader = new IndicatorLoader(default_pathlist);
|
|
||||||
|
|
||||||
iloader.getNames();
|
|
||||||
|
|
||||||
// SeSimClassLoader<Indicator> il = new SeSimClassLoader<>(Indicator.class);
|
|
||||||
// il.setDefaultPathList(default_pathlist);
|
|
||||||
// ArrayList<Class<Indicator>> ires = il.getInstalledClasses();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public final Logger LOGGER = Logger.getLogger("com.cauwersin.sesim");
|
static public final Logger LOGGER = Logger.getLogger("com.cauwersin.sesim");
|
||||||
@ -409,7 +392,7 @@ public class Globals {
|
|||||||
|
|
||||||
public static void saveFile(File f) throws FileNotFoundException {
|
public static void saveFile(File f) throws FileNotFoundException {
|
||||||
|
|
||||||
/* JSONObject sobj = new JSONObject();
|
/* JSONObject sobj = new JSONObject();
|
||||||
|
|
||||||
JSONArray traders = getTraders();
|
JSONArray traders = getTraders();
|
||||||
JSONObject strategies = getStrategies();
|
JSONObject strategies = getStrategies();
|
||||||
@ -417,9 +400,9 @@ public class Globals {
|
|||||||
sobj.put(PrefKeys.SESIMVERSION, SESIM_FILEVERSION);
|
sobj.put(PrefKeys.SESIMVERSION, SESIM_FILEVERSION);
|
||||||
sobj.put(PrefKeys.STRATEGIES, strategies);
|
sobj.put(PrefKeys.STRATEGIES, strategies);
|
||||||
sobj.put(PrefKeys.TRADERS, traders);
|
sobj.put(PrefKeys.TRADERS, traders);
|
||||||
*/
|
*/
|
||||||
JSONObject sobj = Globals.getWorld();
|
JSONObject sobj = Globals.getWorld();
|
||||||
|
|
||||||
PrintWriter out;
|
PrintWriter out;
|
||||||
out = new PrintWriter(f.getAbsolutePath());
|
out = new PrintWriter(f.getAbsolutePath());
|
||||||
out.print(sobj.toString(4));
|
out.print(sobj.toString(4));
|
||||||
|
@ -40,7 +40,7 @@ public class DummyAsset extends AbstractAsset {
|
|||||||
return "DummyAsset";
|
return "DummyAsset";
|
||||||
}
|
}
|
||||||
|
|
||||||
DummyAsset(GodWorld gw, JSONObject cfg) {
|
public DummyAsset(GodWorld gw, JSONObject cfg) {
|
||||||
super(gw, cfg);
|
super(gw, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,10 +89,8 @@ public class XClassLoader {
|
|||||||
Class cls;
|
Class cls;
|
||||||
try {
|
try {
|
||||||
cls = cl.loadClass(class_name);
|
cls = cl.loadClass(class_name);
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException | NoClassDefFoundError ex) {
|
||||||
Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex);
|
// Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
return null;
|
|
||||||
} catch (NoClassDefFoundError e) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public abstract class AbstractTrader implements Trader {
|
|||||||
private String name;
|
private String name;
|
||||||
private String status;
|
private String status;
|
||||||
private World world;
|
private World world;
|
||||||
HashSet accounts;
|
protected Account account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the world
|
* @return the world
|
||||||
|
@ -116,8 +116,9 @@ public class GodWorld implements GetJson, World {
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < exs.length(); i++) {
|
for (int i = 0; i < exs.length(); i++) {
|
||||||
JSONObject o = exs.optJSONObject(i);
|
JSONObject o = exs.optJSONObject(i);
|
||||||
if (o==null)
|
if (o == null) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
createExchange(o);
|
createExchange(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +208,7 @@ public class GodWorld implements GetJson, World {
|
|||||||
return Collections.unmodifiableCollection(assetPairs);
|
return Collections.unmodifiableCollection(assetPairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void add(AssetPair pair) {
|
public void add(AssetPair pair) {
|
||||||
assetPairs.add(pair);
|
assetPairs.add(pair);
|
||||||
}
|
}
|
||||||
@ -293,7 +295,7 @@ public class GodWorld implements GetJson, World {
|
|||||||
public static String getTypeName(Class<AbstractAsset> asset_type) {
|
public static String getTypeName(Class<AbstractAsset> asset_type) {
|
||||||
Constructor<AbstractAsset> c;
|
Constructor<AbstractAsset> c;
|
||||||
try {
|
try {
|
||||||
c = asset_type.getConstructor(GodWorld.class,JSONObject.class);
|
c = asset_type.getConstructor(GodWorld.class, JSONObject.class);
|
||||||
AbstractAsset ait = c.newInstance(null, null);
|
AbstractAsset ait = c.newInstance(null, null);
|
||||||
return ait.getTypeName();
|
return ait.getTypeName();
|
||||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||||
@ -305,12 +307,22 @@ public class GodWorld implements GetJson, World {
|
|||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return new RealWorld(this);
|
return new RealWorld(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
// Stuff belonging to traders
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
private final HashSet<Trader> traders = new HashSet<>();
|
||||||
|
|
||||||
HashSet traders;
|
public Trader createTrader(JSONObject cfg) {
|
||||||
|
|
||||||
public Trader createTrader() {
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Trader> getTradersCollection() {
|
||||||
|
return Collections.unmodifiableCollection(traders);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,4 +53,9 @@ public class RealWorld implements World{
|
|||||||
return godworld.getExchangeCollection();
|
return godworld.getExchangeCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Trader> getTradersCollection() {
|
||||||
|
return godworld.getTradersCollection();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,4 +38,6 @@ public interface World {
|
|||||||
public AbstractAsset getAssetBySymbol(String symbol);
|
public AbstractAsset getAssetBySymbol(String symbol);
|
||||||
|
|
||||||
Collection<Exchange> getExchangeCollection();
|
Collection<Exchange> getExchangeCollection();
|
||||||
|
|
||||||
|
Collection<Trader> getTradersCollection();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user