generated from stscoundrel/java-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from stscoundrel/feature/dictionary
Feature/dictionary
- Loading branch information
Showing
8 changed files
with
147 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/main/java/com/github/stscoundrel/javatemplate/App.java
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
src/main/java/io/github/stscoundrel/oldicelandicdictionary/Dictionary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.github.stscoundrel.oldicelandicdictionary; | ||
|
||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
|
||
import com.google.gson.Gson; | ||
|
||
public class Dictionary { | ||
private DictionaryEntry[] entries; | ||
private DictionaryEntry[] markupEntries; | ||
|
||
enum DictionaryLocation { | ||
NoMarkup, | ||
Markup | ||
} | ||
|
||
private static String getDictionaryPath(DictionaryLocation location) { | ||
if (location == DictionaryLocation.NoMarkup) { | ||
return "/no-markup.json"; | ||
} | ||
return "/markup.json"; | ||
|
||
} | ||
|
||
private static DictionaryEntry[] readDictionary(DictionaryLocation location) { | ||
// Read the JSON file from the resources folder | ||
InputStream inputStream = Dictionary.class.getResourceAsStream(getDictionaryPath(location)); | ||
Reader reader = new InputStreamReader(inputStream); | ||
|
||
// Create a Gson instance | ||
Gson gson = new Gson(); | ||
|
||
// Parse the JSON and convert it to a Java object | ||
DictionaryEntry[] result = gson.fromJson(reader, DictionaryEntry[].class); | ||
|
||
return result; | ||
} | ||
|
||
public DictionaryEntry[] getMarkupDictionary() { | ||
if (entries == null) { | ||
entries = readDictionary(DictionaryLocation.Markup); | ||
} | ||
|
||
return entries; | ||
} | ||
|
||
public DictionaryEntry[] getNoMarkupDictionary() { | ||
if (markupEntries == null) { | ||
markupEntries = readDictionary(DictionaryLocation.NoMarkup); | ||
} | ||
|
||
return markupEntries; | ||
} | ||
|
||
public DictionaryEntry[] getDictionary() { | ||
return getNoMarkupDictionary(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/io/github/stscoundrel/oldicelandicdictionary/DictionaryEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.stscoundrel.oldicelandicdictionary; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class DictionaryEntry { | ||
@SerializedName("a") | ||
public String headword; | ||
|
||
@SerializedName("b") | ||
public String[] definitions; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/test/java/com/github/stscoundrel/javatemplate/AppTest.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
src/test/java/io/github/stscoundrel/oldicelandicdictionary/DictionaryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.github.stscoundrel.oldicelandicdictionary; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class DictionaryTest | ||
extends TestCase { | ||
public void testDefaultDictionaryHasExpectedAmountOfEntries() { | ||
Dictionary dictionary = new Dictionary(); | ||
DictionaryEntry[] result = dictionary.getDictionary(); | ||
|
||
assertEquals(29951, result.length); | ||
} | ||
|
||
public void testMarkupDictionaryHasExpectedAmountOfEntries() { | ||
Dictionary dictionary = new Dictionary(); | ||
DictionaryEntry[] result = dictionary.getMarkupDictionary(); | ||
|
||
assertEquals(29951, result.length); | ||
} | ||
|
||
public void testDictionaryHeadwordsMatch() { | ||
Dictionary dictionary = new Dictionary(); | ||
DictionaryEntry[] noMarkupResult = dictionary.getDictionary(); | ||
DictionaryEntry[] markupResult = dictionary.getMarkupDictionary(); | ||
|
||
for (int i = 0; i < 29951; i++) { | ||
assertEquals(noMarkupResult[i].headword, markupResult[i].headword); | ||
} | ||
} | ||
|
||
public void testDictionaryHasExpectedContent() { | ||
Dictionary dictionary = new Dictionary(); | ||
DictionaryEntry[] result = dictionary.getDictionary(); | ||
|
||
assertEquals("a", result[0].headword); | ||
assertEquals("a negative suffix to verbs, not;", result[0].definitions[0]); | ||
assertEquals("era útmakligt, at it is not unmeet that.", result[0].definitions[1]); | ||
|
||
assertEquals("afbindi", result[14].headword); | ||
assertEquals("n. constipation.", result[14].definitions[0]); | ||
|
||
assertEquals("andstreymr", result[1000].headword); | ||
assertEquals( | ||
"a. strongly adverse (andstreym ørlög); Sighvatr var heldr ~ um eptirmálin, hard to come to terms with.", | ||
result[1000].definitions[0]); | ||
|
||
assertEquals("undanhald", result[25000].headword); | ||
assertEquals("n. flight.", result[25000].definitions[0]); | ||
} | ||
|
||
public void testMarkupDictionaryHasExpectedContent() { | ||
Dictionary dictionary = new Dictionary(); | ||
DictionaryEntry[] result = dictionary.getMarkupDictionary(); | ||
|
||
assertEquals("a", result[0].headword); | ||
assertEquals("a negative suffix to verbs, <i>not</i>;", result[0].definitions[0]); | ||
assertEquals("era útmakligt, <i>at it is not unmeet that</i>.", result[0].definitions[1]); | ||
|
||
assertEquals("afbindi", result[14].headword); | ||
assertEquals("n. <i>constipation</i>.", result[14].definitions[0]); | ||
|
||
assertEquals("andstreymr", result[1000].headword); | ||
assertEquals( | ||
"a. <i>strongly adverse</i> (andstreym ørlög); Sighvatr var heldr ~ um eptirmálin, <i>hard to come to terms with</i>.", | ||
result[1000].definitions[0]); | ||
|
||
assertEquals("undanhald", result[25000].headword); | ||
assertEquals("n. <i>flight</i>.", result[25000].definitions[0]); | ||
} | ||
} |