From 3f8931031b2d89d269987077fbc57ce17a5bd9d6 Mon Sep 17 00:00:00 2001 From: Becky Auger-Williams Date: Mon, 7 Sep 2026 11:57:55 +0100 Subject: [PATCH 1/3] Allow the concat formula function to handle VEnum types so it can extract the string and perform the concat. --- .../formula/string/StringConcatFunction.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/formula/src/main/java/org/csstudio/apputil/formula/string/StringConcatFunction.java b/core/formula/src/main/java/org/csstudio/apputil/formula/string/StringConcatFunction.java index 9b496c673d..11a4367994 100644 --- a/core/formula/src/main/java/org/csstudio/apputil/formula/string/StringConcatFunction.java +++ b/core/formula/src/main/java/org/csstudio/apputil/formula/string/StringConcatFunction.java @@ -3,12 +3,7 @@ import org.csstudio.apputil.formula.spi.FormulaFunction; import org.epics.util.array.ListNumber; -import org.epics.vtype.Alarm; -import org.epics.vtype.Time; -import org.epics.vtype.VNumberArray; -import org.epics.vtype.VString; -import org.epics.vtype.VStringArray; -import org.epics.vtype.VType; +import org.epics.vtype.*; import java.util.ArrayList; import java.util.Arrays; @@ -56,6 +51,9 @@ public VType compute(VType... args) throws Exception { } else if (isString(arg)) { stringBuilder.append(((VString)arg).getValue()); + } else if (isEnum(arg)) + { + stringBuilder.append(((VEnum)arg).getValue()); } }); return VString.of(stringBuilder.toString(), Alarm.none(), Time.now()); @@ -63,12 +61,12 @@ public VType compute(VType... args) throws Exception { /** * Returns true is the value is a StringArray or can be converted to a StringArray - * @param value + * @param value * @return boolean true if value can be used as a string array */ private boolean isStringArray(VType value) { - return value instanceof VStringArray + return value instanceof VStringArray || value instanceof VNumberArray; } @@ -93,4 +91,9 @@ private boolean isString(VType value) { return value instanceof VString; } + + private boolean isEnum(VType value) + { + return value instanceof VEnum; + } } From 0766d438b6ab18b04dfd905786b07c024bfb9e62 Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Tue, 22 Sep 2026 15:15:25 +0100 Subject: [PATCH 2/3] Add concat unit tests including using enum labels --- .../string/StringConcatFunctionTest.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 core/formula/src/test/java/org/csstudio/apputil/formula/string/StringConcatFunctionTest.java diff --git a/core/formula/src/test/java/org/csstudio/apputil/formula/string/StringConcatFunctionTest.java b/core/formula/src/test/java/org/csstudio/apputil/formula/string/StringConcatFunctionTest.java new file mode 100644 index 0000000000..6ce5231aed --- /dev/null +++ b/core/formula/src/test/java/org/csstudio/apputil/formula/string/StringConcatFunctionTest.java @@ -0,0 +1,70 @@ +package org.csstudio.apputil.formula.string; + +import org.epics.util.array.ArrayDouble; +import org.epics.vtype.*; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class StringConcatFunctionTest { + + @Test + public void concatStrings() throws Exception { + StringConcatFunction concatFunction = new StringConcatFunction(); + + VString a = VString.of("a", Alarm.none(), Time.now()); + VString b = VString.of("b", Alarm.none(), Time.now()); + VString c = VString.of("c", Alarm.none(), Time.now()); + + VString res = (VString) concatFunction.compute(a,b,c); + assertEquals(res.getValue(), "abc"); + } + + @Test + public void concatStringArray() throws Exception { + StringConcatFunction concatFunction = new StringConcatFunction(); + + VType array = VStringArray.of(Arrays.asList("a", "b", "c"), Alarm.none(), Time.now()); + + VString res = (VString) concatFunction.compute(array); + assertEquals(res.getValue(), "abc"); + } + + @Test + public void concatDoubleArray() throws Exception { + StringConcatFunction concatFunction = new StringConcatFunction(); + + VType array = VNumberArray.of(ArrayDouble.of(1.0, 2.0, 3.0), Alarm.none(), Time.now(), Display.none()); + + VString res = (VString) concatFunction.compute(array); + assertEquals(res.getValue(), "1.02.03.0"); + } + + @Test + public void concatInvalidVType() throws Exception { + StringConcatFunction concatFunction = new StringConcatFunction(); + + VType num1 = VNumber.of(1.0, Alarm.none(), Time.now(), Display.none()); + VType num2 = VNumber.of(2.0, Alarm.none(), Time.now(), Display.none()); + VType num3 = VNumber.of(3.0, Alarm.none(), Time.now(), Display.none()); + + VString res = (VString) concatFunction.compute(num1, num2, num3); + // Will not attempt to concat and will return empty string + assertEquals(res.getValue(), ""); + } + + @Test + public void concatEnums() throws Exception { + StringConcatFunction concatFunction = new StringConcatFunction(); + + VEnum enum1 = VEnum.of(0, EnumDisplay.of("a", "b", "c"), Alarm.none(), Time.now()); + VEnum enum2 = VEnum.of(1, EnumDisplay.of("a", "b", "c"), Alarm.none(), Time.now()); + VEnum enum3 = VEnum.of(2, EnumDisplay.of("a", "b", "c"), Alarm.none(), Time.now()); + + VString res = (VString) concatFunction.compute(enum1, enum2, enum3); + assertEquals(res.getValue(), "abc"); + } +} From 9840c3dd26a3f61e50af6fd9883d77252eade878 Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Tue, 22 Sep 2026 15:36:53 +0100 Subject: [PATCH 3/3] Fix SonarCloud issues --- .../string/StringConcatFunctionTest.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/core/formula/src/test/java/org/csstudio/apputil/formula/string/StringConcatFunctionTest.java b/core/formula/src/test/java/org/csstudio/apputil/formula/string/StringConcatFunctionTest.java index 6ce5231aed..1fce7e2dd2 100644 --- a/core/formula/src/test/java/org/csstudio/apputil/formula/string/StringConcatFunctionTest.java +++ b/core/formula/src/test/java/org/csstudio/apputil/formula/string/StringConcatFunctionTest.java @@ -4,15 +4,14 @@ import org.epics.vtype.*; import org.junit.jupiter.api.Test; -import java.util.ArrayList; import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertEquals; -public class StringConcatFunctionTest { +class StringConcatFunctionTest { @Test - public void concatStrings() throws Exception { + void concatStrings() throws Exception { StringConcatFunction concatFunction = new StringConcatFunction(); VString a = VString.of("a", Alarm.none(), Time.now()); @@ -20,31 +19,31 @@ public void concatStrings() throws Exception { VString c = VString.of("c", Alarm.none(), Time.now()); VString res = (VString) concatFunction.compute(a,b,c); - assertEquals(res.getValue(), "abc"); + assertEquals("abc", res.getValue()); } @Test - public void concatStringArray() throws Exception { + void concatStringArray() throws Exception { StringConcatFunction concatFunction = new StringConcatFunction(); VType array = VStringArray.of(Arrays.asList("a", "b", "c"), Alarm.none(), Time.now()); VString res = (VString) concatFunction.compute(array); - assertEquals(res.getValue(), "abc"); + assertEquals("abc", res.getValue()); } @Test - public void concatDoubleArray() throws Exception { + void concatDoubleArray() throws Exception { StringConcatFunction concatFunction = new StringConcatFunction(); VType array = VNumberArray.of(ArrayDouble.of(1.0, 2.0, 3.0), Alarm.none(), Time.now(), Display.none()); VString res = (VString) concatFunction.compute(array); - assertEquals(res.getValue(), "1.02.03.0"); + assertEquals("1.02.03.0", res.getValue()); } @Test - public void concatInvalidVType() throws Exception { + void concatInvalidVType() throws Exception { StringConcatFunction concatFunction = new StringConcatFunction(); VType num1 = VNumber.of(1.0, Alarm.none(), Time.now(), Display.none()); @@ -53,11 +52,11 @@ public void concatInvalidVType() throws Exception { VString res = (VString) concatFunction.compute(num1, num2, num3); // Will not attempt to concat and will return empty string - assertEquals(res.getValue(), ""); + assertEquals("", res.getValue()); } @Test - public void concatEnums() throws Exception { + void concatEnums() throws Exception { StringConcatFunction concatFunction = new StringConcatFunction(); VEnum enum1 = VEnum.of(0, EnumDisplay.of("a", "b", "c"), Alarm.none(), Time.now()); @@ -65,6 +64,6 @@ public void concatEnums() throws Exception { VEnum enum3 = VEnum.of(2, EnumDisplay.of("a", "b", "c"), Alarm.none(), Time.now()); VString res = (VString) concatFunction.compute(enum1, enum2, enum3); - assertEquals(res.getValue(), "abc"); + assertEquals("abc", res.getValue()); } }