improved code related to tag condition

This commit is contained in:
Stephan Richter
2020-11-01 18:58:00 +01:00
parent 0decce654d
commit efe93ff448
9 changed files with 28 additions and 24 deletions

View File

@@ -80,11 +80,9 @@ public abstract class Condition implements Constants {
return json;
}
public static Condition load(JSONObject json) {
String type = json.getString(TYPE);
Condition condition = Condition.create(type);
if (condition != null) condition.inverted = json.has(INVERTED) && json.getBoolean(INVERTED);
return condition;
public Condition load(JSONObject json) {
inverted = json.has(INVERTED) && json.getBoolean(INVERTED);
return this;
}
public Tag link(String tagClass,String context) {

View File

@@ -25,10 +25,10 @@ public class TrainHasTag extends Condition {
return super.json().put(TAG, tag);
}
public static TrainHasTag load(JSONObject json) {
TrainHasTag tl = new TrainHasTag();
if (json.has(TAG)) tl.tag = json.getString(TAG);
return tl;
public Condition load(JSONObject json) {
super.load(json);
if (json.has(TAG)) tag = json.getString(TAG);
return this;
}
@Override

View File

@@ -25,10 +25,10 @@ public class TrainLength extends Condition {
return super.json().put(MAX_LENGTH, maxLength);
}
public static TrainLength load(JSONObject json) {
TrainLength tl = new TrainLength();
if (json.has(MAX_LENGTH)) tl.maxLength = json.getInt(MAX_LENGTH);
return tl;
public Condition load(JSONObject json) {
super.load(json);
if (json.has(MAX_LENGTH)) maxLength = json.getInt(MAX_LENGTH);
return this;
}
@Override

View File

@@ -24,9 +24,10 @@ public class TrainSelect extends Condition {
return super.json().put(REALM_TRAIN, train.id);
}
public static TrainSelect load(JSONObject json) {
int trainId = json.getInt(REALM_TRAIN);
return new TrainSelect().train(Train.get(trainId));
public Condition load(JSONObject json) {
super.load(json);
train(Train.get(json.getInt(REALM_TRAIN)));
return this;
}
@Override