|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Rope
A rope represents character strings. Ropes are immutable which means that once they are created, they cannot be changed. This makes them suitable for sharing in multi-threaded environments.
Rope operations, unlike string operations, scale well to very long character strings. Most mutation operations run in O(log n) time or better. However, random-access character retrieval is generally slower than for a String. By traversing consecutive characters with an iterator instead, performance improves to O(1).
This rope implementation implements all performance optimizations outlined in "Ropes: an Alternative to Strings" by Hans-J. Boehm, Russ Atkinson and Michael Plass, including, notably, deferred evaluation of long substrings and automatic rebalancing.
CharSequences
such as Strings
,
or else from mutable CharSequences
that your program
Field Summary | |
---|---|
static RopeBuilder |
BUILDER
A factory used for constructing ropes. |
Method Summary | |
---|---|
Rope |
append(char c)
Returns a new rope created by appending the specified character to this rope. |
Rope |
append(java.lang.CharSequence suffix)
Returns a new rope created by appending the specified character sequence to this rope. |
Rope |
append(java.lang.CharSequence csq,
int start,
int end)
Returns a new rope created by appending the specified character range to this rope. |
Rope |
delete(int start,
int end)
Creats a new rope by delete the specified character substring. |
int |
indexOf(char ch)
Returns the index within this rope of the first occurrence of the specified character. |
Rope |
insert(int dstOffset,
java.lang.CharSequence s)
Creates a new rope by inserting the specified CharSequence
into this rope. |
java.util.Iterator<java.lang.Character> |
iterator(int start)
Returns an iterator positioned to start at the specified index. |
java.util.regex.Matcher |
matcher(java.util.regex.Pattern pattern)
Creates a matcher that will match this rope against the specified pattern. |
Rope |
rebalance()
Rebalances the current rope, returning the rebalanced rope. |
Rope |
subSequence(int start,
int end)
|
void |
write(java.io.Writer out)
Write this rope. |
void |
write(java.io.Writer out,
int offset,
int length)
Write this rope. |
Methods inherited from interface java.lang.CharSequence |
---|
charAt, length, toString |
Methods inherited from interface java.lang.Iterable |
---|
iterator |
Methods inherited from interface java.lang.Comparable |
---|
compareTo |
Field Detail |
---|
static final RopeBuilder BUILDER
Method Detail |
---|
Rope append(char c)
c
- the specified character.
Rope append(java.lang.CharSequence suffix)
suffix
- the specified suffix.
Rope append(java.lang.CharSequence csq, int start, int end)
csq
- the specified character.start
- the start index, inclusive.end
- the end index, non-inclusive.
Rope delete(int start, int end)
start
and extends to
the character at index end - 1
or to the end of the
sequence if no such character exists. If
start
is equal to end
, no changes are made.
start
- The beginning index, inclusive.end
- The ending index, exclusive.
java.lang.StringIndexOutOfBoundsException
- if start
is negative, greater than length()
, or
greater than end
.int indexOf(char ch)
ch
occurs
in the character sequence represented by this String
object, then the index of the first such occurrence is returned --
that is, the smallest value k such that:
this.charAt(k) == ch
is true
. If no such character occurs in this string, then
-1
is returned.
ch
- a character.
-1
if the character
does not occur.Rope insert(int dstOffset, java.lang.CharSequence s)
CharSequence
into this rope.
The characters of the CharSequence
argument are inserted,
in order, into this rope at the indicated offset.
If s
is null
, then the four characters
"null"
are inserted into this sequence.
dstOffset
- the offset.s
- the sequence to be inserted
java.lang.IndexOutOfBoundsException
- if the offset is invalid.java.util.Iterator<java.lang.Character> iterator(int start)
start
- the start position.
Rope rebalance()
void write(java.io.Writer out) throws java.io.IOException
out
-
java.io.IOException
void write(java.io.Writer out, int offset, int length) throws java.io.IOException
out
-
java.io.IOException
Rope subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
java.util.regex.Matcher matcher(java.util.regex.Pattern pattern)
Matcher m = pattern.matcher(this);The difference may be asymptotically better in many cases.
pattern
- the pattern to match this rope against.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |