Skip to content

Commit

Permalink
Fixed some typos, used BufferedReader instead of Files.lines for jar …
Browse files Browse the repository at this point in the history
…packing purposes (Files.lines) throws npe
  • Loading branch information
Fibii committed Jun 12, 2019
1 parent 3e74839 commit 04db242
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 13 additions & 8 deletions src/DiscordCharacters.java → src/me/fibi/manuel/Manuel.java
Original file line number Diff line number Diff line change
@@ -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<Character, String> getAlphabetMap() {
var ENGLISH_CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
var alphaebetMap = ENGLISH_CHARACTERS
var alphabetMap = ENGLISH_CHARACTERS
.chars() // IntStream
.mapToObj(c -> (char) c) // Intstream -> Stream<Character>
.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<Character, String> 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();
Expand Down

0 comments on commit 04db242

Please sign in to comment.