From ee5527a3deeba9a60611e63f87e891b41bfd4ced Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Wed, 5 Dec 2018 18:28:40 +0100 Subject: [PATCH] Added GetJson interface --- nbproject/project.properties | 2 +- src/opensesim/sesim/interfaces/GetJson.java | 36 +++++++++++++++++++++ src/opensesim/world/AbstractAsset.java | 23 ++++++------- 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 src/opensesim/sesim/interfaces/GetJson.java diff --git a/nbproject/project.properties b/nbproject/project.properties index ebf37d6..307bc4f 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Wed, 05 Dec 2018 17:57:49 +0100 +#Wed, 05 Dec 2018 18:03:39 +0100 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/opensesim/sesim/interfaces/GetJson.java b/src/opensesim/sesim/interfaces/GetJson.java new file mode 100644 index 0000000..1c717e2 --- /dev/null +++ b/src/opensesim/sesim/interfaces/GetJson.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, tohe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.interfaces; + +import org.json.JSONObject; + +/** + * + * @author tohe + */ +public interface GetJson { + JSONObject getJson(); +} diff --git a/src/opensesim/world/AbstractAsset.java b/src/opensesim/world/AbstractAsset.java index 96087c9..97e2250 100644 --- a/src/opensesim/world/AbstractAsset.java +++ b/src/opensesim/world/AbstractAsset.java @@ -31,6 +31,7 @@ import javax.swing.JPanel; import opensesim.gui.util.Json; import opensesim.gui.util.Json.Import; import opensesim.sesim.interfaces.Configurable; +import opensesim.sesim.interfaces.GetJson; import opensesim.util.idgenerator.Id; import org.json.JSONException; @@ -40,11 +41,10 @@ import org.json.JSONObject; * * @author 7u83 <7u83@mail.ru> */ -public abstract class AbstractAsset { +public abstract class AbstractAsset implements GetJson { World world; - private String symbol; private String name; private String description; @@ -52,21 +52,21 @@ public abstract class AbstractAsset { /** * Constructor + * * @param world * @param cfg */ public AbstractAsset(World world, JSONObject cfg) { - if (world == null) + if (world == null) { return; + } symbol = cfg.getString("symbol"); name = cfg.getString("name"); - decimals = cfg.optInt("decimals",0); - + decimals = cfg.optInt("decimals", 0); + this.world = world; } - - public abstract String getTypeName(); public int getDecimals() { @@ -160,19 +160,20 @@ public abstract class AbstractAsset { return null; } */ - public JSONObject getJson() { + @Override + public JSONObject getJson() { JSONObject cfg = new JSONObject(); cfg.put(World.JKEYS.ASSET_TYPE, this.getClass().getName()); - + cfg.put(AbstractAsset.JSON_SYMBOL, this.getSymbol()); cfg.put(AbstractAsset.JSON_DECIMALS, this.getDecimals()); cfg.put(AbstractAsset.JSON_NAME, this.getName()); cfg.put(AbstractAsset.JSON_DESCRIPTION, this.getDescription()); - + return cfg; } -/* + /* public void putConfig(JSONObject cfg) { symbol = cfg.optString(AbstractAsset.JSON_SYMBOL); decimals = cfg.optInt(AbstractAsset.JSON_DECIMALS, AbstractAsset.DECIMALS_DEFAULT);