introduce hudson.Util#fixNull(value, defaultValue)

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof committed 2018-09-28 13:59:14 +02:00
1 parent 9801bd961d
commit 179d597679
1 file changed
+12 -6
+12 -6
View File
@@ -1195,8 +1195,14 @@ public class Util {
*/
@Nonnull
public static String fixNull(@CheckForNull String s) {
if(s==null) return "";
else return s;
return fixNull(s, "");
}
/**
* Convert null to defaultValue.
*/
public static <T> T fixNull(@CheckForNull T s, T defaultValue) {
return s != null ? s : defaultValue;
}
/**
@@ -1221,22 +1227,22 @@ public class Util {
@Nonnull
public static <T> List<T> fixNull(@CheckForNull List<T> l) {
return l!=null ? l : Collections.<T>emptyList();
return fixNull(l, Collections.<T>emptyList());
}
@Nonnull
public static <T> Set<T> fixNull(@CheckForNull Set<T> l) {
return l!=null ? l : Collections.<T>emptySet();
return fixNull(l, Collections.<T>emptySet());
}
@Nonnull
public static <T> Collection<T> fixNull(@CheckForNull Collection<T> l) {
return l!=null ? l : Collections.<T>emptySet();
return fixNull(l, Collections.<T>emptySet());
}
@Nonnull
public static <T> Iterable<T> fixNull(@CheckForNull Iterable<T> l) {
return l!=null ? l : Collections.<T>emptySet();
return fixNull(l, Collections.<T>emptySet());
}
/**