diff --git a/core/src/main/java/tc/oc/pgm/map/ConditionalChecker.java b/core/src/main/java/tc/oc/pgm/map/ConditionalChecker.java index c5dc189894..5bee9ef873 100644 --- a/core/src/main/java/tc/oc/pgm/map/ConditionalChecker.java +++ b/core/src/main/java/tc/oc/pgm/map/ConditionalChecker.java @@ -24,7 +24,7 @@ class ConditionalChecker { * * @param ctx the map's context * @param el The conditional element - * @return true if the conditional + * @return if the conditional passes * @throws InvalidXMLException if the element is invalid in any way */ static boolean test(MapFilePreprocessor ctx, Element el) throws InvalidXMLException { @@ -63,31 +63,29 @@ private static boolean constant(MapFilePreprocessor ctx, Element el, String id) value == null ? Cmp.DEFINED : Cmp.EQUALS); var constants = ctx.getConstants(); + var isDefined = constants.containsKey(id); + var constant = isDefined ? constants.get(id) : null; if (!cmp.requireValue) { if (value != null) throw new InvalidXMLException("Comparison type " + cmp + " should not have a value", value); - if (!constants.containsKey(id)) return cmp == Cmp.UNDEFINED; - return switch (cmp) { - case DEFINED -> true; - case DEFINED_DELETE -> constants.get(id) == null; - case DEFINED_VALUE -> constants.get(id) != null; + case UNDEFINED -> !isDefined; + case DEFINED -> isDefined; + case DEFINED_DELETE -> isDefined && constant == null; + case DEFINED_VALUE -> isDefined && constant != null; // Should never happen default -> throw new IllegalStateException(cmp + " not supported"); }; } else { - String constant = constants.get(id); - if (constant == null) { - if (!constants.containsKey(id)) - throw new InvalidXMLException( - "Unknown constant '" + id + "'. Only constants before the conditional may be used.", - el); - return false; - } + if (!isDefined) + throw new InvalidXMLException( + "Unknown constant '" + id + "'. Only constants before the conditional may be used.", + el); if (value == null) throw new InvalidXMLException("Required attribute 'constant-value' not set", el); + if (constant == null) return false; return switch (cmp) { case EQUALS -> Objects.equals(value.getValue(), constant);