Class CharSequences


  • public class CharSequences
    extends java.lang.Object
    Utility functions for handling java.lang.CharSequence instances
    Since:
    2.3.10
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean canUseOriginalForSubSequence​(java.lang.CharSequence str, int start, int count)
      Checks if start == 0 and count == length of CharSequence It does this check only for String, StringBuilder and StringBuffer classes which have a fast way to check length Calculating length on GStringImpl requires building the result which is costly.
      static java.lang.CharSequence createCharSequence​(char[] chars)  
      static java.lang.CharSequence createCharSequence​(char[] chars, int start, int count)  
      static java.lang.CharSequence createCharSequence​(java.lang.CharSequence str, int start, int count)  
      static java.lang.CharSequence createSingleCharSequence​(char ch)  
      static java.lang.CharSequence createSingleCharSequence​(int c)  
      static void getChars​(java.lang.CharSequence csq, int srcBegin, int srcEnd, char[] dst, int dstBegin)
      Provides an optimized way to copy CharSequence content to target array.
      static void writeCharSequence​(java.io.Writer target, java.lang.CharSequence csq)  
      static void writeCharSequence​(java.io.Writer target, java.lang.CharSequence csq, int start, int end)
      Writes a CharSequence instance in the most optimal way to the target writer
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createCharSequence

        public static java.lang.CharSequence createCharSequence​(char[] chars)
      • createCharSequence

        public static java.lang.CharSequence createCharSequence​(char[] chars,
                                                                int start,
                                                                int count)
      • createCharSequence

        public static java.lang.CharSequence createCharSequence​(java.lang.CharSequence str,
                                                                int start,
                                                                int count)
      • canUseOriginalForSubSequence

        public static boolean canUseOriginalForSubSequence​(java.lang.CharSequence str,
                                                           int start,
                                                           int count)
        Checks if start == 0 and count == length of CharSequence It does this check only for String, StringBuilder and StringBuffer classes which have a fast way to check length Calculating length on GStringImpl requires building the result which is costly. This helper method is to avoid calling length on other that String, StringBuilder and StringBuffer classes when checking if the input CharSequence instance is already the same as the requested sub sequence
        Parameters:
        str - CharSequence input
        start - start index
        count - length on sub sequence
        Returns:
        true if input is String, StringBuilder or StringBuffer class, start is 0 and count is length of input sequence
      • createSingleCharSequence

        public static java.lang.CharSequence createSingleCharSequence​(int c)
      • createSingleCharSequence

        public static java.lang.CharSequence createSingleCharSequence​(char ch)
      • writeCharSequence

        public static void writeCharSequence​(java.io.Writer target,
                                             java.lang.CharSequence csq,
                                             int start,
                                             int end)
                                      throws java.io.IOException
        Writes a CharSequence instance in the most optimal way to the target writer
        Parameters:
        target - writer
        csq - source CharSequence instance
        start - start/offset index
        end - end index + 1
        Throws:
        java.io.IOException
      • writeCharSequence

        public static void writeCharSequence​(java.io.Writer target,
                                             java.lang.CharSequence csq)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • getChars

        public static void getChars​(java.lang.CharSequence csq,
                                    int srcBegin,
                                    int srcEnd,
                                    char[] dst,
                                    int dstBegin)
        Provides an optimized way to copy CharSequence content to target array. Uses getChars method available on String, StringBuilder and StringBuffer classes. Characters are copied from the source sequence csq into the destination character array dst. The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The total number of characters to be copied is srcEnd-srcBegin. The characters are copied into the subarray of dst starting at index dstBegin and ending at index:

         dstbegin + (srcEnd-srcBegin) - 1
         
        Parameters:
        csq - the source CharSequence instance.
        srcBegin - start copying at this offset.
        srcEnd - stop copying at this offset.
        dst - the array to copy the data into.
        dstBegin - offset into dst.
        Throws:
        java.lang.NullPointerException - if dst is null.
        java.lang.IndexOutOfBoundsException - if any of the following is true:
        • srcBegin is negative
        • dstBegin is negative
        • the srcBegin argument is greater than the srcEnd argument.
        • srcEnd is greater than this.length().
        • dstBegin+srcEnd-srcBegin is greater than dst.length