Make Strings more like Options.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2558 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2009-05-26 22:21:21 +00:00
parent b759dcad7d
commit 933c486986
@@ -121,6 +121,14 @@ public class StringUtil
return truncate(s, maxLength, "");
}
/**
* Returns the string if it is non-blank (see {@link #isBlank}), the default value otherwise.
*/
public static String getOr (String value, String defval)
{
return isBlank(value) ? defval : value;
}
/**
* Truncate the specified String if it is longer than maxLength. The string will be truncated
* at a position such that it is maxLength chars long after the addition of the 'append'