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.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -278,7 +278,7 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
public boolean save(GodWorld worldadm ){
|
||||
JSONObject jo = Json.get(this);
|
||||
|
||||
System.out.printf("ASSETGETTER: %s\n",jo.toString(5));
|
||||
|
||||
|
||||
if (jo.getString(GodWorld.JKEYS.ASSET_SYMBOL).length()==0){
|
||||
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.util.XClassLoader.ClassCache;
|
||||
import opensesim.world.GodWorld;
|
||||
import opensesim.world.Trader;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -213,10 +214,10 @@ public class Globals {
|
||||
static public ArrayList<Class<AbstractAsset>> getAvailableAssetsTypes(boolean sort) {
|
||||
|
||||
// if class_cache is not initialized return an empty list
|
||||
if (class_cache == null){
|
||||
if (class_cache == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
Collection<Class> asset_types_raw;
|
||||
asset_types_raw = class_cache.getClassCollection(AbstractAsset.class);
|
||||
|
||||
@ -251,9 +252,8 @@ public class Globals {
|
||||
return class_cache.getClassByName(name);
|
||||
}
|
||||
|
||||
static public void installLookAndFeels() {
|
||||
static private void installLookAndFeels() {
|
||||
Collection<Class> lafs;
|
||||
// lafs = opensesim.util.XClassLoader.getClassesList(urllist, LookAndFeel.class);
|
||||
lafs = class_cache.getClassCollection(LookAndFeel.class);
|
||||
if (lafs == null) {
|
||||
return;
|
||||
@ -267,69 +267,52 @@ public class Globals {
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
|
||||
for (Class<?> cls : lafs) {
|
||||
/* System.out.println("Class:");
|
||||
System.out.println(cls.getName());*/
|
||||
|
||||
Class<LookAndFeel> lafc;
|
||||
lafc = (Class<LookAndFeel>) cls;
|
||||
LookAndFeel laf;
|
||||
|
||||
try {
|
||||
laf = lafc.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | InternalError ex) {
|
||||
Logger.getLogger(SeSimApplication.class.getName()).log(Level.SEVERE, null, ex);
|
||||
laf = lafc.getConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
//Logger.getLogger(Globals.class.getName()).log(Level.SEVERE, null, ex);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* System.out.println("LAF:");
|
||||
System.out.println(laf.getName());*/
|
||||
UIManager.installLookAndFeel(laf.getName() + " - " + laf.getDescription(), lafc.getName());
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
prefs = Preferences.userNodeForPackage(c);
|
||||
|
||||
// world = new World();
|
||||
// initialize urllist used by class loader
|
||||
updateUrlList();
|
||||
|
||||
class_cache = new ClassCache(urllist, new Class[]{
|
||||
LookAndFeel.class,
|
||||
AbstractAsset.class
|
||||
AbstractAsset.class,
|
||||
Trader.class
|
||||
});
|
||||
|
||||
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");
|
||||
@ -409,7 +392,7 @@ public class Globals {
|
||||
|
||||
public static void saveFile(File f) throws FileNotFoundException {
|
||||
|
||||
/* JSONObject sobj = new JSONObject();
|
||||
/* JSONObject sobj = new JSONObject();
|
||||
|
||||
JSONArray traders = getTraders();
|
||||
JSONObject strategies = getStrategies();
|
||||
@ -417,9 +400,9 @@ public class Globals {
|
||||
sobj.put(PrefKeys.SESIMVERSION, SESIM_FILEVERSION);
|
||||
sobj.put(PrefKeys.STRATEGIES, strategies);
|
||||
sobj.put(PrefKeys.TRADERS, traders);
|
||||
*/
|
||||
*/
|
||||
JSONObject sobj = Globals.getWorld();
|
||||
|
||||
|
||||
PrintWriter out;
|
||||
out = new PrintWriter(f.getAbsolutePath());
|
||||
out.print(sobj.toString(4));
|
||||
|
@ -40,7 +40,7 @@ public class DummyAsset extends AbstractAsset {
|
||||
return "DummyAsset";
|
||||
}
|
||||
|
||||
DummyAsset(GodWorld gw, JSONObject cfg) {
|
||||
public DummyAsset(GodWorld gw, JSONObject cfg) {
|
||||
super(gw, cfg);
|
||||
}
|
||||
|
||||
|
@ -89,10 +89,8 @@ public class XClassLoader {
|
||||
Class cls;
|
||||
try {
|
||||
cls = cl.loadClass(class_name);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
} catch (ClassNotFoundException | NoClassDefFoundError ex) {
|
||||
// Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public abstract class AbstractTrader implements Trader {
|
||||
private String name;
|
||||
private String status;
|
||||
private World world;
|
||||
HashSet accounts;
|
||||
protected Account account;
|
||||
|
||||
/**
|
||||
* @return the world
|
||||
|
@ -116,8 +116,9 @@ public class GodWorld implements GetJson, World {
|
||||
}
|
||||
for (int i = 0; i < exs.length(); i++) {
|
||||
JSONObject o = exs.optJSONObject(i);
|
||||
if (o==null)
|
||||
if (o == null) {
|
||||
continue;
|
||||
}
|
||||
createExchange(o);
|
||||
}
|
||||
|
||||
@ -207,6 +208,7 @@ public class GodWorld implements GetJson, World {
|
||||
return Collections.unmodifiableCollection(assetPairs);
|
||||
}
|
||||
|
||||
|
||||
public void add(AssetPair pair) {
|
||||
assetPairs.add(pair);
|
||||
}
|
||||
@ -293,7 +295,7 @@ public class GodWorld implements GetJson, World {
|
||||
public static String getTypeName(Class<AbstractAsset> asset_type) {
|
||||
Constructor<AbstractAsset> c;
|
||||
try {
|
||||
c = asset_type.getConstructor(GodWorld.class,JSONObject.class);
|
||||
c = asset_type.getConstructor(GodWorld.class, JSONObject.class);
|
||||
AbstractAsset ait = c.newInstance(null, null);
|
||||
return ait.getTypeName();
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
@ -305,12 +307,22 @@ public class GodWorld implements GetJson, World {
|
||||
public World getWorld() {
|
||||
return new RealWorld(this);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Stuff belonging to traders
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
|
||||
private final HashSet<Trader> traders = new HashSet<>();
|
||||
|
||||
HashSet traders;
|
||||
|
||||
public Trader createTrader() {
|
||||
|
||||
public Trader createTrader(JSONObject cfg) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Trader> getTradersCollection() {
|
||||
return Collections.unmodifiableCollection(traders);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,4 +53,9 @@ public class RealWorld implements World{
|
||||
return godworld.getExchangeCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Trader> getTradersCollection() {
|
||||
return godworld.getTradersCollection();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,4 +38,6 @@ public interface World {
|
||||
public AbstractAsset getAssetBySymbol(String symbol);
|
||||
|
||||
Collection<Exchange> getExchangeCollection();
|
||||
|
||||
Collection<Trader> getTradersCollection();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user