Add getChars to CharSequence

Martin Buchholz martinrb at google.com
Thu Apr 11 20:37:05 UTC 2013


Alan, please file an rfe for us: Add default methods CharSequence.getChars
to match String and StringBuilder.

Ulf et al: The exception messages for out of bounds checks are maddeningly
inconsistent.  Are y'all OK with making them consistent and maximally
informative?  something like "start = %d, end = %d, length = %d".  Throwing
SIIOBE(srcEnd - srcBegin) as is currently done is confusing.

Martin

On Thu, Apr 11, 2013 at 12:55 PM, Ulf Zibis <Ulf.Zibis at cosoco.de> wrote:

> Hi Martin,
>
> great idea!
>
> Regarding the exception handling...
>
> You should reuse getCharsOutOfBounds() from AbstractStringBuilder in
> String.
> Also IMO the exception messages need some "corporate design"; e.g. in some
> cases the string "srcBegin > srcEnd" is returned, in other cases the int
> value of srcEnd - srcBegin, very messy.
> Resolved that, I'm sure you would need less, maybe only 1, package private
> method to build the exceptions argument.
>
> Anyway as those methods all need some CPU time to execute normally, I'm
> not sure if it's worth to save 1 comparison by outsourcing.
> Additionally having getCharsOutOfBounds as source for the exceptions
> cause/stacktrace could lead to some confusion.
>
> In interface CharSequence, the javadocs are missing.
>
> -Ulf
>
>
> Am 11.04.2013 02:40, schrieb Martin Buchholz:
>
>  I've often wished that CharSequence had getChars methods, as many of the
>> concrete implementations already do.
>> In jdk8 with default methods, this is possible!
>> This will make some of the String code a little nicer and more efficient.
>>
>> Here's a preliminary patch in this direction, that overlaps with some of
>> the work done in
>>
>> 6206780: (str) Forwarding append methods in String{Buffer,Builder} are
>> inconsistent
>> Summary: update StringBuilder & StringBuffer to consistently handle
>> forwarding to AbstractStringBuilder. Some additional cleanup (removal of
>> refs to sub-classes from AbstractStringBuilder)
>>
>> http://cr.openjdk.java.net/~**martin/webrevs/openjdk8/**getChars/<http://cr.openjdk.java.net/~martin/webrevs/openjdk8/getChars/>
>>
>> If we have consensus that this is a good idea, I can flesh this out.
>>
>>
>



More information about the core-libs-dev mailing list