From 5f4ad5edf50bbbabff70d6fe1e99f97c86658448 Mon Sep 17 00:00:00 2001 From: steffenaxer <26229392+steffenaxer@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:18:29 +0100 Subject: [PATCH] Use computeIfAbsent for stringCache --- .../attributeconverters/StringConverter.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java b/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java index 3a600e82bc1..bf9a209818a 100644 --- a/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java +++ b/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java @@ -31,14 +31,10 @@ */ public class StringConverter implements AttributeConverter { private final Map stringCache = new ConcurrentHashMap<>(1000); + @Override public String convert(String value) { - String s = this.stringCache.get(value); - if (s == null) { - s = value; - this.stringCache.put(s, s); - } - return s; + return stringCache.computeIfAbsent(value, k -> k); } @Override