Created ValueGetter interface

This commit is contained in:
Auxilor 2020-12-28 12:47:51 +00:00
parent 8c2eddd2b2
commit 40f237317e
2 changed files with 98 additions and 2 deletions

View File

@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
public abstract class BaseConfig extends PluginDependent {
public abstract class BaseConfig extends PluginDependent implements ValueGetter {
/**
* The linked {@link YamlConfiguration} where values are physically stored.
*/
@ -115,6 +115,7 @@ public abstract class BaseConfig extends PluginDependent {
* @param path The key to fetch the value from.
* @return The found value, or 0 if not found.
*/
@Override
public int getInt(@NotNull final String path) {
return config.getInt(path, 0);
}
@ -126,6 +127,7 @@ public abstract class BaseConfig extends PluginDependent {
* @param def The value to default to if not found.
* @return The found value, or the default.
*/
@Override
public int getInt(@NotNull final String path,
final int def) {
return config.getInt(path, def);
@ -137,6 +139,7 @@ public abstract class BaseConfig extends PluginDependent {
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@Override
@NotNull
public List<Integer> getInts(@NotNull final String path) {
return config.getIntegerList(path);
@ -148,6 +151,7 @@ public abstract class BaseConfig extends PluginDependent {
* @param path The key to fetch the value from.
* @return The found value, or false if not found.
*/
@Override
public boolean getBool(@NotNull final String path) {
return config.getBoolean(path, false);
}
@ -158,17 +162,19 @@ public abstract class BaseConfig extends PluginDependent {
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@Override
@NotNull
public List<Boolean> getBools(@NotNull final String path) {
return config.getBooleanList(path);
}
/**
* Get a string from config.
* Get a string from config.C
*
* @param path The key to fetch the value from.
* @return The found value, or an empty string if not found.
*/
@Override
@NotNull
public String getString(@NotNull final String path) {
return Objects.requireNonNull(config.getString(path, ""));
@ -180,6 +186,7 @@ public abstract class BaseConfig extends PluginDependent {
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@Override
@NotNull
public List<String> getStrings(@NotNull final String path) {
return config.getStringList(path);
@ -191,6 +198,7 @@ public abstract class BaseConfig extends PluginDependent {
* @param path The key to fetch the value from.
* @return The found value, or 0 if not found.
*/
@Override
public double getDouble(@NotNull final String path) {
return config.getDouble(path, 0);
}
@ -201,6 +209,7 @@ public abstract class BaseConfig extends PluginDependent {
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@Override
@NotNull
public List<Double> getDoubles(@NotNull final String path) {
return config.getDoubleList(path);

View File

@ -0,0 +1,87 @@
package com.willfp.eco.util.config;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface ValueGetter {
/**
* Get an integer from config.
*
* @param path The key to fetch the value from.
* @return The found value, or 0 if not found.
*/
int getInt(@NotNull String path);
/**
* Get an integer from config with a specified default (not found) value.
*
* @param path The key to fetch the value from.
* @param def The value to default to if not found.
* @return The found value, or the default.
*/
int getInt(@NotNull String path,
int def);
/**
* Get a list of integers from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<Integer> getInts(@NotNull String path);
/**
* Get a boolean from config.
*
* @param path The key to fetch the value from.
* @return The found value, or false if not found.
*/
boolean getBool(@NotNull String path);
/**
* Get a list of booleans from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<Boolean> getBools(@NotNull String path);
/**
* Get a string from config.
*
* @param path The key to fetch the value from.
* @return The found value, or an empty string if not found.
*/
@NotNull
String getString(@NotNull String path);
/**
* Get a list of strings from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<String> getStrings(@NotNull String path);
/**
* Get a decimal from config.
*
* @param path The key to fetch the value from.
* @return The found value, or 0 if not found.
*/
double getDouble(@NotNull String path);
/**
* Get a list of decimals from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<Double> getDoubles(@NotNull String path);
}