diff --git a/lib/src/main/java/net/fellbaum/jemoji/EmojiManager.java b/lib/src/main/java/net/fellbaum/jemoji/EmojiManager.java index a41733f..5cd1daa 100644 --- a/lib/src/main/java/net/fellbaum/jemoji/EmojiManager.java +++ b/lib/src/main/java/net/fellbaum/jemoji/EmojiManager.java @@ -24,7 +24,7 @@ public final class EmojiManager { private static final Map> EMOJI_FIRST_CODEPOINT_TO_EMOJIS_ORDER_CODEPOINT_LENGTH_DESCENDING; private static final List EMOJIS_LENGTH_DESCENDING; - private static final Pattern EMOJI_PATTERN; + private static Pattern EMOJI_PATTERN; private static final Pattern NOT_WANTED_EMOJI_CHARACTERS = Pattern.compile("[\\p{Alpha}\\p{Z}]"); private static final Comparator EMOJI_CODEPOINT_COMPARATOR = (final Emoji o1, final Emoji o2) -> { @@ -45,9 +45,6 @@ public final class EmojiManager { EMOJIS_LENGTH_DESCENDING = Collections.unmodifiableList(emojis.stream().sorted(EMOJI_CODEPOINT_COMPARATOR).collect(Collectors.toList())); EMOJI_FIRST_CODEPOINT_TO_EMOJIS_ORDER_CODEPOINT_LENGTH_DESCENDING = emojis.stream().collect(getEmojiLinkedHashMapCollector()); - - EMOJI_PATTERN = Pattern.compile(EMOJIS_LENGTH_DESCENDING.stream() - .map(s -> "(" + Pattern.quote(s.getEmoji()) + ")").collect(Collectors.joining("|"))); } catch (final JsonProcessingException e) { throw new RuntimeException(e); } @@ -223,6 +220,11 @@ private static String addColonToAlias(final String alias) { * @return The pattern for all emojis. */ public static Pattern getEmojiPattern() { + if (EMOJI_PATTERN == null) { + EMOJI_PATTERN = Pattern.compile(EMOJIS_LENGTH_DESCENDING.stream() + .map(s -> "(" + Pattern.quote(s.getEmoji()) + ")").collect(Collectors.joining("|"))); + } + return EMOJI_PATTERN; }