io.soffa.foundation.commons.MapUtil Maven / Gradle / Ivy
The newest version!
package io.soffa.foundation.commons;
import java.util.HashMap;
import java.util.Map;
public final class MapUtil {
private MapUtil() {
}
public static Map create(Object... args) {
if (args.length % 2 != 0) {
throw new IllegalArgumentException("MapUtil.create() requires an even number of arguments");
}
Map result = new HashMap<>();
for (int i = 0; i < args.length; i += 2) {
if (!(args[i] instanceof String)) {
throw new IllegalArgumentException("MapUtil.create() requires String keys");
}
result.put(args[i].toString(), args[i + 1]);
}
return result;
}
public static boolean isEmpty(Map tags) {
return tags==null || tags.isEmpty();
}
public static boolean isNotEmpty(Map tags) {
return !isEmpty(tags);
}
}