org.sitemesh.tagprocessor.util
Class CharSequenceList
java.lang.Object
org.sitemesh.tagprocessor.util.CharSequenceList
- All Implemented Interfaces:
- Appendable, CharSequence, Iterable<CharSequence>, CharSequenceBuffer
public class CharSequenceList
- extends Object
- implements CharSequenceBuffer
An Appendable buffer of character data,similar to StringBuilder and
StringBuffer), except rather than copying the contents to an array of characters,
it keeps a list of references to the original CharSequences.
This offers a few advantages:
- If the CharSequences are already in memory elsewhere, it avoids the need for having
multiple copies, thereby saving memory.
- Avoiding copying the actual char data also offers a performance boost when copying large
CharSequences.
- The actual CharSequence being referred to does not need to know it's data until the entire
CharSequenceList is rendered. This offers the ability to do async data loading.
With these advantages, come some disadvantages:
- Appending an individual char requires wrapping it in an object and appending to a list. Avoid appending
lots of small CharSequences - it's better to use fewer larger chunks.
- Random access reading through the CharSequence interface is not yet supported. Use
writeTo(Appendable)
instead.
- Author:
- Joe Walnes
CharSequenceList
public CharSequenceList()
append
public Appendable append(CharSequence csq)
- Specified by:
append in interface Appendable
append
public Appendable append(CharSequence csq,
int start,
int end)
- Specified by:
append in interface Appendable
append
public Appendable append(char c)
- Warning: Each time this method is called, a new String of length 1 is constructed
and added to a LinkedList - this is not optimal. If building up strings, it is
more efficient to build these up externally in a StringBuilder, and then pass that
to
append(CharSequence).
- Specified by:
append in interface Appendable
length
public int length()
- Specified by:
length in interface CharSequence
charAt
public char charAt(int index)
- Specified by:
charAt in interface CharSequence
subSequence
public CharSequence subSequence(int start,
int end)
- Specified by:
subSequence in interface CharSequence
iterator
public Iterator<CharSequence> iterator()
- Specified by:
iterator in interface Iterable<CharSequence>
toString
public String toString()
- Specified by:
toString in interface CharSequence- Overrides:
toString in class Object
writeTo
public void writeTo(Appendable out)
throws IOException
- Specified by:
writeTo in interface CharSequenceBuffer
- Throws:
IOException
Copyright © 2011. All Rights Reserved.