Added GetJson interface

This commit is contained in:
7u83 2018-12-05 18:28:40 +01:00
parent 84c6718c8e
commit ee5527a3de
3 changed files with 49 additions and 12 deletions

View File

@ -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=

View File

@ -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();
}

View File

@ -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);