From c522e1e3df8e973d780c3296b5508c141f97d8c7 Mon Sep 17 00:00:00 2001 From: Lars Johansson <lars.johansson@ess.eu> Date: Wed, 30 Nov 2022 11:38:09 +0100 Subject: [PATCH] Refactor to use String.split instead of StringTokenizer --- .../names/util/NamingConventionUtil.java | 79 ++++++++----------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/openepics/names/util/NamingConventionUtil.java b/src/main/java/org/openepics/names/util/NamingConventionUtil.java index 51e5abfe..68603fa7 100644 --- a/src/main/java/org/openepics/names/util/NamingConventionUtil.java +++ b/src/main/java/org/openepics/names/util/NamingConventionUtil.java @@ -19,7 +19,6 @@ package org.openepics.names.util; import java.util.Arrays; -import java.util.StringTokenizer; import org.apache.commons.lang3.StringUtils; import org.openepics.names.repository.model.Discipline; @@ -138,11 +137,11 @@ public class NamingConventionUtil { // system structure // before first occurrence of DELIMITER_EXTRA - StringTokenizer st1 = new StringTokenizer(conventionName, DELIMITER_EXTRA, false); - if (st1.countTokens() == 1 || st1.countTokens() == 2 || st1.countTokens() == 3) { - StringTokenizer st2 = new StringTokenizer(st1.nextToken(), DELIMITER_INTRA, false); - if (st2.countTokens() == 3) { - return st2.nextToken(); + String[] s1 = conventionName.split(DELIMITER_EXTRA); + if (s1.length == 1 || s1.length == 2 || s1.length == 3) { + String[] s2 = s1[0].split(DELIMITER_INTRA); + if (s2.length == 3) { + return s2[0]; } } } @@ -161,14 +160,13 @@ public class NamingConventionUtil { // system structure // before first occurrence of DELIMITER_EXTRA - StringTokenizer st1 = new StringTokenizer(conventionName, DELIMITER_EXTRA, false); - if (st1.countTokens() == 1 || st1.countTokens() == 2 || st1.countTokens() == 3) { - StringTokenizer st2 = new StringTokenizer(st1.nextToken(), DELIMITER_INTRA, false); - if (st2.countTokens() == 3) { - st2.nextToken(); - return st2.nextToken(); - } else if (st2.countTokens() == 2 || st2.countTokens() == 1) { - return st2.nextToken(); + String[] s1 = conventionName.split(DELIMITER_EXTRA); + if (s1.length == 1 || s1.length == 2 || s1.length == 3) { + String[] s2 = s1[0].split(DELIMITER_INTRA); + if (s2.length == 3) { + return s2[1]; + } else if (s2.length == 2 || s2.length == 1) { + return s2[0]; } } } @@ -187,16 +185,13 @@ public class NamingConventionUtil { // system structure // before first occurrence of DELIMITER_EXTRA - StringTokenizer st1 = new StringTokenizer(conventionName, DELIMITER_EXTRA, false); - if (st1.countTokens() == 1 || st1.countTokens() == 2 || st1.countTokens() == 3) { - StringTokenizer st2 = new StringTokenizer(st1.nextToken(), DELIMITER_INTRA, false); - if (st2.countTokens() == 3) { - st2.nextToken(); - st2.nextToken(); - return st2.nextToken(); - } else if (st2.countTokens() == 2) { - st2.nextToken(); - return st2.nextToken(); + String[] s1 = conventionName.split(DELIMITER_EXTRA); + if (s1.length == 1 || s1.length == 2 || s1.length == 3) { + String[] s2 = s1[0].split(DELIMITER_INTRA); + if (s2.length == 3) { + return s2[2]; + } else if (s2.length == 2) { + return s2[1]; } } } @@ -216,12 +211,11 @@ public class NamingConventionUtil { // after first occurrence of DELIMITER_EXTRA // before possible second occurrence of DELIMITER_EXTRA - StringTokenizer st1 = new StringTokenizer(conventionName, DELIMITER_EXTRA, false); - if (st1.countTokens() == 2 || st1.countTokens() == 3) { - st1.nextToken(); - StringTokenizer st2 = new StringTokenizer(st1.nextToken(), DELIMITER_INTRA, false); - if (st2.countTokens() == 3 || st2.countTokens() == 2) { - return st2.nextToken(); + String[] s1 = conventionName.split(DELIMITER_EXTRA); + if (s1.length == 2 || s1.length == 3) { + String[] s2 = s1[1].split(DELIMITER_INTRA); + if (s2.length == 3 || s2.length == 2) { + return s2[0]; } } } @@ -241,13 +235,11 @@ public class NamingConventionUtil { // after first occurrence of DELIMITER_EXTRA // before possible second occurrence of DELIMITER_EXTRA - StringTokenizer st1 = new StringTokenizer(conventionName, DELIMITER_EXTRA, false); - if (st1.countTokens() == 2 || st1.countTokens() == 3) { - st1.nextToken(); - StringTokenizer st2 = new StringTokenizer(st1.nextToken(), DELIMITER_INTRA, false); - if (st2.countTokens() == 3 || st2.countTokens() == 2) { - st2.nextToken(); - return st2.nextToken(); + String[] s1 = conventionName.split(DELIMITER_EXTRA); + if (s1.length == 2 || s1.length == 3) { + String[] s2 = s1[1].split(DELIMITER_INTRA); + if (s2.length == 3 || s2.length == 2) { + return s2[1]; } } } @@ -267,14 +259,11 @@ public class NamingConventionUtil { // after first occurrence of DELIMITER_EXTRA // before possible second occurrence of DELIMITER_EXTRA - StringTokenizer st1 = new StringTokenizer(conventionName, DELIMITER_EXTRA, false); - if (st1.countTokens() == 2 || st1.countTokens() == 3) { - st1.nextToken(); - StringTokenizer st2 = new StringTokenizer(st1.nextToken(), DELIMITER_INTRA, false); - if (st2.countTokens() == 3) { - st2.nextToken(); - st2.nextToken(); - return st2.nextToken(); + String[] s1 = conventionName.split(DELIMITER_EXTRA); + if (s1.length == 2 || s1.length == 3) { + String[] s2 = s1[1].split(DELIMITER_INTRA); + if (s2.length == 3) { + return s2[2]; } } } -- GitLab