Package org.grails.charsequences
Class CharSequences
- java.lang.Object
-
- org.grails.charsequences.CharSequences
-
public class CharSequences extends java.lang.ObjectUtility 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 booleancanUseOriginalForSubSequence(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.CharSequencecreateCharSequence(char[] chars)static java.lang.CharSequencecreateCharSequence(char[] chars, int start, int count)static java.lang.CharSequencecreateCharSequence(java.lang.CharSequence str, int start, int count)static java.lang.CharSequencecreateSingleCharSequence(char ch)static java.lang.CharSequencecreateSingleCharSequence(int c)static voidgetChars(java.lang.CharSequence csq, int srcBegin, int srcEnd, char[] dst, int dstBegin)Provides an optimized way to copy CharSequence content to target array.static voidwriteCharSequence(java.io.Writer target, java.lang.CharSequence csq)static voidwriteCharSequence(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
-
-
-
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 inputstart- start indexcount- 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.IOExceptionWrites a CharSequence instance in the most optimal way to the target writer- Parameters:
target- writercsq- source CharSequence instancestart- start/offset indexend- 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 sequencecsqinto the destination character arraydst. The first character to be copied is at indexsrcBegin; the last character to be copied is at indexsrcEnd-1. The total number of characters to be copied issrcEnd-srcBegin. The characters are copied into the subarray ofdststarting at indexdstBeginand 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 intodst.- Throws:
java.lang.NullPointerException- ifdstisnull.java.lang.IndexOutOfBoundsException- if any of the following is true:srcBeginis negativedstBeginis negative- the
srcBeginargument is greater than thesrcEndargument. srcEndis greater thanthis.length().dstBegin+srcEnd-srcBeginis greater thandst.length
-
-