From 933c486986fbc34dd54099b58d5d96b7eb5ad95d Mon Sep 17 00:00:00 2001 From: samskivert Date: Tue, 26 May 2009 22:21:21 +0000 Subject: [PATCH] Make Strings more like Options. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2558 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/util/StringUtil.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/java/com/samskivert/util/StringUtil.java b/src/java/com/samskivert/util/StringUtil.java index 7733bb8c..fd8017bb 100644 --- a/src/java/com/samskivert/util/StringUtil.java +++ b/src/java/com/samskivert/util/StringUtil.java @@ -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'