Add getChars to CharSequence

Ulf Zibis Ulf.Zibis at CoSoCo.de
Thu Apr 11 19:55:08 UTC 2013


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/
>
> If we have consensus that this is a good idea, I can flesh this out.
>




More information about the core-libs-dev mailing list