From 254d57d834255856672addb20cc486fe35fff9ab Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Mon, 10 Dec 2018 11:28:30 +0100 Subject: [PATCH] Some code cleaning --- nbproject/project.properties | 2 +- .../gui/AssetEditor/AssetEditorPanel.java | 2 +- src/opensesim/gui/Globals.java | 63 +++++++------------ src/opensesim/sesim/Assets/DummyAsset.java | 2 +- src/opensesim/util/XClassLoader.java | 6 +- src/opensesim/world/AbstractTrader.java | 2 +- src/opensesim/world/GodWorld.java | 24 +++++-- src/opensesim/world/RealWorld.java | 5 ++ src/opensesim/world/World.java | 2 + 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index cbacd51..9e73e5d 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -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= diff --git a/src/opensesim/gui/AssetEditor/AssetEditorPanel.java b/src/opensesim/gui/AssetEditor/AssetEditorPanel.java index d52b187..6059952 100644 --- a/src/opensesim/gui/AssetEditor/AssetEditorPanel.java +++ b/src/opensesim/gui/AssetEditor/AssetEditorPanel.java @@ -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.", diff --git a/src/opensesim/gui/Globals.java b/src/opensesim/gui/Globals.java index ebd71d1..fe73e31 100644 --- a/src/opensesim/gui/Globals.java +++ b/src/opensesim/gui/Globals.java @@ -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> 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 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 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 lafc; lafc = (Class) 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> res; - - res = cl.getInstalledClasses(default_pathlist); - - for (Class 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 il = new SeSimClassLoader<>(Indicator.class); -// il.setDefaultPathList(default_pathlist); -// ArrayList> 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)); diff --git a/src/opensesim/sesim/Assets/DummyAsset.java b/src/opensesim/sesim/Assets/DummyAsset.java index 40c6b23..c2dfb9b 100644 --- a/src/opensesim/sesim/Assets/DummyAsset.java +++ b/src/opensesim/sesim/Assets/DummyAsset.java @@ -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); } diff --git a/src/opensesim/util/XClassLoader.java b/src/opensesim/util/XClassLoader.java index bb378eb..c81c22e 100644 --- a/src/opensesim/util/XClassLoader.java +++ b/src/opensesim/util/XClassLoader.java @@ -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; } diff --git a/src/opensesim/world/AbstractTrader.java b/src/opensesim/world/AbstractTrader.java index 6c9f4bd..89ea701 100644 --- a/src/opensesim/world/AbstractTrader.java +++ b/src/opensesim/world/AbstractTrader.java @@ -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 diff --git a/src/opensesim/world/GodWorld.java b/src/opensesim/world/GodWorld.java index f47491e..32738e3 100644 --- a/src/opensesim/world/GodWorld.java +++ b/src/opensesim/world/GodWorld.java @@ -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 asset_type) { Constructor 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 traders = new HashSet<>(); - HashSet traders; - - public Trader createTrader() { - + public Trader createTrader(JSONObject cfg) { + return null; } + @Override + public Collection getTradersCollection() { + return Collections.unmodifiableCollection(traders); + } + } diff --git a/src/opensesim/world/RealWorld.java b/src/opensesim/world/RealWorld.java index e0bba6c..d0166e0 100644 --- a/src/opensesim/world/RealWorld.java +++ b/src/opensesim/world/RealWorld.java @@ -53,4 +53,9 @@ public class RealWorld implements World{ return godworld.getExchangeCollection(); } + @Override + public Collection getTradersCollection() { + return godworld.getTradersCollection(); + } + } diff --git a/src/opensesim/world/World.java b/src/opensesim/world/World.java index 5664249..ad60c94 100644 --- a/src/opensesim/world/World.java +++ b/src/opensesim/world/World.java @@ -38,4 +38,6 @@ public interface World { public AbstractAsset getAssetBySymbol(String symbol); Collection getExchangeCollection(); + + Collection getTradersCollection(); }