Adds Enum support to YamlConfiguration class (#41)
This commit is contained in:
parent
8f15df3601
commit
41bd5c633a
|
@ -117,6 +117,8 @@ public class YamlConfiguration implements IConfiguration, HeaderCommentable, Nod
|
||||||
value = ((Float) value).doubleValue();
|
value = ((Float) value).doubleValue();
|
||||||
} else if (value instanceof Character) {
|
} else if (value instanceof Character) {
|
||||||
value = ((Character) value).toString();
|
value = ((Character) value).toString();
|
||||||
|
} else if (value.getClass().isEnum()) {
|
||||||
|
value = ((Enum<?>) value).name();
|
||||||
} else if (value.getClass().isArray()) {
|
} else if (value.getClass().isArray()) {
|
||||||
if (value instanceof int[]) {
|
if (value instanceof int[]) {
|
||||||
value = Arrays.asList(ArrayUtils.toObject((int[]) value));
|
value = Arrays.asList(ArrayUtils.toObject((int[]) value));
|
||||||
|
|
|
@ -289,6 +289,16 @@ class YamlConfigurationTest {
|
||||||
assertEquals(3, primitivesList.get(2));
|
assertEquals(3, primitivesList.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSetterWithEnumValue() {
|
||||||
|
final YamlConfiguration cfg = new YamlConfiguration();
|
||||||
|
|
||||||
|
assertNull(cfg.set("primitives.enum", TestEnum.ENUM_VALUE));
|
||||||
|
|
||||||
|
assertInstanceOf(String.class, cfg.get("primitives.enum"));
|
||||||
|
assertEquals(TestEnum.ENUM_VALUE, TestEnum.valueOf((String) cfg.get("primitives.enum")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSetterWithBooleanArrayValue() {
|
void testSetterWithBooleanArrayValue() {
|
||||||
final YamlConfiguration cfg = new YamlConfiguration();
|
final YamlConfiguration cfg = new YamlConfiguration();
|
||||||
|
@ -566,4 +576,13 @@ class YamlConfigurationTest {
|
||||||
|
|
||||||
assertEquals(expectedYaml, cfg.toYamlString());
|
assertEquals(expectedYaml, cfg.toYamlString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum TestEnum {
|
||||||
|
ENUM_VALUE;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "#toString(): " + super.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue