• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ljacqu / wordeval / 15617797752

12 Jun 2025 06:01PM UTC coverage: 61.749% (+0.4%) from 61.35%
15617797752

push

github

ljacqu
Add hr, lt, lv, uk language + dictionary

407 of 718 branches covered (56.69%)

21 of 22 new or added lines in 3 files covered. (95.45%)

1017 of 1647 relevant lines covered (61.75%)

3.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/src/main/java/ch/jalu/wordeval/dictionary/WordFactory.java
1
package ch.jalu.wordeval.dictionary;
2

3
import ch.jalu.wordeval.language.Alphabet;
4
import ch.jalu.wordeval.language.Language;
5
import org.apache.commons.lang3.StringUtils;
6

7
import java.util.Locale;
8

9
/**
10
 * Constructs an object of a word in different representations, respecting the language's rules.
11
 */
12
public class WordFactory {
13

14
  private final Locale locale;
15
  private final String lettersToKeep;
16
  private final String tempReplacements;
17
  private final Alphabet alphabet;
18

19
  /**
20
   * Constructor.
21
   *
22
   * @param language the language
23
   */
24
  public WordFactory(Language language) {
2✔
25
    lettersToKeep = language.getCharsToPreserve();
4✔
26
    tempReplacements = initializeTempReplacements(lettersToKeep);
5✔
27
    locale = language.getLocale();
4✔
28
    alphabet = language.getAlphabet();
4✔
29
  }
1✔
30

31
  /**
32
   * Computes the different word forms (all lowercase, accents removed, etc.) for the given word.
33
   *
34
   * @param word the word to process in its raw form
35
   * @return Word with all its forms
36
   */
37
  public Word createWordObject(String word) {
38
    if (word.isEmpty()) {
3✔
39
      throw new IllegalArgumentException("The word may not be empty");
5✔
40
    }
41

42
    Word wordObject = new Word();
4✔
43
    wordObject.setRaw(word);
3✔
44
    wordObject.setLowercase(word.toLowerCase(locale));
6✔
45
    wordObject.setWithoutAccents(removeNonLetterAccents(wordObject.getLowercase()));
6✔
46
    wordObject.setWithoutAccentsWordCharsOnly(wordObject.getWithoutAccents()
6✔
47
      .replace("-", "").replace("'", ""));
4✔
48
    return wordObject;
2✔
49
  }
50

51
  private String removeNonLetterAccents(String word) {
52
    if (lettersToKeep.isEmpty()) {
4✔
53
      alphabet.removeAccents(word);
5✔
54
    }
55

56
    String escapedWord = alphabet.removeAccents(StringUtils.replaceChars(word, lettersToKeep, tempReplacements));
10✔
57
    return StringUtils.replaceChars(escapedWord, tempReplacements, lettersToKeep);
7✔
58
  }
59

60
  private static String initializeTempReplacements(String lettersToKeep) {
61
    if (lettersToKeep.length() > 20) {
4!
NEW
62
      throw new IllegalStateException("Can only support up to 20 additional letters currently; "
×
63
          + "please update WordFactory with more replacements.");
64
    }
65

66
    return "01234567890123456789".substring(0, lettersToKeep.length());
6✔
67
  }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc