Skip to content

Commit 443d9af

Browse files
Add additional convenience methods
1 parent b189184 commit 443d9af

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

core/src/main/java/io/github/almightysatan/jaskl/entries/CustomConfigEntry.java

+12
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ class CustomConfigEntryImpl extends WritableConfigEntryImpl<T> implements Custom
4343
static <T> @NotNull CustomConfigEntry<T> of(@NotNull Config config, @NotNull String path, @NotNull T defaultValue, @NotNull Class<T> clazz, @NotNull Validator<T>... validators) throws InvalidTypeException, ValidationException {
4444
return of(config, path, null, defaultValue, clazz, validators);
4545
}
46+
47+
@SuppressWarnings("unchecked")
48+
@SafeVarargs
49+
static <T> @NotNull CustomConfigEntry<T> of(@NotNull Config config, @NotNull String path, @Nullable String description, @NotNull T defaultValue, @NotNull Validator<T>... validators) throws InvalidTypeException, ValidationException {
50+
return of(config, path, description, defaultValue, (Class<T>) defaultValue.getClass(), validators);
51+
}
52+
53+
@SuppressWarnings("unchecked")
54+
@SafeVarargs
55+
static <T> @NotNull CustomConfigEntry<T> of(@NotNull Config config, @NotNull String path, @NotNull T defaultValue, @NotNull Validator<T>... validators) throws InvalidTypeException, ValidationException {
56+
return of(config, path, defaultValue, (Class<T>) defaultValue.getClass(), validators);
57+
}
4658
}

core/src/testFixtures/java/io/github/almightysatan/jaskl/test/ConfigTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ public static void testCustom(Supplier<Config> configSupplier) throws IOExceptio
450450
config0.close();
451451

452452
Config config1 = configSupplier.get();
453-
ConfigEntry<ExampleCustomObject> entry2 = CustomConfigEntry.of(config1, "example.custom", "Hello World", new ExampleCustomObject("Default1", 6, ExampleEnum.ANOTHER_EXAMPLE), ExampleCustomObject.class);
454-
ConfigEntry<ExampleNestedCustomObject> entry3 = CustomConfigEntry.of(config1, "example.nestedCustom", "Hello World", new ExampleNestedCustomObject(new ExampleCustomObject("Default1", 6, ExampleEnum.ANOTHER_EXAMPLE)), ExampleNestedCustomObject.class);
453+
ConfigEntry<ExampleCustomObject> entry2 = CustomConfigEntry.of(config1, "example.custom", "Hello World", new ExampleCustomObject("Default1", 6, ExampleEnum.ANOTHER_EXAMPLE));
454+
ConfigEntry<ExampleNestedCustomObject> entry3 = CustomConfigEntry.of(config1, "example.nestedCustom", "Hello World", new ExampleNestedCustomObject(new ExampleCustomObject("Default1", 6, ExampleEnum.ANOTHER_EXAMPLE)));
455455

456456
Assertions.assertThrows(InvalidAnnotationConfigException.class, () -> CustomConfigEntry.of(config1, "example.nestedCustom", new ExampleCircularCustomObject(), ExampleCircularCustomObject.class));
457457

0 commit comments

Comments
 (0)