JDK-4838318 : (str) add StringBuilder.indexOf(CharSequence) and related
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2003-03-27
  • Updated: 2017-12-15
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Name: nt126004			Date: 03/26/2003


A DESCRIPTION OF THE REQUEST :
RFE

With the introduction of the CharSequence interface,
the String class is no longer the lowest-common-denominator
for character data, and yet String arguments
are still a pervasive requirement throughout the API.

All API methods currently specifying String arguments
should be relaxed to CharSequence arguments unless
they require immutability, equals(), hashCode(),
or other String-specific behavior.

This change would not affect any existing code.

Here are a few candidate methods
found by simply searching the API for the string,
err, I mean the CharSequence ;-)
---> "(String"

StringBuffer(String str)
StringBuffer.append(String str) //related Bug Id 4812591
StringBuffer.append(StringBuffer sb) //related Bug Id 4812591
StringBuffer.indexOf(String str)
StringBuffer.lastIndexOf(String str, int fromIndex)
java.io.StringReader(String s) // CharSequenceReader?
JTextComponent.replaceSelection(String content)
JTextComponent.setText(String t)
JEditorPane.setText(String text)
JTextArea(String text)
JTextArea(String text, int rows, int columns)
JTextArea.append(String str)
JTextArea.insert(String str, int pos)
JTextArea.replaceRange(String str, int start, int end)
JEditorPane(String url)
JEditorPane(String type, String text)
JList.getNextMatch(String prefix, int startIndex, Position.Bias bias)
AbstractWriter.setLineSeparator(String value)
AbstractWriter.write(String content)
Integer(String s)
Integer.parseInt(String s)
Integer.valueOf(String s)
Double(String s)
Double.parseDouble(String s)
StringTokenizer.nextToken(String delim)


JUSTIFICATION :
This enhancement would eliminate creation and garbage-collection of superfluous String objects when text is stored in a some other implementation of CharSequence.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Component makeTextArea(CharSequence chars){
    return new javax.swing.JTextArea(chars);
}
Component makeTextArea(CharSequence chars){
    return new javax.swing.JTextArea(chars.toString());
}

CUSTOMER SUBMITTED WORKAROUND :
Use charSequence.toString() wherever a String object is required.
(Review ID: 183002) 
======================================================================

Comments
This bug is considerably narrow than as originally filed, as described in the comment from Iris on 2006-09-13. Specifically, this bug now covers only enhancements to add CharSequence overloads for the following: StringBuilder.indexOf(String str) StringBuilder.indexOf(String str, int fromIndex) StringBuilder.lastIndexOf(String str) StringBuilder.lastIndexOf(String str, int fromIndex) and corresponding methods for StringBuffer. I'm adjusting the summary line accordingly. The original summary line was: (str) Substitute CharSequence for String arguments wherever possible
15-12-2017

EVALUATION This request is covered by several other bugs as indicated. java.lang StringBuffer(String str) - Tiger bug 4705328 StringBuffer.append(String str) //related Bug Id 4812591 StringBuffer.append(StringBuffer sb) //related Bug Id 4812591 - Tiger bug 4812591 StringBuffer.indexOf(String str) StringBuffer.lastIndexOf(String str, int fromIndex) - This bug remains open to consider the possibility of adding these methods. java.io java.io.StringReader(String s) // CharSequenceReader? - Related bug 5043696? javax.swing JTextComponent.replaceSelection(String content) JTextComponent.setText(String t) JEditorPane.setText(String text) JTextArea(String text) JTextArea(String text, int rows, int columns) JTextArea.append(String str) JTextArea.insert(String str, int pos) JTextArea.replaceRange(String str, int start, int end) JEditorPane(String url) JEditorPane(String type, String text) JList.getNextMatch(String prefix, int startIndex, Position.Bias bias) AbstractWriter.setLineSeparator(String value) AbstractWriter.write(String content) - covered under newly-submitted swing bug 6470454 java.lang - wrapper classes Integer(String s) Integer.parseInt(String s) Integer.valueOf(String s) Double(String s) Double.parseDouble(String s) - enlarged scope of 4951621 (for parse methods only) to cover constructors and valueOf() java.util StringTokenizer.nextToken(String delim) - covered under newly-submitted util bug 6470511
14-09-2006