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

AuthMe / ConfigMe / 6022426951

30 Aug 2023 08:26AM UTC coverage: 97.279% (+3.7%) from 93.592%
6022426951

push

github

ljacqu
Draft: collection property types (3)

528 of 546 branches covered (0.0%)

45 of 45 new or added lines in 12 files covered. (100.0%)

1466 of 1507 relevant lines covered (97.28%)

4.44 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.InlineArrayPropertyBuilder;
6
import ch.jalu.configme.properties.builder.MapPropertyBuilder;
7
import ch.jalu.configme.properties.types.ArrayPropertyType;
8
import ch.jalu.configme.properties.types.InlineArrayPropertyType;
9
import ch.jalu.configme.properties.types.PropertyType;
10
import org.jetbrains.annotations.NotNull;
11

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

235
    // --------------
236
    // Property builders
237
    // --------------
238

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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