From 13c41c9182be94fa4419f8737033b6812689a29e Mon Sep 17 00:00:00 2001 From: Sam Leeflang Date: Mon, 18 Nov 2024 17:34:10 +0100 Subject: [PATCH] Reduce complexity --- .../dissco/core/translator/terms/utils/AgentsUtils.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java b/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java index b5b21e4..b89e42e 100644 --- a/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java +++ b/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java @@ -65,11 +65,11 @@ private static void handleMultipleAgents( List agents, String agentValue, String agentId, AgentRoleType role, Type type) { var ids = new String[0]; var agentValues = new String[0]; - if (agentValue != null && (agentValue.contains("&") || agentValue.contains("|"))) { + if (checkIfNeedsParsing(agentValue)) { agentValues = Arrays.stream(agentValue.split("[&|]")).map(String::trim) .toArray(String[]::new); } - if (agentId != null && (agentId.contains("&") || agentId.contains("|"))) { + if (checkIfNeedsParsing(agentId)) { ids = Arrays.stream(agentId.split("[&|]")).map(String::trim).toArray(String[]::new); } if (agentValues.length == ids.length) { @@ -96,4 +96,8 @@ private static void handleMultipleAgents( } } } + + private static boolean checkIfNeedsParsing(String value) { + return value != null && (value.contains("&") || value.contains("|")); + } }