From d4523244de63f90fbd9f551699bb401d4e4843bc Mon Sep 17 00:00:00 2001 From: Lars Johansson <lars.johansson@ess.eu> Date: Tue, 18 Apr 2023 13:49:37 +0200 Subject: [PATCH] Correct extraction of mnemonic paths and improve performance Correct extraction of system structure and device structure mnemonic paths to handle content according to current and old naming convention. Improve performance of extraction of mnemonic paths. --- .../names/util/NamingConventionUtil.java | 111 +++++++++--------- .../names/util/NamingConventionUtilTest.java | 14 ++- 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/src/main/java/org/openepics/names/util/NamingConventionUtil.java b/src/main/java/org/openepics/names/util/NamingConventionUtil.java index 37768a29..70fb9999 100644 --- a/src/main/java/org/openepics/names/util/NamingConventionUtil.java +++ b/src/main/java/org/openepics/names/util/NamingConventionUtil.java @@ -42,15 +42,19 @@ public class NamingConventionUtil { // Note // - // ================================================================================ - // This class handles system structure and device structure of name convention - // ================================================================================ + // ==================================================================================================== + // This class handles system structure and device structure of naming convention + // ==================================================================================================== // ESS Naming Convention - // system structure:device structure:process variable + // name = system structure + // = system structure:device structure-instance index // ------------------------------------------------------------ // system structure need to be part of name // device structure need not to be part of name - // process variable not to be part of name + // instance index need not to be part of name + // ------------------------------------------------------------ + // process variable not to be part of name (!) + // pv name = name:process variable // ------------------------------------------------------------ // system structure // system group @@ -58,35 +62,39 @@ public class NamingConventionUtil { // subsystem // device structure // discipline + // ( device group ) // device type - // instance index (name) + // instance index + // ------------------------------------------------------------ + // system group optional + // device group not part of name + // instance index optional + // ==================================================================================================== + // Kind of names handled - naming convention // ------------------------------------------------------------ - // system group is optional - // instance index is optional - // ================================================================================ - // Kind of names handled - // CONVENTIONNAME_010 - // CONVENTIONNAME_011 - // CONVENTIONNAME_010_111 - // CONVENTIONNAME_011_110 - // CONVENTIONNAME_011_111 - // CONVENTIONNAME_111_110 - // CONVENTIONNAME_111_111 + // (1) able to handle + // ------------------------------------------------------------ + // systemGroup + // system + // system-subsystem + // systemGroup:discipline-deviceType-instanceIndex + // system:discipline-deviceType-instanceIndex + // system-subsystem:discipline-deviceType-instanceIndex // ------------------------------------------------------------ - // system - // system-subsystem - // system:discipline-deviceType-instanceIndex - // system-subsystem:discipline-deviceType - // system-subsystem:discipline-deviceType-instanceIndex - // systemGroup-system-subsystem:discipline-deviceType - // systemGroup-system-subsystem:discipline-deviceType-instanceIndex - // ================================================================================ + // (2) able to handle - old naming / naming convention - may exist + // ------------------------------------------------------------ + // system-subsystem:discipline-deviceType + // systemGroup-system-subsystem:discipline-deviceType + // systemGroup-system-subsystem:discipline-deviceType-instanceIndex + // ==================================================================================================== // delimiters // : // - - // ================================================================================ + // ------------------------------------------------------------ + // 1 occurrence of : expected, if 2 then pv name and erroneous from this perspective + // ==================================================================================================== // This class to be able to handle past and present names - // ================================================================================ + // ==================================================================================================== // p&id - pipeline & instrumentation diagram public static final String DISCIPLINE_P_ID = "P&ID"; @@ -277,26 +285,17 @@ public class NamingConventionUtil { * @return mnemonic path for system structure */ public static String extractMnemonicPathSystemStructure(String conventionName) { + // see documentation at top of class to learn about kind of names + // (according to current and old naming convention) + // that are to be handled + // + // performance is important! + if (!StringUtils.isEmpty(conventionName)) { int index = conventionName.indexOf(DELIMITER_EXTRA); - String mnemonicPath = null; - if (index != -1) { - mnemonicPath = conventionName.substring(0, index); - } else { - mnemonicPath = conventionName; - } - - // 0 or 1 DELIMITER_INTRA expected - index = mnemonicPath.indexOf(DELIMITER_INTRA); - if (index != -1) { - if (mnemonicPath.indexOf(DELIMITER_INTRA, index + 1) != -1) { - return null; - } else { - return mnemonicPath; - } - } else { - return mnemonicPath; - } + return index != -1 + ? conventionName.substring(0, index) + : conventionName; } return null; } @@ -309,18 +308,24 @@ public class NamingConventionUtil { * @return mnemonic path for device structure */ public static String extractMnemonicPathDeviceStructure(String conventionName) { + // see documentation at top of class to learn about kind of names + // (according to current and old naming convention) + // that are to be handled + // + // performance is important! + if (!StringUtils.isEmpty(conventionName)) { int index = conventionName.indexOf(DELIMITER_EXTRA); if (index != -1) { - String discipline = extractDiscipline(conventionName); - String deviceType = extractDeviceType(conventionName); - if (!StringUtils.isEmpty(discipline) && !StringUtils.isEmpty(deviceType)) { - return discipline + DELIMITER_INTRA + deviceType; - } else { - return null; + String mnemonicpath = conventionName.substring(index + 1); + + // discipline + device type + String[] deviceStructure = mnemonicpath.split(DELIMITER_INTRA); + if (deviceStructure.length == 3) { + return deviceStructure[0] + DELIMITER_INTRA + deviceStructure[1]; + } else if (deviceStructure.length == 2) { + return mnemonicpath; } - } else { - return null; } } return null; diff --git a/src/test/java/org/openepics/names/util/NamingConventionUtilTest.java b/src/test/java/org/openepics/names/util/NamingConventionUtilTest.java index 93c9d4ac..89019c87 100644 --- a/src/test/java/org/openepics/names/util/NamingConventionUtilTest.java +++ b/src/test/java/org/openepics/names/util/NamingConventionUtilTest.java @@ -223,25 +223,28 @@ class NamingConventionUtilTest { */ @Test void extractMnemonicPathSystemStructure() { + // may be put in loop for performance test + // loop size may be increased to 10000000 in order to view performance + assertEquals(NULL, NamingConventionUtil.extractMnemonicPathSystemStructure(NULL)); assertEquals(NULL, NamingConventionUtil.extractMnemonicPathSystemStructure(EMPTY)); assertEquals(DUMMY, NamingConventionUtil.extractMnemonicPathSystemStructure(DUMMY)); assertEquals(CONVENTIONNAME_010, NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_010)); assertEquals(CONVENTIONNAME_011, NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_011)); - assertEquals(NULL, NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_111)); + assertEquals(CONVENTIONNAME_111, NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_111)); assertEquals("CWL", NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_010_111)); assertEquals("LEBT-010", NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_011_110)); assertEquals("CWL-CWSE05", NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_011_111)); - assertEquals(NULL, NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_111_110)); - assertEquals(NULL, NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_111_111)); + assertEquals(CONVENTIONNAME_111, NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_111_110)); + assertEquals("DUMMY-CWL-CWSE05", NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_111_111)); assertEquals("CWL-CWSE05", NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_011_111_SC1)); assertEquals("CWL-CWSE05", NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_011_111_SC2)); assertEquals("CW1-CWSE5", NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_011_111_EQCLASS)); - assertEquals(NULL, NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_111_111_EQCLASS)); + assertEquals("DUMMY-CW1-CWSE5", NamingConventionUtil.extractMnemonicPathSystemStructure(CONVENTIONNAME_111_111_EQCLASS)); } /** @@ -249,6 +252,9 @@ class NamingConventionUtilTest { */ @Test void extractMnemonicPathDeviceStructure() { + // may be put in loop for performance test + // loop size may be increased to 1000000 in order to view performance + assertEquals(NULL, NamingConventionUtil.extractMnemonicPathDeviceStructure(NULL)); assertEquals(NULL, NamingConventionUtil.extractMnemonicPathDeviceStructure(EMPTY)); assertEquals(NULL, NamingConventionUtil.extractMnemonicPathDeviceStructure(DUMMY)); -- GitLab