I have been able to successfully load my ArrayList from the values of the enum class. I am not very familiar with using enums, and I was wondering if there was a way to handle this without typing add for each enum as I have shown.
public enum PartsOfSpeech {
Adjective("Placeholder [adjective] : To be updated..."),
Adverb("Placeholder [adverb] : To be updated..."),
Conjunction("Placeholder [conjection] : To be updated..."),
Interjection("Placeholder [interjection] : To be updated..."),
Noun("Placeholder [noun] : To be updated..."),
Preposition("Placeholder [preposition] : To be updated..."),
Pronoun("Placeholder [pronoun] : To be updated..."),
Verb("Placeholder [verb] : To be updated...");
private String speechValue;
private PartsOfSpeech(String speechValue) {
this.speechValue= speechValue;
}
public String getSpeechValue() {
return speechValue;
}
}
public class Dictionary {
public static void main(String args[]) {
System.out.println("! Loading data...");
Map<String, List<String>> dictionaryMap = new HashMap<String, List<String>>();
List<String> POSList = new ArrayList<>();
POSList.add(PartsOfSpeech.Adjective.getSpeechValue());
POSList.add(PartsOfSpeech.Adverb.getSpeechValue());
POSList.add(PartsOfSpeech.Conjunction.getSpeechValue());
POSList.add(PartsOfSpeech.Interjection.getSpeechValue());
POSList.add(PartsOfSpeech.Noun.getSpeechValue());
POSList.add(PartsOfSpeech.Preposition.getSpeechValue());
POSList.add(PartsOfSpeech.Pronoun.getSpeechValue());
POSList.add(PartsOfSpeech.Verb.getSpeechValue());
dictionaryMap.put("distinct",POSList);
Adjective("Placeholder [adjective] : To be updated..."),just doesn't look right as it looks like you're hard coding implementation details within a model, the enum. Likely better is the more simpleADJECTIVE("adjective"), ...or something similar. You would then create your"Placeholder [%s]: To be updated..."at some later place where you would display information to the user. Otherwise your code becomes rigid and hard to enhance, update and change later.