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

Add rotate(string, int) method to StringUtils

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.5
    • lang.*
    • None

    Description

      Add a method to rotate (circular shift) a String into StringUtils.

      /**
       * <p>Rotate (circular shift) a String of {@code shift} characters.</p>
       * <ul>
       *  <li>If {@code shift > 0}, right circular shift (ex : ABCDEF =&gt; FABCDE)</li>
       *  <li>If {@code shift < 0}, left circular shift (ex : ABCDEF =&gt; BCDEFA)</li>
       * </ul>
       *
       * <pre>
       * StringUtils.rotate(null, *)        = null
       * StringUtils.rotate("", *)          = ""
       * StringUtils.rotate("abcdefg", 0)   = "abcdefg"
       * StringUtils.rotate("abcdefg", 2)   = "fgabcde"
       * StringUtils.rotate("abcdefg", -2)  = "cdefgab"
       * StringUtils.rotate("abcdefg", 7)   = "abcdefg"
       * StringUtils.rotate("abcdefg", -7)  = "abcdefg"
       * StringUtils.rotate("abcdefg", 9)   = "fgabcde"
       * StringUtils.rotate("abcdefg", -9)  = "cdefgab"
       * </pre>
       *
       * @param str  the String to rotate, may be null
       * @param shift  number of time to shift (positive : right shift, negative : left shift)
       * @return the rotated String,
       *          or the original String if {@code shift == 0},
       *          or {@code null} if null String input
       */
      public static String rotate(String str, int shift);
      

      See PR #71 : https://github.com/apache/commons-lang/pull/71

      Attachments

        Activity

          People

            britter Benedikt Ritter
            rikles Loic Guibert
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: