diff --git a/README.md b/README.md index 2765586..52938b6 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ ## Manuel -Manuel is a lightweight library that encodes English alphabet to discord alphabet emojis. +me.fibi.manuel.Manuel is a lightweight library that encodes English alphabet to discord alphabet emojis. It uses streams to map the characters to emojis. #### Example of usage ```java -var manuel = new DiscordCharacters(); +var manuel = new Manuel(); System.out.println(manuel.getEncodedStatement("manuel 2.9")); ``` ![](https://i.imgur.com/As0Q0WJ.png) \ No newline at end of file diff --git a/src/DiscordCharacters.java b/src/me/fibi/manuel/Manuel.java similarity index 69% rename from src/DiscordCharacters.java rename to src/me/fibi/manuel/Manuel.java index 741a23c..a47605e 100644 --- a/src/DiscordCharacters.java +++ b/src/me/fibi/manuel/Manuel.java @@ -1,35 +1,40 @@ +package me.fibi.manuel; + +import java.io.BufferedReader; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.io.InputStreamReader; import java.util.Map; import java.util.stream.Collectors; -public class DiscordCharacters { +public class Manuel { /** * generates a map of english characters with discord emoji values */ private Map getAlphabetMap() { var ENGLISH_CHARACTERS = "abcdefghijklmnopqrstuvwxyz"; - var alphaebetMap = ENGLISH_CHARACTERS + var alphabetMap = ENGLISH_CHARACTERS .chars() // IntStream .mapToObj(c -> (char) c) // Intstream -> Stream .collect(Collectors.toMap(c -> c, c -> ":regional_indicator_" + c + ":")); // characters to map - return alphaebetMap; + return alphabetMap; } /** * adds spacing, punctuation marks to the map * - * @return map of english Charactersm punctuation marks with discord emoji values + * @return map of english Characters punctuation marks with discord emoji values */ private Map getCharMap() { try { var charMap = getAlphabetMap(); - var emojiMap = Files.lines(Paths.get("res/emoji.txt")) + // var emojiMap = Files.lines(Path.of(Manuel.class.getClassLoader().getResource("emoji.txt").getPath())).collect(Collectors.toMap(s -> s.split(",")[0].toCharArray()[0], s -> ":" + s.split(",")[1].strip() + ":")); + // Files.lines won't work for jar, gotta use BufferedReader + var emojiMap = new BufferedReader(new InputStreamReader(Manuel.class.getClassLoader().getResource("emoji.txt").openStream())) + .lines() .collect(Collectors.toMap(s -> s.split(",")[0].toCharArray()[0], s -> ":" + s.split(",")[1].strip() + ":")); charMap.putAll(emojiMap); // merge the two maps - charMap.put(' ', "\t"); + charMap.put(' ', "\t"); // add space encoding return charMap; } catch (IOException e) { e.printStackTrace();