Rename IConfiguration#getOrDefault to #getOr

This commit is contained in:
Christian Koop 2022-06-26 01:38:50 +02:00
parent 41bd5c633a
commit f6e207cdda
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
3 changed files with 6 additions and 10 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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