still overhauling class hierarchy

This commit is contained in:
Stephan Richter
2020-12-02 00:14:46 +01:00
parent b7effda44f
commit c4f48ebb63
19 changed files with 111 additions and 96 deletions

View File

@@ -199,8 +199,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
}
@Override
protected Tile load(JSONObject json) throws IOException {
super.load(json);
public Tile load(JSONObject json) {
name = json.has(NAME) ? json.getString(NAME) : "Block";
turnAllowed = json.has(ALLOW_TURN) && json.getBoolean(ALLOW_TURN);
if (json.has(WAIT_TIMES)) {
@@ -210,7 +209,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
if (object instanceof JSONObject) waitTimes.add(new WaitTime(null).load((JSONObject) object));
});
}
return this;
return super.load(json);
}
@Override
@@ -345,7 +344,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
}
@Override
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
if (params.containsKey(NAME)) name=params.get(NAME);
if (params.containsKey(Train.class.getSimpleName())) {
Id trainId = Id.from(params,Train.class.getSimpleName());

View File

@@ -46,7 +46,7 @@ public abstract class Bridge extends Tile {
}
@Override
protected Tile load(JSONObject json) throws IOException {
public Tile load(JSONObject json) {
if (json.has(COUNTERPART)) {
new Thread() {
@Override

View File

@@ -117,11 +117,10 @@ public class Contact extends Tile{
@Override
protected Tile load(JSONObject json) throws IOException {
super.load(json);
public Tile load(JSONObject json) {
if (json.has(ADDRESS)) addr(json.getInt(ADDRESS));
if (json.has(REALM_ACTIONS)) actions = ActionList.load(json.getJSONArray(REALM_ACTIONS));
return this;
return super.load(json);
}
@Override
@@ -213,7 +212,7 @@ public class Contact extends Tile{
return true;
}
@Override
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
if (params.containsKey(ADDRESS)) addr(Integer.parseInt(params.get(ADDRESS)));
return super.update(params);
}

View File

@@ -109,7 +109,7 @@ public class Relay extends Tile implements Device{
}
@Override
protected Tile load(JSONObject json) throws IOException {
public Tile load(JSONObject json) {
if (json.has(ADDRESS)) address = json.getInt(ADDRESS);
if (json.has(PORT_A)) portA = json.getInt(PORT_A);
if (json.has(PORT_B)) portB = json.getInt(PORT_B);
@@ -227,7 +227,7 @@ public class Relay extends Tile implements Device{
}
@Override
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
if (params.containsKey(ADDRESS)) address = Integer.parseInt(params.get(ADDRESS));
if (params.containsKey(PORT_A)) portA = Integer.parseInt(params.get(PORT_A));

View File

@@ -1,6 +1,5 @@
package de.srsoftware.web4rail.tiles;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
@@ -30,10 +29,9 @@ public abstract class StretchableTile extends Tile {
}
@Override
protected Tile load(JSONObject json) throws IOException {
super.load(json);
public Tile load(JSONObject json) {
if (json.has(STRETCH_LENGTH)) stretch = json.getInt(STRETCH_LENGTH);
return this;
return super.load(json);
}
@Override
@@ -61,7 +59,7 @@ public abstract class StretchableTile extends Tile {
protected abstract String stretchType();
@Override
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
for (Entry<String, String> entry : params.entrySet()) {
switch (entry.getKey()) {
case STRETCH_LENGTH:

View File

@@ -25,10 +25,9 @@ public class TextDisplay extends StretchableTile {
}
@Override
protected Tile load(JSONObject json) throws IOException {
super.load(json);
public Tile load(JSONObject json) {
if (json.has(TEXT)) text = json.getString(TEXT);
return this;
return super.load(json);
}
@Override
@@ -73,7 +72,7 @@ public class TextDisplay extends StretchableTile {
}
@Override
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
for (Entry<String, String> entry : params.entrySet()) {
switch (entry.getKey()) {
case TEXT:

View File

@@ -169,7 +169,8 @@ public abstract class Tile extends BaseClass{
}
}
protected Tile load(JSONObject json) throws IOException {
public Tile load(JSONObject json) {
super.load(json);
JSONObject pos = json.getJSONObject(POS);
x = pos.getInt(X);
y = pos.getInt(Y);
@@ -394,7 +395,7 @@ public abstract class Tile extends BaseClass{
plan.place(this);
}
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
String oneWayDir = params.get("oneway");
if (isSet(oneWayDir)) {
@@ -407,7 +408,7 @@ public abstract class Tile extends BaseClass{
disabled = "on".equals(params.get(DISABLED));
String len = params.get(LENGTH);
if (isSet(len)) length(Integer.parseInt(len));
plan.stream(tag(null).toString());
plan.place(this);
return this;
}

View File

@@ -103,7 +103,7 @@ public abstract class Turnout extends Tile implements Device{
}
@Override
protected Tile load(JSONObject json) throws IOException {
public Tile load(JSONObject json) {
if (json.has(ADDRESS)) address = json.getInt(ADDRESS);
if (json.has(PORT_A)) portA = json.getInt(PORT_A);
if (json.has(PORT_B)) portB = json.getInt(PORT_B);
@@ -201,7 +201,7 @@ public abstract class Turnout extends Tile implements Device{
}
@Override
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
if (params.containsKey(ADDRESS)) {
int newAddress = Integer.parseInt(params.get(ADDRESS));

View File

@@ -50,7 +50,7 @@ public class TurnoutL extends Turnout {
}
@Override
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
if (params.containsKey(STRAIGHT)) portA = Integer.parseInt(params.get(STRAIGHT));
if (params.containsKey(LEFT)) portB = Integer.parseInt(params.get(LEFT));
return super.update(params);

View File

@@ -51,7 +51,7 @@ public class TurnoutR extends Turnout {
}
@Override
public Tile update(HashMap<String, String> params) throws IOException {
public Tile update(HashMap<String, String> params) {
if (params.containsKey(STRAIGHT)) portA = Integer.parseInt(params.get(STRAIGHT));
if (params.containsKey(RIGHT)) portB = Integer.parseInt(params.get(RIGHT));
return super.update(params);