Adds getter to ConfigEntry for List<String>
This commit is contained in:
parent
da3c89450e
commit
3a09c19dbb
|
@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -195,6 +196,22 @@ public class ConfigEntry {
|
||||||
return Boolean.parseBoolean(value);
|
return Boolean.parseBoolean(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable List<String> getStringList() {
|
||||||
|
return getStringList(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("!null -> !null")
|
||||||
|
public @Nullable List<String> getStringList(List<String> fallbackValue) {
|
||||||
|
Object value = get();
|
||||||
|
|
||||||
|
if (value instanceof List) {
|
||||||
|
//noinspection unchecked
|
||||||
|
return (List<String>) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallbackValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #getMaterial(CompatibleMaterial)
|
* @see #getMaterial(CompatibleMaterial)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,11 +4,15 @@ import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@ -133,6 +137,26 @@ class ConfigEntryTest {
|
||||||
assertTrue(entry.getBoolean(true));
|
assertTrue(entry.getBoolean(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetStringList() {
|
||||||
|
SongodaYamlConfig cfg = new SongodaYamlConfig(new File("ConfigEntryTest.yml"));
|
||||||
|
ConfigEntry entry = new ConfigEntry(cfg, "key");
|
||||||
|
|
||||||
|
final List<String> fallbackValue = Collections.unmodifiableList(new LinkedList<>());
|
||||||
|
|
||||||
|
entry.set(null);
|
||||||
|
assertNull(entry.getStringList());
|
||||||
|
assertSame(fallbackValue, entry.getStringList(fallbackValue));
|
||||||
|
|
||||||
|
entry.set(Collections.singletonList("value"));
|
||||||
|
assertEquals(Collections.singletonList("value"), entry.getStringList());
|
||||||
|
|
||||||
|
entry.set(new String[] {"value2"});
|
||||||
|
assertEquals(Collections.singletonList("value2"), entry.getStringList());
|
||||||
|
|
||||||
|
entry.set("string-value");
|
||||||
|
assertNull(entry.getStringList());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetMaterial() {
|
void testGetMaterial() {
|
||||||
|
|
Loading…
Reference in New Issue