Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-974

New StringUtils Method defaultIfNotIn(String, String, String ...)

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 3.2.1
    • None
    • lang.*
    • None

    Description

      Example use case:
      If a Method expects values that should only consist of a certain set such as "0" and "1", and any Invalid String should be defaulted to "0".

      Possible Solution:

        public static String defaultIfNotIn(final String str, final String defaultString, String... validStrings) {
          if (str == null) {
            return defaultString;
          }
          for (final String validString : validStrings) {
            if (validString.equals(str)) {
              return str;
            }
          }
          return defaultString;
        }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            sknitelius Stephan Knitelius
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: