started major refactoring
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.HashMap;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
|
||||
@@ -26,7 +25,7 @@ public class BlockFree extends Condition {
|
||||
|
||||
public Condition load(JSONObject json) {
|
||||
super.load(json);
|
||||
block(Block.get(json.getString(BLOCK)));
|
||||
block(Block.get(new Id(json.getString(BLOCK))));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -52,7 +51,7 @@ public class BlockFree extends Condition {
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
if (!params.containsKey(BLOCK)) return t("No block id passed to BlockFree.update()!");
|
||||
String bid = params.get(BLOCK);
|
||||
Id bid = new Id(params.get(BLOCK));
|
||||
Block block = Block.get(bid);
|
||||
if (block == null) return t("No block with id {} found!",bid);
|
||||
this.block = block;
|
||||
|
||||
@@ -17,7 +17,6 @@ import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Plan;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
import de.srsoftware.web4rail.actions.ConditionalAction;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Checkbox;
|
||||
@@ -30,16 +29,15 @@ public abstract class Condition extends BaseClass {
|
||||
public static final Logger LOG = LoggerFactory.getLogger(Condition.class);
|
||||
private static final String INVERTED = "inverted";
|
||||
private static final String PREFIX = Condition.class.getPackageName();
|
||||
private static HashMap<Integer, Condition> conditions = new HashMap<Integer, Condition>();
|
||||
private static HashMap<Id, Condition> conditions = new HashMap<Id, Condition>();
|
||||
public boolean inverted = false;
|
||||
protected int id;
|
||||
private Object parent;
|
||||
|
||||
public Condition() {
|
||||
this(Application.createId());
|
||||
this(new Id());
|
||||
}
|
||||
|
||||
public Condition(int id) {
|
||||
public Condition(Id id) {
|
||||
this.id = id;
|
||||
conditions.put(id, this);
|
||||
}
|
||||
@@ -48,7 +46,7 @@ public abstract class Condition extends BaseClass {
|
||||
String action = params.get(ACTION);
|
||||
if (action == null) return t("No action passed to Condition.action!");
|
||||
|
||||
Integer cid = (params.containsKey(ID)) ? Integer.parseInt(params.get(ID)) : null;
|
||||
Id cid = Id.from(params);
|
||||
|
||||
if (isSet(cid)) {
|
||||
Condition condition = conditions.get(cid);
|
||||
@@ -85,14 +83,14 @@ public abstract class Condition extends BaseClass {
|
||||
Condition condition = Condition.create(type);
|
||||
if (isNull(condition)) return t("Unknown type \"{}\" of condition!",type);
|
||||
String[] parts = context.split(":");
|
||||
String contextId = parts[1];
|
||||
Id contextId = new Id(parts[1]);
|
||||
String realm = parts[0];
|
||||
switch (realm) {
|
||||
case REALM_ROUTE:
|
||||
Route route = plan.route(Integer.parseInt(contextId));
|
||||
Route route = plan.route(contextId);
|
||||
if (isNull(route)) return t("Unknown route: {}",contextId);
|
||||
route.add(condition);
|
||||
return route.properties(new HashMap<String,String>(Map.of(REALM,REALM_ROUTE,ACTION,ACTION_PROPS,ID,contextId)));
|
||||
return route.properties(new HashMap<String,String>(Map.of(REALM,REALM_ROUTE,ACTION,ACTION_PROPS,ID,contextId.toString())));
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -124,10 +122,6 @@ public abstract class Condition extends BaseClass {
|
||||
}
|
||||
|
||||
public abstract boolean fulfilledBy(Context context);
|
||||
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject json = new JSONObject().put(TYPE, getClass().getSimpleName());
|
||||
@@ -146,7 +140,7 @@ public abstract class Condition extends BaseClass {
|
||||
String tx = args.length<1 ? toString()+NBSP : args[0];
|
||||
String type = args.length<2 ? "span" : args[1];
|
||||
String context = args.length<3 ? null : args[2];
|
||||
return link(type, Map.of(REALM,REALM_CONDITION,ID,id(),ACTION,ACTION_PROPS,CONTEXT,context), tx);
|
||||
return link(type, tx,Map.of(CONTEXT,context));
|
||||
}
|
||||
|
||||
private static List<Class<? extends Condition>> list() {
|
||||
|
||||
@@ -8,8 +8,9 @@ import org.json.JSONObject;
|
||||
import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Application;
|
||||
import de.srsoftware.web4rail.BaseClass.Context;
|
||||
import de.srsoftware.web4rail.BaseClass.Id;
|
||||
import de.srsoftware.web4rail.Constants;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
@@ -39,9 +40,9 @@ public class ConditionList extends Vector<Condition> implements Constants{
|
||||
}
|
||||
}
|
||||
|
||||
public void removeById(int cid) {
|
||||
public void removeById(Id cid) {
|
||||
for (Condition condition : this) {
|
||||
if (condition.id() == cid) {
|
||||
if (condition.id().equals(cid)) {
|
||||
remove(condition);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.stream.Collectors;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
|
||||
public class OrCondition extends Condition{
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package de.srsoftware.web4rail.conditions;
|
||||
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
|
||||
public class PushPullTrain extends Condition {
|
||||
|
||||
@Override
|
||||
public boolean fulfilledBy(Context context) {
|
||||
return context.train.pushPull != inverted;
|
||||
return context.train().pushPull != inverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.HashMap;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
@@ -17,7 +16,7 @@ public class TrainHasTag extends Condition {
|
||||
@Override
|
||||
public boolean fulfilledBy(Context context) {
|
||||
if (tag == null) return true;
|
||||
return context.train.tags().contains(tag) != inverted;
|
||||
return context.train().tags().contains(tag) != inverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
@@ -17,8 +16,8 @@ public class TrainLength extends Condition {
|
||||
|
||||
@Override
|
||||
public boolean fulfilledBy(Context context) {
|
||||
if (isNull(context.train)) return false;
|
||||
return (context.train.length() < maxLength) != inverted;
|
||||
if (isNull(context.train())) return false;
|
||||
return (context.train().length() < maxLength) != inverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.HashMap;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
@@ -16,17 +15,17 @@ public class TrainSelect extends Condition {
|
||||
|
||||
@Override
|
||||
public boolean fulfilledBy(Context context) {
|
||||
return (context.train == train) != inverted;
|
||||
return (context.train() == train) != inverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
return super.json().put(REALM_TRAIN, train.id);
|
||||
return super.json().put(REALM_TRAIN, train.id());
|
||||
}
|
||||
|
||||
public Condition load(JSONObject json) {
|
||||
super.load(json);
|
||||
train(Train.get(json.getInt(REALM_TRAIN)));
|
||||
train(Train.get(new Id(json.getString(REALM_TRAIN))));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -52,7 +51,7 @@ public class TrainSelect extends Condition {
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
if (!params.containsKey(TRAIN)) return t("No train id passed to TrainSelect.update()!");
|
||||
int tid = Integer.parseInt(params.get(TRAIN));
|
||||
Id tid = new Id(params.get(TRAIN));
|
||||
Train train = Train.get(tid);
|
||||
if (train == null) return t("No train with id {} found!",tid);
|
||||
this.train = train;
|
||||
|
||||
Reference in New Issue
Block a user