bugfix: conditions not respecting inversion
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>0.9.10</version>
|
<version>0.9.11</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class ConditionalAction extends Action {
|
|||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) throws IOException {
|
||||||
for (Condition condition : conditions) {
|
for (Condition condition : conditions) {
|
||||||
if (condition.fulfilledBy(context) != condition.inverted) return actions.fire(context);
|
if (condition.fulfilledBy(context)) return actions.fire(context);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ public abstract class Condition implements Constants {
|
|||||||
private static final String INVERTED = "inverted";
|
private static final String INVERTED = "inverted";
|
||||||
private static final String PREFIX = Condition.class.getPackageName();
|
private static final String PREFIX = Condition.class.getPackageName();
|
||||||
private static HashMap<Integer, Condition> conditions = new HashMap<Integer, Condition>();
|
private static HashMap<Integer, Condition> conditions = new HashMap<Integer, Condition>();
|
||||||
public abstract boolean fulfilledBy(Context context);
|
|
||||||
public boolean inverted = false;
|
public boolean inverted = false;
|
||||||
protected int id;
|
protected int id;
|
||||||
|
|
||||||
@@ -70,6 +69,8 @@ public abstract class Condition implements Constants {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract boolean fulfilledBy(Context context);
|
||||||
|
|
||||||
public int id() {
|
public int id() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class TrainHasTag extends Condition {
|
|||||||
@Override
|
@Override
|
||||||
public boolean fulfilledBy(Context context) {
|
public boolean fulfilledBy(Context context) {
|
||||||
if (tag == null) return true;
|
if (tag == null) return true;
|
||||||
return context.train.tags().contains(tag);
|
return context.train.tags().contains(tag) != inverted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class TrainLength extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fulfilledBy(Context context) {
|
public boolean fulfilledBy(Context context) {
|
||||||
return context.train.length() < maxLength;
|
return (context.train.length() < maxLength) != inverted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class TrainSelect extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fulfilledBy(Context context) {
|
public boolean fulfilledBy(Context context) {
|
||||||
return context.train == train;
|
return (context.train == train) != inverted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import de.srsoftware.web4rail.tags.Select;
|
|||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
import de.srsoftware.web4rail.tiles.Signal;
|
import de.srsoftware.web4rail.tiles.Signal;
|
||||||
|
|
||||||
public class Train implements Comparable,Constants {
|
public class Train implements Comparable<Train>,Constants {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Train.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Train.class);
|
||||||
|
|
||||||
private static final HashMap<Integer, Train> trains = new HashMap<>();
|
private static final HashMap<Integer, Train> trains = new HashMap<>();
|
||||||
@@ -516,7 +516,7 @@ public class Train implements Comparable,Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Train o) {
|
||||||
return name().compareTo(o.toString());
|
return name().compareTo(o.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user