com.github.restup.util.UpUtils Maven / Gradle / Ivy
package com.github.restup.util;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;
import com.github.restup.path.ResourcePath;
import com.google.common.collect.Iterables;
public class UpUtils {
private UpUtils() {
}
/**
* Null safe unmodifiable list returning empty list for null.
*
* @param type of elements in the list
* @param list to make unmodifiable
* @return unmodifiable list, never null
*/
public static List unmodifiableList(List list) {
return list == null ? Collections.emptyList() : Collections.unmodifiableList(list);
}
public static Map unmodifiableMap(Map map) {
return map == null ? Collections.emptyMap() : Collections.unmodifiableMap(map);
}
public static void removeAll(List target, List source) {
if (source != null) {
target.removeAll(source);
}
}
public static void addAll(List target, List source) {
if (source != null) {
target.addAll(source);
}
}
public static T getFirst(Iterable it) {
return getFirst(it, null);
}
public static T getFirst(Iterable it, T defaultValue) {
return it == null ? defaultValue : Iterables.getFirst(it, defaultValue);
}
public static void put(Map map, String name, String value) {
String[] arr = map.get(name);
if (arr == null) {
map.put(name, new String[]{value});
} else {
map.put(name, ArrayUtils.add(arr, value));
}
}
public static T nvl(T a, T b) {
return a == null ? b : a;
}
}