Skip to content

Commit

Permalink
Fix Unicode attribute returning emoji instead os Unicode string. Do n…
Browse files Browse the repository at this point in the history
…o longer fetch emoji sources from third party services. Instead, use a custom script
  • Loading branch information
felldo committed Sep 6, 2024
1 parent 8f0c25a commit 0340b12
Show file tree
Hide file tree
Showing 9 changed files with 6,334 additions and 6,118 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ as possible.
### Fetched sources:

- [unicode.org](https://unicode.org/Public/emoji/latest/emoji-test.txt) for all unicode emojis
- [EmojiTerra](https://emojiterra.com/list/) for additional information about emojis like aliases
- [discord-emoji by Emzi0767](https://gitlab.emzi0767.dev/Emzi0767/discord-emoji) for additional information about
emojis for Discord
- [Discord](https://discord.com) custom script for fetching additional information about emojis for Discord
- [Slack](https://slack.com) custom script for fetching additional information about emojis for Slack

## 📦 Installation

Expand Down Expand Up @@ -242,9 +241,9 @@ large files were used. Click [Here](./lib/src/jmh/) to see the benchmark code an

## 💾 Emoji JSON list Generation

The emoji list can be easily generated with the ``generateEmojis`` Gradle task. The generated list will be saved in the
The emoji list can be easily generated with the ``generate`` Gradle task. The generated list will be saved in the
``public`` folder.

## Project setup
To get started with your local development, execute the ``generate`` Gradle task in the group ``other``.
To get started with your local development, execute the ``generateJavaSourceFiles`` Gradle task in the group ``jemoji``.

2 changes: 1 addition & 1 deletion emoji_source_files/github-emoji-definition.json

Large diffs are not rendered by default.

639 changes: 437 additions & 202 deletions lib/build.gradle.kts

Large diffs are not rendered by default.

49 changes: 18 additions & 31 deletions lib/src/main/java/net/fellbaum/jemoji/Emoji.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public final class Emoji implements Comparable<Emoji> {
private final List<String> allAliases;

Emoji(
String emoji,
String unicode,
List<String> discordAliases,
List<String> slackAliases,
List<String> githubAliases,
boolean hasFitzpatrick,
boolean hasHairStyle,
double version,
Qualification qualification,
String description,
EmojiGroup group,
EmojiSubGroup subgroup,
boolean hasVariationSelectors) {
final String emoji,
final String unicode,
final List<String> discordAliases,
final List<String> slackAliases,
final List<String> githubAliases,
final boolean hasFitzpatrick,
final boolean hasHairStyle,
final double version,
final Qualification qualification,
final String description,
final EmojiGroup group,
final EmojiSubGroup subgroup,
final boolean hasVariationSelectors) {
this.emoji = emoji;
this.unicode = unicode;
this.discordAliases = discordAliases;
Expand All @@ -57,7 +57,7 @@ public final class Emoji implements Comparable<Emoji> {
this.group = group;
this.subgroup = subgroup;
this.hasVariationSelectors = hasVariationSelectors;
Set<String> aliases = new HashSet<>();
final Set<String> aliases = new HashSet<>();
aliases.addAll(getDiscordAliases());
aliases.addAll(getGithubAliases());
aliases.addAll(getSlackAliases());
Expand Down Expand Up @@ -123,13 +123,14 @@ public List<Emoji> getVariations() {
public String getURLEncoded() {
try {
return URLEncoder.encode(getEmoji(), StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
} catch (final UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

/**
* Gets the Discord aliases for this emoji.
* If possible, do not use the :name::skin-tone-1: variants as they might not produce the emoji you want.
*
* @return The Discord aliases for this emoji.
*/
Expand Down Expand Up @@ -322,25 +323,11 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;

Emoji emoji1 = (Emoji) o;
return hasFitzpatrick == emoji1.hasFitzpatrick && hasHairStyle == emoji1.hasHairStyle && Double.compare(version, emoji1.version) == 0 && hasVariationSelectors == emoji1.hasVariationSelectors && emoji.equals(emoji1.emoji) && unicode.equals(emoji1.unicode) && discordAliases.equals(emoji1.discordAliases) && githubAliases.equals(emoji1.githubAliases) && slackAliases.equals(emoji1.slackAliases) && qualification == emoji1.qualification && description.equals(emoji1.description) && group == emoji1.group && subgroup == emoji1.subgroup && allAliases.equals(emoji1.allAliases);
return emoji.equals(emoji1.emoji);
}

@Override
public int hashCode() {
int result = emoji.hashCode();
result = 31 * result + unicode.hashCode();
result = 31 * result + discordAliases.hashCode();
result = 31 * result + githubAliases.hashCode();
result = 31 * result + slackAliases.hashCode();
result = 31 * result + Boolean.hashCode(hasFitzpatrick);
result = 31 * result + Boolean.hashCode(hasHairStyle);
result = 31 * result + Double.hashCode(version);
result = 31 * result + qualification.hashCode();
result = 31 * result + description.hashCode();
result = 31 * result + group.hashCode();
result = 31 * result + subgroup.hashCode();
result = 31 * result + Boolean.hashCode(hasVariationSelectors);
result = 31 * result + allAliases.hashCode();
return result;
return emoji.hashCode();
}
}
2 changes: 1 addition & 1 deletion lib/src/main/java/net/fellbaum/jemoji/IndexedEmoji.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @see EmojiManager#extractEmojisInOrderWithIndex(String)
*/
public class IndexedEmoji {
public final class IndexedEmoji {
private final Emoji emoji;
private final int charIndex;
private final int codePointIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Map;
import java.util.Optional;

class InternalEmojiUtils {
final class InternalEmojiUtils {

private InternalEmojiUtils() {
}
Expand Down
15 changes: 5 additions & 10 deletions lib/src/test/java/net/fellbaum/jemoji/EmojiManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ public class EmojiManagerTest {
private static final String SIMPLE_POSITION_EMOJI_STRING = "Hello ❤️ ❤ 👩🏻‍🤝‍👨🏼 ❤❤️ World";
private static final String EMOJI_VARIATION_STRING = "♎️";

/*@Test
public void testIfLoadedEmojisMatchesWithJSON() {
ObjectMapper objectMapper = new ObjectMapper();
try {
JsonNode node = objectMapper.readTree(Paths.get(".." + File.separator + "public/emojis.min.json").toFile());
assertEquals(node.size(), EmojiManager.getAllEmojis().size());
} catch (IOException e) {
throw new RuntimeException(e);
}
}*/
@Test
public void testIfAllEmojisAreUnique() {
final List<String> unicodeEmojis = EmojiManager.getAllEmojis().stream().map(Emoji::getEmoji).collect(Collectors.toList());
assertTrue(EmojiManager.getAllEmojis().stream().allMatch(emoji -> unicodeEmojis.contains(emoji.getEmoji())));
}

@Test
public void testIfEmojiAlternativeLanguageIsLoaded() {
Expand Down
Loading

0 comments on commit 0340b12

Please sign in to comment.