mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 10:35:18 +01:00
Rename IConfiguration#getOrDefault
to #getOr
This commit is contained in:
parent
41bd5c633a
commit
f6e207cdda
@ -3,10 +3,6 @@ package com.songoda.core.configuration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
@ -34,7 +30,7 @@ public interface IConfiguration {
|
||||
* but returns the given default value if the key doesn't exist or the value is null.
|
||||
*/
|
||||
@Nullable
|
||||
Object getOrDefault(String key, @Nullable Object defaultValue);
|
||||
Object getOr(String key, @Nullable Object defaultValue);
|
||||
|
||||
/**
|
||||
* This method sets a given key to a given value in memory.
|
||||
|
@ -84,7 +84,7 @@ public class YamlConfiguration implements IConfiguration, HeaderCommentable, Nod
|
||||
|
||||
@Override
|
||||
@Contract(pure = true, value = "null,_ -> param2")
|
||||
public @Nullable Object getOrDefault(String key, @Nullable Object defaultValue) {
|
||||
public @Nullable Object getOr(String key, @Nullable Object defaultValue) {
|
||||
Object value = get(key);
|
||||
|
||||
return value == null ? defaultValue : value;
|
||||
|
@ -245,11 +245,11 @@ class YamlConfigurationTest {
|
||||
assertEquals("bar", cfg.set("foo", "bar"));
|
||||
assertNull(cfg.set("bar.baz", "foz"));
|
||||
|
||||
assertEquals("bar", cfg.getOrDefault("foo", "baz"));
|
||||
assertEquals("foz", cfg.getOrDefault("bar.baz", "baz"));
|
||||
assertEquals("bar", cfg.getOr("foo", "baz"));
|
||||
assertEquals("foz", cfg.getOr("bar.baz", "baz"));
|
||||
|
||||
assertEquals("default", cfg.getOrDefault("foo.bar", "default"));
|
||||
assertEquals("default", cfg.getOrDefault("bar.baz.foo", "default"));
|
||||
assertEquals("default", cfg.getOr("foo.bar", "default"));
|
||||
assertEquals("default", cfg.getOr("bar.baz.foo", "default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user