[Bug 198] New: return java.lang.CharSequence in getTextCharacters()
[email protected] Thu, 13 May 2004 15:09:05 -0500 (EST)
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Message-ID | <[email protected]> |
http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=198
Summary: return java.lang.CharSequence in getTextCharacters()
Product: XmlPull.org
Version: 1.1.2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P5
Component: Design
AssignedTo: [email protected]
ReportedBy: [email protected]
I would like to have: java.lang.CharSequence getTextCharacters() in XmlPullParser
This is easier to use than char[] getTextCharacters(int[]).
See also: http://developer.java.sun.com/developer/bugParade/bugs/4838318.html
The Java SDK will in future allow much more CharSequence type parameters where
it currently requires String type parameters.
As far as I see it, getTextCharacters(int[]) was mainly added for performance reasons, since getText() is also available.
And as already stated in the docu for getTextCharacters(int[]), that the content
is only available (valid) until any next() call, the same should be true for
this new method. So that the implementation only needs to store/maintain one
instance of CharSequence. The implementation then only changes the internal char[] buffer, the start offset and the length before it returns the same CharSequence again.
If the general idea of the above would be accepted, then I even would like to
continue with adding two new public interfaces to the API like illustrated here:
interface XmlText extends CharSequence {
// implement all methods from CharSequence
/** read content as integer value.
* This would allow the implementation to supply primitive value types
* without the need of intermediate object creations.
*/
int parseInt() throws java.text.ParseException
/** read content as long value */
long parseLong() throws java.text.ParseException;
// same for all other primitive Java types
/** build same hash code as java.lang.String does, so that
* this instance can be used in java.lang.Map for lookups
*/
int hashCode();
/** compares this instance with any other CharSequene character
* by character
*/
boolean equals( Object o );
/** trim whites at the left and right side.
* NOTE: this would again return the same instance
*/
XmlText trim();
String toString();
}
Another interface XmlAttibute is implemented just like the class above.
The XmlAttribute interface may additionally supply methods with information
from the validator like isNumberType().
Finally on XmlPullParser the following methods need to be added:
XmlText getXmlText();
XmlAttribute getXmlAttribute(int index);
Comment:
Supplying XmlText and XmlAttribute as part of the API would allow the
JIT-compiler to inline the implementation of CharSequence.charAt(int)
from the XmlText and XmlAttribute implementation where ever it is used,
as long as there is only one implementation of XmlText and XmlAttribute
for the current class loader.
While just returning a CharSequence instance (which is implemented in several
classes, like in String) does not allow the JIT-compiler to optimize (inline).
And charAt(int) will be the most frequently used method here.
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/2U_rlB/TM
---------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/xmlpull-dev/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/