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

AuthMe / ConfigMe / 6147809157

11 Sep 2023 02:28PM UTC coverage: 98.541% (+1.2%) from 97.344%
6147809157

push

github

ljacqu
Add some more tests / create util method for empty check

534 of 548 branches covered (0.0%)

7 of 7 new or added lines in 4 files covered. (100.0%)

1486 of 1508 relevant lines covered (98.54%)

4.5 hits per line

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

97.22
/src/main/java/ch/jalu/configme/properties/PropertyInitializer.java
1
package ch.jalu.configme.properties;
2

3
import ch.jalu.configme.properties.builder.ArrayPropertyBuilder;
4
import ch.jalu.configme.properties.builder.CollectionPropertyBuilder;
5
import ch.jalu.configme.properties.builder.MapPropertyBuilder;
6
import ch.jalu.configme.properties.types.ArrayPropertyType;
7
import ch.jalu.configme.properties.types.InlineArrayPropertyType;
8
import ch.jalu.configme.properties.types.PropertyType;
9
import org.jetbrains.annotations.NotNull;
10

11
import java.util.Collection;
12
import java.util.List;
13
import java.util.Map;
14
import java.util.Set;
15
import java.util.function.IntFunction;
16
import java.util.regex.Pattern;
17

18
/**
19
 * Convenience class for instantiating {@link Property} objects. You can use
20
 * a static import for the methods for a short, convenient way to declare properties.
21
 * <p>
22
 * If you use additional property types, it may make the most sense to write your own
23
 * property initializer class similar to this one, or extend this class to keep the
24
 * default methods.
25
 */
26
public class PropertyInitializer {
27

28
    protected PropertyInitializer() {
2✔
29
        // Protected constructor to allow inheritance
30
    }
1✔
31

32
    /**
33
     * Creates a new boolean property.
34
     *
35
     * @param path the property's path
36
     * @param defaultValue the default value
37
     * @return the created property
38
     */
39
    public static @NotNull BooleanProperty newProperty(@NotNull String path, boolean defaultValue) {
40
        return new BooleanProperty(path, defaultValue);
7✔
41
    }
42

43
    /**
44
     * Creates a new short property.
45
     *
46
     * @param path the property's path
47
     * @param defaultValue the default value
48
     * @return the created property
49
     */
50
    public static @NotNull ShortProperty newProperty(@NotNull String path, short defaultValue) {
51
        return new ShortProperty(path, defaultValue);
7✔
52
    }
53

54
    /**
55
     * Creates a new integer property.
56
     *
57
     * @param path the property's path
58
     * @param defaultValue the default value
59
     * @return the created property
60
     */
61
    public static @NotNull IntegerProperty newProperty(@NotNull String path, int defaultValue) {
62
        return new IntegerProperty(path, defaultValue);
7✔
63
    }
64

65
    /**
66
     * Creates a new long property.
67
     *
68
     * @param path the property's path
69
     * @param defaultValue the default value
70
     * @return the created property
71
     */
72
    public static @NotNull LongProperty newProperty(@NotNull String path, long defaultValue) {
73
        return new LongProperty(path, defaultValue);
7✔
74
    }
75

76
    /**
77
     * Creates a new float property.
78
     *
79
     * @param path the property's path
80
     * @param defaultValue the default value
81
     * @return the created property
82
     */
83
    public static @NotNull FloatProperty newProperty(@NotNull String path, float defaultValue) {
84
        return new FloatProperty(path, defaultValue);
6✔
85
    }
86

87
    /**
88
     * Creates a new double property.
89
     *
90
     * @param path the property's path
91
     * @param defaultValue the default value
92
     * @return the created property
93
     */
94
    public static @NotNull DoubleProperty newProperty(@NotNull String path, double defaultValue) {
95
        return new DoubleProperty(path, defaultValue);
6✔
96
    }
97

98
    /**
99
     * Creates a new String property.
100
     *
101
     * @param path the property's path
102
     * @param defaultValue the default value
103
     * @return the created property
104
     */
105
    public static @NotNull StringProperty newProperty(@NotNull String path, @NotNull String defaultValue) {
106
        return new StringProperty(path, defaultValue);
6✔
107
    }
108

109
    /**
110
     * Creates a new enum property.
111
     *
112
     * @param clazz the enum class
113
     * @param path the property's path
114
     * @param defaultValue the default value
115
     * @param <E> the enum type
116
     * @return the created enum property
117
     */
118
    public static <E extends Enum<E>> @NotNull EnumProperty<E> newProperty(@NotNull Class<E> clazz,
119
                                                                           @NotNull String path,
120
                                                                           @NotNull E defaultValue) {
121
        return new EnumProperty<>(clazz, path, defaultValue);
7✔
122
    }
123

124
    /**
125
     * Creates a new regex pattern property.
126
     *
127
     * @param path the property's path
128
     * @param defaultRegexValue the default pattern of the property
129
     * @return the created regex property
130
     */
131
    public static @NotNull RegexProperty newRegexProperty(@NotNull String path, @NotNull String defaultRegexValue) {
132
        return new RegexProperty(path, defaultRegexValue);
6✔
133
    }
134

135
    /**
136
     * Creates a new regex pattern property.
137
     *
138
     * @param path the property's path
139
     * @param defaultRegexValue the default pattern of the property
140
     * @return the created regex property
141
     */
142
    public static @NotNull RegexProperty newRegexProperty(@NotNull String path, @NotNull Pattern defaultRegexValue) {
143
        return new RegexProperty(path, defaultRegexValue);
6✔
144
    }
145

146
    /**
147
     * Creates a new String list property.
148
     *
149
     * @param path the property's path
150
     * @param defaultValues the items in the default list
151
     * @return the created list property
152
     */
153
    public static @NotNull StringListProperty newListProperty(@NotNull String path,
154
                                                              @NotNull String @NotNull ... defaultValues) {
155
        // does not have the same name as not to clash with #newProperty(String, String)
156
        return new StringListProperty(path, defaultValues);
6✔
157
    }
158

159
    /**
160
     * Creates a new String list property.
161
     *
162
     * @param path the property's path
163
     * @param defaultValues the default value of the property
164
     * @return the created list property
165
     */
166
    public static @NotNull StringListProperty newListProperty(@NotNull String path,
167
                                                              @NotNull List<String> defaultValues) {
168
        // does not have the same name as not to clash with #newProperty(String, String)
169
        return new StringListProperty(path, defaultValues);
6✔
170
    }
171

172
    /**
173
     * Creates a new String set property.
174
     *
175
     * @param path the property's path
176
     * @param defaultValues the items in the default set
177
     * @return the created set property
178
     */
179
    public static @NotNull StringSetProperty newSetProperty(@NotNull String path,
180
                                                            @NotNull String @NotNull ... defaultValues) {
181
        return new StringSetProperty(path, defaultValues);
6✔
182
    }
183

184
    /**
185
     * Creates a new String set property.
186
     *
187
     * @param path the property's path
188
     * @param defaultValues the default value of the property
189
     * @return the created set property
190
     */
191
    public static @NotNull StringSetProperty newSetProperty(@NotNull String path,
192
                                                            @NotNull Set<String> defaultValues) {
193
        return new StringSetProperty(path, defaultValues);
6✔
194
    }
195

196
    /**
197
     * Creates a new String set property where all values are lowercase.
198
     *
199
     * @param path the property's path
200
     * @param defaultValues the items in the default set
201
     * @return the created set property
202
     */
203
    public static @NotNull LowercaseStringSetProperty newLowercaseStringSetProperty(@NotNull String path,
204
                                                                           @NotNull String @NotNull ... defaultValues) {
205
        return new LowercaseStringSetProperty(path, defaultValues);
6✔
206
    }
207

208
    /**
209
     * Creates a new String set property where all values are lowercase.
210
     *
211
     * @param path the property's path
212
     * @param defaultValues the default value of the property
213
     * @return the created set property
214
     */
215
    public static @NotNull LowercaseStringSetProperty newLowercaseStringSetProperty(@NotNull String path,
216
                                                                            @NotNull Collection<String> defaultValues) {
217
        return new LowercaseStringSetProperty(path, defaultValues);
6✔
218
    }
219

220
    /**
221
     * Creates a new bean property.
222
     *
223
     * @param beanClass the JavaBean class
224
     * @param path the property's path
225
     * @param defaultValue default value
226
     * @param <B> the bean type
227
     * @return the created bean property
228
     */
229
    public static <B> @NotNull BeanProperty<B> newBeanProperty(@NotNull Class<B> beanClass, @NotNull String path,
230
                                                               @NotNull B defaultValue) {
231
        return new BeanProperty<>(beanClass, path, defaultValue);
7✔
232
    }
233

234
    // --------------
235
    // Property builders
236
    // --------------
237

238
    @NotNull
239
    public static <T> CollectionPropertyBuilder<T, List<T>, ListProperty<T>> listProperty(
240
                                                                                        @NotNull PropertyType<T> type) {
241
        return CollectionPropertyBuilder.listBuilder(type);
3✔
242
    }
243

244
    @NotNull
245
    public static <T> CollectionPropertyBuilder<T, Set<T>, SetProperty<T>> setProperty(@NotNull PropertyType<T> type) {
246
        return CollectionPropertyBuilder.setBuilder(type);
3✔
247
    }
248

249
    @NotNull
250
    public static <V> MapPropertyBuilder<V, Map<String, V>, MapProperty<V>> mapProperty(@NotNull PropertyType<V> type) {
251
        return MapPropertyBuilder.mapBuilder(type);
3✔
252
    }
253

254
    @NotNull
255
    public static <T> ArrayPropertyBuilder<T, ArrayProperty<T>> arrayProperty(@NotNull PropertyType<T> type,
256
                                                                              @NotNull IntFunction<T[]> arrayProducer) {
257
        return ArrayPropertyBuilder.arrayBuilder(type, arrayProducer);
4✔
258
    }
259

260
    @NotNull
261
    public static <T> ArrayPropertyBuilder<T, ArrayProperty<T>> arrayProperty(@NotNull ArrayPropertyType<T> arrayType) {
262
        return ArrayPropertyBuilder.arrayBuilder(arrayType);
×
263
    }
264

265
    @NotNull
266
    public static <E> ArrayPropertyBuilder<E, InlineArrayProperty<E>> inlineArrayProperty(
267
                                                                  @NotNull InlineArrayPropertyType<E> inlineArrayType) {
268
        return ArrayPropertyBuilder.inlineArrayBuilder(inlineArrayType);
3✔
269
    }
270

271
    // --------------
272
    // Optional flavors
273
    // --------------
274
    public static @NotNull OptionalProperty<Boolean> optionalBooleanProperty(@NotNull String path) {
275
        return new OptionalProperty<>(new BooleanProperty(path, false));
10✔
276
    }
277

278
    public static @NotNull OptionalProperty<Short> optionalShortProperty(@NotNull String path) {
279
        return new OptionalProperty<>(new ShortProperty(path, (short) 0));
10✔
280
    }
281

282
    public static @NotNull OptionalProperty<Integer> optionalIntegerProperty(@NotNull String path) {
283
        return new OptionalProperty<>(new IntegerProperty(path, 0));
10✔
284
    }
285

286
    public static @NotNull OptionalProperty<Long> optionalLongProperty(@NotNull String path) {
287
        return new OptionalProperty<>(new LongProperty(path, 0L));
10✔
288
    }
289

290
    public static @NotNull OptionalProperty<Float> optionalFloatProperty(@NotNull String path) {
291
        return new OptionalProperty<>(new FloatProperty(path, 0f));
9✔
292
    }
293

294
    public static @NotNull OptionalProperty<Double> optionalDoubleProperty(@NotNull String path) {
295
        return new OptionalProperty<>(new DoubleProperty(path, 0.0));
9✔
296
    }
297

298
    public static @NotNull OptionalProperty<String> optionalStringProperty(@NotNull String path) {
299
        return new OptionalProperty<>(new StringProperty(path, ""));
9✔
300
    }
301

302
    public static <E extends Enum<E>> @NotNull OptionalProperty<E> optionalEnumProperty(@NotNull Class<E> clazz,
303
                                                                                        @NotNull String path) {
304
        // default value may never be null, so get the first entry in the enum class
305
        return new OptionalProperty<>(new EnumProperty<>(clazz, path, clazz.getEnumConstants()[0]));
14✔
306
    }
307

308
    public static @NotNull OptionalProperty<Pattern> optionalRegexProperty(@NotNull String path) {
309
        return new OptionalProperty<>(new RegexProperty(path, ""));
9✔
310
    }
311

312
    public static @NotNull OptionalProperty<List<String>> optionalListProperty(@NotNull String path) {
313
        return new OptionalProperty<>(new StringListProperty(path));
10✔
314
    }
315

316
    public static @NotNull OptionalProperty<Set<String>> optionalSetProperty(@NotNull String path) {
317
        return new OptionalProperty<>(new StringSetProperty(path));
10✔
318
    }
319
}
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