diff --git a/src/main/java/com/beust/jcommander/ParameterDescription.java b/src/main/java/com/beust/jcommander/ParameterDescription.java index 87e66804..fea4ba42 100644 --- a/src/main/java/com/beust/jcommander/ParameterDescription.java +++ b/src/main/java/com/beust/jcommander/ParameterDescription.java @@ -21,6 +21,8 @@ import com.beust.jcommander.validators.NoValidator; import com.beust.jcommander.validators.NoValueValidator; +import static com.beust.jcommander.Strings.isStringEmpty; + import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.*; @@ -74,12 +76,12 @@ private ResourceBundle findResourceBundle(Object o) { ResourceBundle result = null; Parameters p = o.getClass().getAnnotation(Parameters.class); - if (p != null && ! isEmpty(p.resourceBundle())) { + if (p != null && ! isStringEmpty(p.resourceBundle())) { result = ResourceBundle.getBundle(p.resourceBundle(), Locale.getDefault()); } else { com.beust.jcommander.ResourceBundle a = o.getClass().getAnnotation( com.beust.jcommander.ResourceBundle.class); - if (a != null && ! isEmpty(a.value())) { + if (a != null && ! isStringEmpty(a.value())) { result = ResourceBundle.getBundle(a.value(), Locale.getDefault()); } } @@ -87,13 +89,9 @@ private ResourceBundle findResourceBundle(Object o) { return result; } - private boolean isEmpty(String s) { - return s == null || "".equals(s); - } - private void initDescription(String description, String descriptionKey, String[] names) { this.description = description; - if (! "".equals(descriptionKey)) { + if (! isStringEmpty(descriptionKey)) { if (bundle != null) { this.description = bundle.getString(descriptionKey); } diff --git a/src/main/java/com/beust/jcommander/Strings.java b/src/main/java/com/beust/jcommander/Strings.java index a0b22b89..f0e2e80f 100644 --- a/src/main/java/com/beust/jcommander/Strings.java +++ b/src/main/java/com/beust/jcommander/Strings.java @@ -5,7 +5,7 @@ public class Strings { public static boolean isStringEmpty(String s) { - return s == null || "".equals(s); + return s == null || s.isEmpty(); } public static boolean startsWith(String s, String with, boolean isCaseSensitive) { diff --git a/src/main/java/com/beust/jcommander/UnixStyleUsageFormatter.java b/src/main/java/com/beust/jcommander/UnixStyleUsageFormatter.java index 75921547..946ff367 100644 --- a/src/main/java/com/beust/jcommander/UnixStyleUsageFormatter.java +++ b/src/main/java/com/beust/jcommander/UnixStyleUsageFormatter.java @@ -77,13 +77,13 @@ public void appendAllParametersDetails(StringBuilder out, int indentCount, Strin if (pd.isDynamicParameter()) { String syntax = "(syntax: " + parameter.names()[0] + "key" + parameter.getAssignment() + "value)"; - description += (description.length() == 0 ? "" : " ") + syntax; + description += (description.isEmpty() ? "" : " ") + syntax; } if (def != null && !pd.isHelp()) { String displayedDef = Strings.isStringEmpty(def.toString()) ? "" : def.toString(); String defaultText = "(default: " + (parameter.password() ? "********" : displayedDef) + ")"; - description += (description.length() == 0 ? "" : " ") + defaultText; + description += (description.isEmpty() ? "" : " ") + defaultText; } Class type = pd.getParameterized().getType(); @@ -94,7 +94,7 @@ public void appendAllParametersDetails(StringBuilder out, int indentCount, Strin // of an enum field is empty in ParameterDescription#init(..) if (!description.contains("Options: " + valueList)) { String possibleValues = "(values: " + valueList + ")"; - description += (description.length() == 0 ? "" : " ") + possibleValues; + description += (description.isEmpty() ? "" : " ") + possibleValues; } }