Skip to content

Commit

Permalink
Merge remote-tracking branch 'felldo/master' into refactor/performance
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/src/main/java/net/fellbaum/jemoji/EmojiManager.java
  • Loading branch information
freya022 committed Nov 9, 2023
2 parents d4c1ad1 + fdc47e3 commit 086b209
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/src/main/java/net/fellbaum/jemoji/EmojiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class EmojiManager {
// Get emoji by alias
private static final Map<AliasGroup, Map<String, Emoji>> ALIAS_GROUP_TO_EMOJI_ALIAS_TO_EMOJI = new EnumMap<>(AliasGroup.class);

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> EMOJI_CODEPOINT_COMPARATOR = (final Emoji o1, final Emoji o2) -> {
Expand All @@ -50,9 +50,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);
}
Expand Down Expand Up @@ -247,6 +244,11 @@ private static <K, V> V getEither(Map<K, V> map, K first, K second) {
* @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;
}

Expand Down

0 comments on commit 086b209

Please sign in to comment.