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

ljacqu / wordeval / 14562498097

20 Apr 2025 07:08PM UTC coverage: 54.64% (-0.6%) from 55.233%
14562498097

push

github

ljacqu
Create tests for appData, prevent AppData from being initialized directly

270 of 570 branches covered (47.37%)

8 of 9 new or added lines in 3 files covered. (88.89%)

26 existing lines in 5 files now uncovered.

736 of 1347 relevant lines covered (54.64%)

3.24 hits per line

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

96.67
/src/main/java/ch/jalu/wordeval/dictionary/Dictionary.java
1
package ch.jalu.wordeval.dictionary;
2

3
import ch.jalu.wordeval.dictionary.sanitizer.Sanitizer;
4
import ch.jalu.wordeval.language.Language;
5
import lombok.Getter;
6
import lombok.ToString;
7

8
import java.util.Objects;
9
import java.util.function.Function;
10

11
import static com.google.common.base.MoreObjects.firstNonNull;
12

13
/**
14
 * Dictionary. Stores the {@link #file location} as well as various parameters
15
 * on its format so that its entries can be read correctly.
16
 */
17
@Getter
18
@ToString(of = "identifier")
19
public class Dictionary {
20

21
  /**
22
   * The dictionary identifier is typically the ISO-639-1 abbreviation of its language.
23
   */
24
  private final String identifier;
25

26
  private final String file;
27

28
  private final Language language;
29

30
  /**
31
   * Collection of characters to search for in a read line. The line is cut
32
   * before the first occurrence of a delimiter, returning the word without any
33
   * additional data the dictionary may store.
34
   */
35
  private final char[] delimiters;
36
  /**
37
   * Collection of skip sequences - if any such sequence is found in the word,
38
   * it is skipped.
39
   */
40
  private final String[] skipSequences;
41
  /**
42
   * Function that creates a custom sanitizer (null if none available).
43
   */
44
  private final Function<Dictionary, Sanitizer> sanitizerCreator;
45

46
  private Dictionary(String identifier, String file, Language language, char[] delimiters,
47
                     String[] skipSequences, Function<Dictionary, Sanitizer> sanitizerCreator) {
2✔
48
    this.identifier = identifier;
3✔
49
    this.file = file;
3✔
50
    this.language = language;
3✔
51
    this.delimiters = delimiters;
3✔
52
    this.skipSequences = skipSequences;
3✔
53
    this.sanitizerCreator = sanitizerCreator;
3✔
54
  }
1✔
55

56
  /**
57
   * Builds a sanitizer with the required information.
58
   * @return The created sanitizer
59
   */
60
  public Sanitizer buildSanitizer() {
61
    return sanitizerCreator == null
4!
UNCOV
62
        ? new Sanitizer(this)
×
63
        : sanitizerCreator.apply(this);
5✔
64
  }
65

66
  public static Builder builder() {
67
    return new Builder();
4✔
68
  }
69

70
  public static final class Builder {
71

72
    private String identifier;
73
    private String file;
74
    private Language language;
75
    private char[] delimiters;
76
    private String[] skipSequences;
77
    private Function<Dictionary, Sanitizer> sanitizerCreator;
78

79
    private Builder() {
80
    }
81

82
    public Dictionary build() {
83
      Objects.requireNonNull(identifier, "identifier");
5✔
84
      Objects.requireNonNull(file, "file");
5✔
85
      Objects.requireNonNull(language, "language");
5✔
86

87
      return new Dictionary(
13✔
88
        identifier,
89
        file,
90
        language,
91
        firstNonNull(delimiters, new char[0]),
6✔
92
        firstNonNull(skipSequences, new String[0]),
5✔
93
        sanitizerCreator);
94
    }
95

96
    public Builder identifier(String identifier) {
97
      this.identifier = identifier;
3✔
98
      return this;
2✔
99
    }
100

101
    public Builder file(String file) {
102
      this.file = file;
3✔
103
      return this;
2✔
104
    }
105

106
    public Builder language(Language language) {
107
      this.language = language;
3✔
108
      return this;
2✔
109
    }
110

111
    public Builder delimiters(char... delimiters) {
112
      this.delimiters = delimiters;
3✔
113
      return this;
2✔
114
    }
115

116
    public Builder skipSequences(String... skipSequences) {
117
      this.skipSequences = skipSequences;
3✔
118
      return this;
2✔
119
    }
120

121
    public Builder sanitizerCreator(Function<Dictionary, Sanitizer> sanitizerCreator) {
122
      this.sanitizerCreator = sanitizerCreator;
3✔
123
      return this;
2✔
124
    }
125
  }
126
}
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

© 2025 Coveralls, Inc