From 8ad730376d13e3cbd303157cb39030b76cf529c6 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 1 Mar 2020 20:17:29 +0100 Subject: [PATCH] Optimize LanguageUtils#getEnchantmentString(...) --- .../shopchest/language/LanguageUtils.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index af84d8c..9168510 100644 --- a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -23,6 +23,7 @@ import org.bukkit.potion.PotionType; import java.util.ArrayList; import java.util.Map; +import java.util.StringJoiner; public class LanguageUtils { @@ -2417,21 +2418,13 @@ public class LanguageUtils { */ public static String getEnchantmentString(Map enchantmentMap) { if (enchantmentMap == null) return null; - Enchantment[] enchantments = enchantmentMap.keySet().toArray(new Enchantment[enchantmentMap.size()]); - StringBuilder enchantmentList = new StringBuilder(); + StringJoiner joiner = new StringJoiner(", "); - for (int i = 0; i < enchantments.length; i++) { - Enchantment enchantment = enchantments[i]; - - if (i == enchantments.length - 1) { - enchantmentList.append(LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment))); - } else { - enchantmentList.append(LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment))); - enchantmentList.append(", "); - } + for (Enchantment enchantment : enchantmentMap.keySet()) { + joiner.add(LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment))); } - return enchantmentList.toString(); + return joiner.toString(); } /**