forked from java-cli-apps/basic-java-22-quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguage.java
More file actions
32 lines (26 loc) · 952 Bytes
/
Language.java
File metadata and controls
32 lines (26 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import net.fellbaum.jemoji.Emoji;
import net.fellbaum.jemoji.EmojiManager;
import java.util.Optional;
public enum Language {
French("Bonjour", "fr"),
English("Hello", "gb");
private final String message;
private final String alias;
Language(String message, String alias) {
this.message = message;
this.alias = alias;
}
public String getGreeting() {
Optional<Emoji> optionalEmoji = EmojiManager.getByAlias(alias);
String flag = optionalEmoji.map(Emoji::getEmoji).orElse("");
return message + " " + flag;
}
public static Language fromString(String language) {
return switch (language) {
case String s when s.equals(French.name()) -> French;
case String s when s.equals(English.name()) -> English;
default ->
throw new IllegalArgumentException("No response or unknown language provided.");
};
}
}