-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve EMOJI_CODEPOINT_COMPARATOR (#18)
* Improve/replace EMOJI_CODEPOINT_COMPARATOR * Rework Emoji Comparator in EmojiManager to Emoji implementing Comparable. * Created EmojiUtils used for internal utility methods. * Compare Emojis with their codepoints and if they are equal, compare their emoji unicode value --------- Co-authored-by: Dominic Fellbaum <[email protected]>
- Loading branch information
Showing
3 changed files
with
61 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.fellbaum.jemoji; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
class EmojiUtils { | ||
|
||
public static int getCodePointCount(String string) { | ||
return string.codePointCount(0, string.length()); | ||
} | ||
|
||
public static boolean isStringNullOrEmpty(final String string) { | ||
return null == string || string.isEmpty(); | ||
} | ||
|
||
public static String removeColonFromAlias(final String alias) { | ||
return alias.startsWith(":") && alias.endsWith(":") ? alias.substring(1, alias.length() - 1) : alias; | ||
} | ||
|
||
public static String addColonToAlias(final String alias) { | ||
return alias.startsWith(":") && alias.endsWith(":") ? alias : ":" + alias + ":"; | ||
} | ||
|
||
public static <K, V> Optional<V> findEmojiByEitherAlias(final Map<K, V> map, final K aliasWithColon, final K aliasWithoutColon) { | ||
final V firstValue = map.get(aliasWithColon); | ||
if (firstValue != null) return Optional.of(firstValue); | ||
final V secondValue = map.get(aliasWithoutColon); | ||
if (secondValue != null) return Optional.of(secondValue); | ||
return Optional.empty(); | ||
} | ||
} |