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

StrBuilder appendSeparator with defaultIfEmpty

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4
    • 2.5
    • lang.text.*
    • None

    Description

      If would like to suggest the following method for the StrBuilder class:

      appendSeparator(String separator, String defaultIfEmpty)

      it's usage is very handy for building queries (a much more I guess)

      StrBuilder whereClause = new StrBuilder();
      if(searchCommand.priority != null) {
        whereClause.appendSeparator(" and", " where");
        whereClause.append(" priority = ?")
      }
      if(searchCommand.component != null) {
        whereClause.appendSeparator(" and", " where");
        whereClause.append(" component = ?")
      }
      
      // if(!whereClause.isEmpty()) {
      // selectClause.append(" where")
      // selectClause.append(whereClause)
      //}
      selectClause.append(whereClause)
      
      

      this can be done for every queryClause (eliminating all isEmpty-checks), but there are usefull usecases

      Attachments

        1. LANG-422-RS.patch
          6 kB
          Robert Scholte

        Activity

          People

            Unassigned Unassigned
            rfscholte-getthere Robert Scholte
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: