xyz.snaker.snakerlib.utility.Checks Maven / Gradle / Ivy
package xyz.snaker.snakerlib.utility;
import java.util.Map;
/**
* Created by SnakerBone on 2/09/2023
**/
public class Checks
{
public static K checkKeyExists(Map map, K key)
{
if (!map.containsKey(key)) {
throw new RuntimeException(String.format("Key '%s' not present in map", key));
}
return key;
}
public static K checkKeyExists(Map map, K key, String errorMessage)
{
if (!map.containsKey(key)) {
throw new RuntimeException(errorMessage);
}
return key;
}
public static K checkKeyExists(Map map, K key, String errorTemplate, Object... args)
{
if (!map.containsKey(key)) {
throw new RuntimeException(String.format(errorTemplate, args));
}
return key;
}
public static V checkValueExists(Map map, V value)
{
if (!map.containsValue(value)) {
throw new RuntimeException(String.format("Value '%s' not present in map", value));
}
return value;
}
public static V checkValueExists(Map map, V value, String errorMessage)
{
if (!map.containsValue(value)) {
throw new RuntimeException(errorMessage);
}
return value;
}
public static V checkValueExists(Map map, V value, String errorTemplate, Object... args)
{
if (!map.containsValue(value)) {
throw new RuntimeException(String.format(errorTemplate, args));
}
return value;
}
public static K checkValueExistsFromKey(Map map, K key)
{
if (map.get(key) == null) {
throw new RuntimeException(String.format("Value '%s' not present in map", key));
}
return key;
}
public static K checkValueExistsFromKey(Map map, K key, String errorMessage)
{
if (map.get(key) == null) {
throw new RuntimeException(errorMessage);
}
return key;
}
public static K checkValueExistsFromKey(Map map, K key, String errorTemplate, Object... args)
{
if (map.get(key) == null) {
throw new RuntimeException(String.format(errorTemplate, args));
}
return key;
}
}