introduce hudson.Util#fixNull(value, defaultValue)
@@ -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());
}
/**
