added AndCondition
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.2.55</version>
|
||||
<version>1.2.56</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -20,6 +20,7 @@ Address : Adresse
|
||||
Address\: : Adresse:
|
||||
Analyze : analysieren
|
||||
and : und
|
||||
AndCondition : Und-Bedingung
|
||||
Apply : Übernehmen
|
||||
Auto pilot : Autopilot
|
||||
AutopilotActive : Autopilot aktiv
|
||||
|
||||
@@ -10,7 +10,7 @@ public class BrakeStop extends Action {
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
if (isNull(context.route())) return false;
|
||||
if (isNull(context.route()) || isNull(context.route().train())) return false;
|
||||
context.route().brakeStop();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package de.srsoftware.web4rail.conditions;
|
||||
|
||||
public class AndCondition extends ConditionList{
|
||||
|
||||
@Override
|
||||
public boolean fulfilledBy(Context context) {
|
||||
for (Condition condition : this) {
|
||||
if (!condition.fulfilledBy(context)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String glue() {
|
||||
return t("and");
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,7 @@ public abstract class Condition extends BaseClass {
|
||||
|
||||
private static List<Class<? extends Condition>> list() {
|
||||
return List.of(
|
||||
AndCondition.class,
|
||||
AutopilotActive.class,
|
||||
BlockFree.class,
|
||||
CarInTrain.class,
|
||||
|
||||
@@ -148,7 +148,11 @@ public class ConditionList extends Condition implements Iterable<Condition>{
|
||||
if (conditions.isEmpty()) return "["+t("Click here to add conditions")+"]";
|
||||
StringBuffer sb = new StringBuffer(conditions.firstElement().toString());
|
||||
String glue = glue();
|
||||
for (int i=1; i<conditions.size(); i++) sb.append(" ").append(glue).append(" "+conditions.get(i));
|
||||
for (int i=1; i<conditions.size(); i++) {
|
||||
Condition condition = conditions.get(i);
|
||||
String cString = condition instanceof ConditionList ? " ("+condition+")" : " "+condition;
|
||||
sb.append(" ").append(glue).append(cString);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user