
net.intelie.liverig.plugin.util.MapUtils Maven / Gradle / Ivy
The newest version!
package net.intelie.liverig.plugin.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class MapUtils {
@Nullable
public static String getString(@NotNull Map, ?> map, @NotNull String key) {
Object value = map.get(key);
return value instanceof String ? (String) value : null;
}
@Nullable
public static String getAsString(@NotNull Map, ?> map, @NotNull String key) {
Object value = map.get(key);
return value == null ? null : value.toString();
}
@Nullable
public static Boolean getBoolean(@NotNull Map, ?> map, @NotNull String key) {
Object value = map.get(key);
return value == null ? null : Boolean.valueOf(value.toString());
}
public static Double getDouble(@NotNull Map, ?> map, @NotNull String key) {
Object value = map.get(key);
return value == null ? null : Double.valueOf(value.toString());
}
public static Long getLong(@NotNull Map, ?> map, @NotNull String key) {
Object value = map.get(key);
return value == null ? null : Long.valueOf(value.toString());
}
public static Integer getInteger(@NotNull Map, ?> map, @NotNull String key) {
Object value = map.get(key);
return value == null ? null : Integer.valueOf(value.toString());
}
@NotNull
public static List> getListOrEmpty(@NotNull Map, ?> map, @NotNull String key) {
Object value = map.get(key);
return value instanceof List ? (List>) value : Collections.emptyList();
}
@NotNull
public static Map, ?> getMapOrValue(@NotNull Map, ?> map, @NotNull String key) {
Object value = map.get(key);
return value instanceof Map ? (Map, ?>) value : value != null ? Collections.singletonMap("value", value) : Collections.emptyMap();
}
@NotNull
public static Map, ?> getMapOrEmpty(Map, ?> map, String key) {
Object value = map.get(key);
return value instanceof Map ? (Map, ?>) value : Collections.emptyMap();
}
@Nullable
public static Map, ?> getMap(Map, ?> map, String key) {
Object value = map.get(key);
return value instanceof Map ? (Map, ?>) value : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy