|
|||||||||
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. |
boolean |
endsWith(java.lang.CharSequence suffix)
Returns true if this rope ends with the specified
suffix. |
boolean |
endsWith(java.lang.CharSequence suffix,
int offset)
Returns true if this rope, terminated at a specified
offset, ends with the specified suffix. |
int |
indexOf(char ch)
Returns the index within this rope of the first occurrence of the specified character. |
int |
indexOf(char ch,
int fromIndex)
Returns the index within this rope of the first occurrence of the specified character, beginning at the specified index. |
int |
indexOf(java.lang.CharSequence sequence)
Returns the index within this rope of the first occurrence of the specified string. |
int |
indexOf(java.lang.CharSequence sequence,
int fromIndex)
Returns the index within this rope of the first occurrence of the specified string, beginning at the specified index. |
Rope |
insert(int dstOffset,
java.lang.CharSequence s)
Creates a new rope by inserting the specified CharSequence
into this rope. |
boolean |
isEmpty()
Returns true if and only if the length of this rope is zero. |
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. |
boolean |
matches(java.util.regex.Pattern regex)
Returns true if this rope matches the specified
Pattern , or false otherwise. |
boolean |
matches(java.lang.String regex)
Returns true if this rope matches the specified
regular expression, or false otherwise. |
Rope |
padEnd(int toLength)
Increase the length of this rope to the specified length by appending spaces to this rope. |
Rope |
padEnd(int toLength,
char padChar)
Increase the length of this rope to the specified length by repeatedly appending the specified character to this rope. |
Rope |
padStart(int toLength)
Increase the length of this rope to the specified length by prepending spaces to this rope. |
Rope |
padStart(int toLength,
char padChar)
Increase the length of this rope to the specified length by repeatedly prepending the specified character to this rope. |
Rope |
rebalance()
Rebalances the current rope, returning the rebalanced rope. |
Rope |
reverse()
Reverses this rope. |
java.util.Iterator<java.lang.Character> |
reverseIterator()
Returns a reverse iterator positioned to start at the end of this rope. |
java.util.Iterator<java.lang.Character> |
reverseIterator(int start)
Returns a reverse iterator positioned to start at the specified index. |
boolean |
startsWith(java.lang.CharSequence prefix)
Returns true if this rope starts with the specified
prefix. |
boolean |
startsWith(java.lang.CharSequence prefix,
int offset)
Returns true if this rope, beginning from a specified
offset, starts with the specified prefix. |
Rope |
subSequence(int start,
int end)
|
Rope |
trim()
Trims all whitespace as well as characters less than 0x20 from
the beginning and end of this string. |
Rope |
trimEnd()
Trims all whitespace as well as characters less than 0x20 from
the end of this rope. |
Rope |
trimStart()
Trims all whitespace as well as characters less than 0x20 from the beginning of this string. |
void |
write(java.io.Writer out)
Write this rope to a Writer . |
void |
write(java.io.Writer out,
int offset,
int length)
Write a range of this rope to a Writer . |
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 Rope
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.int indexOf(char ch, int fromIndex)
ch
occurs in the character sequence
represented by this Rope
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.fromIndex
- the index to start searching from.
int indexOf(java.lang.CharSequence sequence)
this.startsWith(str, k)If no such k exists, then -1 is returned.
sequence
- the string to find.
int indexOf(java.lang.CharSequence sequence, int fromIndex)
k >= fromIndex && this.startsWith(str, k)If no such k exists, then -1 is returned.
sequence
- the string to find.fromIndex
- the index to start searching from.
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 trimStart()
java.util.regex.Matcher matcher(java.util.regex.Pattern pattern)
Matcher m = pattern.matcher(this);The difference may be asymptotically better in some cases.
pattern
- the pattern to match this rope against.
boolean matches(java.util.regex.Pattern regex)
true
if this rope matches the specified
Pattern
, or false
otherwise.
regex
- the specified regular expression.
true
if this rope matches the specified
Pattern
, or false
otherwise.Pattern
boolean matches(java.lang.String regex)
true
if this rope matches the specified
regular expression, or false
otherwise.
regex
- the specified regular expression.
true
if this rope matches the specified
regular expression, or false
otherwise.Pattern
Rope rebalance()
Rope reverse()
java.util.Iterator<java.lang.Character> reverseIterator()
reverseIterator(int)
java.util.Iterator<java.lang.Character> reverseIterator(int start)
start
- the start position.
reverseIterator()
Rope trimEnd()
0x20
from
the end of this rope.
Rope subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
Rope trim()
0x20
from
the beginning and end of this string.
void write(java.io.Writer out) throws java.io.IOException
Writer
.
out
- the writer object.
java.io.IOException
void write(java.io.Writer out, int offset, int length) throws java.io.IOException
Writer
.
out
- the writer object.offset
- the range offset.length
- the range length.
java.io.IOException
Rope padStart(int toLength)
toLength
- the desired length.
padStart(int, char)
Rope padStart(int toLength, char padChar)
toLength
- the desired length.padChar
- the character to use for padding.
padStart(int, char)
Rope padEnd(int toLength)
toLength
- the desired length.
padStart(int, char)
Rope padEnd(int toLength, char padChar)
toLength
- the desired length.padChar
- the character to use for padding.
padStart(int, char)
boolean isEmpty()
true
if and only if the length of this
rope is zero, and false
otherwise.boolean startsWith(java.lang.CharSequence prefix)
true
if this rope starts with the specified
prefix.
prefix
- the prefix to test.
true
if this rope starts with the
specified prefix and false
otherwise.startsWith(CharSequence, int)
boolean startsWith(java.lang.CharSequence prefix, int offset)
true
if this rope, beginning from a specified
offset, starts with the specified prefix.
prefix
- the prefix to test.offset
- the start offset.
true
if this rope starts with the
specified prefix and false
otherwise.boolean endsWith(java.lang.CharSequence suffix)
true
if this rope ends with the specified
suffix.
suffix
- the suffix to test.
true
if this rope starts with the
specified suffix and false
otherwise.endsWith(CharSequence, int)
boolean endsWith(java.lang.CharSequence suffix, int offset)
true
if this rope, terminated at a specified
offset, ends with the specified suffix.
suffix
- the suffix to test.offset
- the termination offset, counted from the end of the
rope.
true
if this rope starts with the
specified prefix and false
otherwise.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |