1 package sun.misc; 2 3 /** 4 * An internal extension of CharSequence that guarantees it's 5 * {@link #length()} to be constant. The underlying characters can change 6 * concurrently only as a result of improper use of objects this object 7 * was derived from and were not intended for multi-thread use without 8 * proper synchronization. 9 */ 10 public interface ConstantLengthCharSequence extends CharSequence { 11 12 /** 13 * Returns a {@link ConstantLengthCharSequence} for given {@code charSequence}. 14 * If given {@code charSequence} is a {@link ConstantLengthCharSequence} then it 15 * returns the given instance itself. 16 * 17 * @return a {@link ConstantLengthCharSequence} for given {@code charSequence} 18 */ 19 static ConstantLengthCharSequence valueFor(CharSequence charSequence) { 20 if (charSequence instanceof ConstantLengthCharSequence) { 21 return (ConstantLengthCharSequence) charSequence; 22 } else { 23 return charSequence.toString(); 24 } 25 } 26 27 /** 28 * Copies characters from this {@code ConstantLengthCharSequence} into the 29 * destination character array. 30 * <p> 31 * The first character to be copied is at index {@code srcBegin}; 32 * the last character to be copied is at index {@code srcEnd-1} 33 * (thus the total number of characters to be copied is 34 * {@code srcEnd-srcBegin}). The characters are copied into the 35 * subarray of {@code dst} starting at index {@code dstBegin} 36 * and ending at index: 37 * <blockquote><pre> 38 * dstBegin + (srcEnd-srcBegin) - 1 39 * </pre></blockquote> 40 * 41 * @param srcBegin index of the first character in the sequence 42 * to copy. 43 * @param srcEnd index after the last character in the sequence 44 * to copy. 45 * @param dst the destination array. 46 * @param dstBegin the start offset in the destination array. 47 * @throws IndexOutOfBoundsException If any of the following 48 * is true: 49 * <ul><li>{@code srcBegin} is negative. 50 * <li>{@code srcBegin} is greater than 51 * {@code srcEnd} 52 * <li>{@code srcEnd} is greater than the 53 * length of this sequence 54 * <li>{@code dstBegin} is negative 55 * <li>{@code dstBegin+(srcEnd-srcBegin)} 56 * is larger than {@code dst.length}</ul> 57 */ 58 void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin); 59 }