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

StringUtils.same opposite method to StringUtils.differ

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Won't Fix
    • 3.3.2
    • None
    • None

    Description

      This is pretty easy to do but I have seen this come up and was surprised to find that StringUtils didn't have a utility method.

      The difference() method is described as doing the following:
      Compares two Strings, and returns the portion where they differ.

      What I am proposing is essentially the opposite of the difference method called same(). This method would compare two String and return a new String when they are the same.

      This is essentially the implementation:

          public static String same(String str1, String str2) {
              if (str1 != null && StringUtils.equalsIgnoreCase(str1, str2)) {
                  return new String(str1);
              }
              return null;
          }
      
      StringUtils.same(null, null) = null
      StringUtils.same("", "") = "";
      StringUtils.same("123", "") = null
      StringUtils.same("123", "123") = "123";
      

      If there is already a way to do this using the apache lang library please point me in the right direction. Otherwise I would be more than happy to do the testing, coding and documentation for this.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            mbazos Michael Bazos
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment