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

trydofor / professional-mirana / #92

26 Jan 2025 09:07AM UTC coverage: 86.903% (-0.5%) from 87.427%
#92

push

trydofor
✨ R.ngError, CodeAware, NameAware #49

0 of 45 new or added lines in 6 files covered. (0.0%)

3 existing lines in 2 files now uncovered.

6861 of 7895 relevant lines covered (86.9%)

0.87 hits per line

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

97.06
/src/main/java/pro/fessional/mirana/i18n/I18nString.java
1
package pro.fessional.mirana.i18n;
2

3
import org.jetbrains.annotations.Contract;
4
import org.jetbrains.annotations.NotNull;
5
import org.jetbrains.annotations.Nullable;
6

7
import java.beans.Transient;
8
import java.text.MessageFormat;
9
import java.util.Arrays;
10
import java.util.Locale;
11
import java.util.Objects;
12

13
/**
14
 * <pre>
15
 * String can be used as i18n template (MessageFormat by default)
16
 * - i18nCode - template id, default empty
17
 * - i18nArgs - template arguments, default empty
18
 * - i18nHint - default text or template, not in hash and equals, default empty
19
 * - i18nCache - cached value for performance
20
 * </pre>
21
 *
22
 * @author trydofor
23
 * @see MessageFormat
24
 * @since 2019-09-19
25
 */
26
public class I18nString implements I18nAware {
27
    private static final long serialVersionUID = 19791023L;
28
    private static final Object[] EMPTY_ARGS = {};
1✔
29

30
    @NotNull
31
    private final String i18nCode;
32
    @NotNull
33
    private final Object[] i18nArgs;
34
    @NotNull
35
    private String i18nHint;
36

37
    private transient String i18nCache = null;
1✔
38

39
    public I18nString(String i18nCode) {
40
        this(i18nCode, "", EMPTY_ARGS);
1✔
41
    }
1✔
42

43
    public I18nString(String i18nCode, String i18nHint) {
44
        this(i18nCode, i18nHint, EMPTY_ARGS);
1✔
45
    }
1✔
46

47
    public I18nString(String i18nCode, String i18nHint, Object... args) {
1✔
48
        this.i18nCode = i18nCode == null ? "" : i18nCode;
1✔
49
        this.i18nArgs = args == null ? EMPTY_ARGS : args;
1✔
50
        this.i18nHint = i18nHint == null ? "" : i18nHint;
1✔
51
    }
1✔
52

53
    @Override
54
    @NotNull
55
    public String getI18nCode() {
56
        return i18nCode;
1✔
57
    }
58

59
    @Override
60
    @NotNull
61
    public Object[] getI18nArgs() {
62
        return i18nArgs;
1✔
63
    }
64

65
    @Override
66
    @NotNull
67
    public String getI18nHint() {
68
        return i18nHint;
1✔
69
    }
70

71
    @Contract("_ -> this")
72
    public I18nString setI18nHint(String i18nHint) {
73
        this.i18nHint = i18nHint == null ? "" : i18nHint;
1✔
74
        return this;
1✔
75
    }
76

77
    @Transient
78
    @Contract("_->this")
79
    public I18nString setI18nHintBy(@Nullable Locale locale) {
80
        return setI18nHint(toString(locale));
1✔
81
    }
82

83
    @Transient
84
    @Contract("_,_->this")
85
    public I18nString setI18nHintBy(@Nullable Locale locale, @NotNull I18nSource source) {
86
        return setI18nHint(toString(locale, source));
1✔
87
    }
88

89
    @Nullable
90
    public String getI18nCache() {
91
        return i18nCache;
1✔
92
    }
93

94
    @Contract("_->this")
95
    public I18nString setI18nCache(String i18nCache) {
96
        this.i18nCache = i18nCache;
1✔
97
        return this;
1✔
98
    }
99

100
    @Transient
101
    @Contract("_,_->this")
102
    public I18nString setI18nCacheBy(@Nullable Locale locale, @NotNull I18nSource source) {
103
        return setI18nCache(toString(locale, source));
1✔
104
    }
105

106
    @Transient
107
    public boolean isEmpty() {
108
        return i18nCode.isEmpty();
1✔
109
    }
110

111
    @Override
112
    public String toString() {
113
        if (i18nCache != null) return i18nCache;
1✔
114
        return toString(Locale.getDefault());
1✔
115
    }
116

117
    @Override
118
    public boolean equals(Object o) {
119
        if (this == o) return true;
1✔
120
        if (!(o instanceof I18nString)) return false;
1✔
121
        I18nString that = (I18nString) o;
1✔
122
        return Objects.equals(i18nCode, that.i18nCode) && Arrays.equals(i18nArgs, that.i18nArgs);
1✔
123
    }
124

125
    @Override
126
    public int hashCode() {
127
        int result = Objects.hash(i18nCode);
1✔
128
        result = 31 * result + Arrays.hashCode(i18nArgs);
1✔
129
        return result;
1✔
130
    }
131

132
    /**
133
     * the string as i18nCode, empty args and hint
134
     */
135
    public static I18nString of(String str) {
136
        return new I18nString(str);
1✔
137
    }
138

139
    /**
140
     * the string as i18nCode, empty args and hint
141
     */
142
    public static I18nString of(@NotNull I18nAware i18n) {
NEW
143
        return new I18nString(i18n.getI18nCode(), i18n.getI18nHint(), i18n.getI18nArgs());
×
144
    }
145
}
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