Skip to content

Commit

Permalink
small code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnaber committed Apr 4, 2015
1 parent 4d0d957 commit 904e236
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Expand Up @@ -73,33 +73,36 @@ private void loadCompoundFile(final String path) throws IOException {
) {
String line;
while ((line = br.readLine()) != null) {
if (line.length() < 1 || line.charAt(0) == '#') {
if (line.isEmpty() || line.charAt(0) == '#') {
continue; // ignore comments
}
// the set contains the incorrect spellings, i.e. the ones without hyphen
line = line.replace('-', ' ');
final String[] parts = line.split(" ");
if (parts.length > AbstractCompoundRule.MAX_TERMS) {
throw new IOException("Too many compound parts in file " + path + ": " + line + ", maximum allowed: " + AbstractCompoundRule.MAX_TERMS);
}
if (parts.length == 1) {
throw new IOException("Not a compound in file " + path + ": " + line);
}
line = line.replace('-', ' '); // the set contains the incorrect spellings, i.e. the ones without hyphen
validateLine(path, line);
if (line.endsWith("+")) {
line = removeLastCharacter(line);
noDashSuggestion.add(line.toLowerCase());
} else if (line.endsWith("*")) {
line = removeLastCharacter(line);
onlyDashSuggestion.add(line.toLowerCase());
}
if (incorrectCompounds.contains(line.toLowerCase())) {
throw new RuntimeException("Duplicated word in file " + path + ": " + line);
}
incorrectCompounds.add(line.toLowerCase());
}
}
}

private void validateLine(String path, String line) throws IOException {
final String[] parts = line.split(" ");
if (parts.length == 1) {
throw new RuntimeException("Not a compound in file " + path + ": " + line);
}
if (parts.length > AbstractCompoundRule.MAX_TERMS) {
throw new RuntimeException("Too many compound parts in file " + path + ": " + line + ", maximum allowed: " + AbstractCompoundRule.MAX_TERMS);
}
if (incorrectCompounds.contains(line.toLowerCase())) {
throw new RuntimeException("Duplicated word in file " + path + ": " + line);
}
}

private String removeLastCharacter(String str) {
return str.substring(0, str.length() - 1);
}
Expand Down
Expand Up @@ -30,9 +30,6 @@
*/
public final class SimpleReplaceDataLoader {

public SimpleReplaceDataLoader() {
}

/**
* Load replacement rules from a utf-8 stream.
*/
Expand Down

0 comments on commit 904e236

Please sign in to comment.