Skip to content

Commit d42d090

Browse files
committed
[phoebus] add 'in' operator for scan server scripts
1 parent bc47f7f commit d42d090

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

app/scan/model/src/main/java/org/csstudio/scan/command/Comparison.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public enum Comparison
4343
INCREASE_BY("to increase by"),
4444

4545
/** Value has decreased by some amount */
46-
DECREASE_BY("to decrease by");
46+
DECREASE_BY("to decrease by"),
47+
48+
/** (Discrete) value has to be included in some list (only for TextValueConditions) */
49+
IN("in"),
50+
51+
/** (Discrete) value has to NOT be included in some list (only for TextValueConditions) */
52+
NOT_IN("not in");
4753

4854
final private String label;
4955

services/scan-server/src/main/java/org/csstudio/scan/server/condition/TextValueCondition.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.csstudio.scan.server.condition;
1717

1818
import java.time.Duration;
19+
import java.util.Arrays;
1920
import java.util.concurrent.TimeoutException;
2021

2122
import org.csstudio.scan.command.Comparison;
@@ -119,6 +120,12 @@ public void await() throws TimeoutException, Exception
119120
}
120121
}
121122

123+
private boolean containsValue(String value) {
124+
return Arrays.stream(desired_value.split(",")).anyMatch(
125+
v -> v.strip().equals(value.strip()) // strip input value just to be sure
126+
);
127+
}
128+
122129
/** Determine if the condition is currently met
123130
* @return <code>true</code> if condition is met
124131
* @throws Exception on error reading from the device
@@ -140,6 +147,10 @@ public boolean isConditionMet() throws Exception
140147
return value.compareTo(desired_value) <= 0;
141148
case BELOW:
142149
return value.compareTo(desired_value) < 0;
150+
case IN:
151+
return containsValue(value);
152+
case NOT_IN:
153+
return !containsValue(value);
143154
default:
144155
throw new Error("Condition not implemented for strings: " + comparison);
145156
}

0 commit comments

Comments
 (0)