org.ahmadsoft.ropes.impl
Class AbstractRope

java.lang.Object
  extended by org.ahmadsoft.ropes.impl.AbstractRope
All Implemented Interfaces:
java.io.Serializable, java.lang.CharSequence, java.lang.Comparable<java.lang.CharSequence>, java.lang.Iterable<java.lang.Character>, Rope
Direct Known Subclasses:
ConcatenationRope, FlatCharArrayRope, FlatCharSequenceRope, ReverseRope, SubstringRope

public abstract class AbstractRope
extends java.lang.Object
implements Rope

Abstract base class for ropes that implements many of the common operations.

Author:
Amin Ahmad
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.ahmadsoft.ropes.Rope
BUILDER
 
Constructor Summary
AbstractRope()
           
 
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.
 int compareTo(java.lang.CharSequence sequence)
           
 Rope delete(int start, int end)
          Creats a new rope by delete the specified character substring.
abstract  byte depth()
           
 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.
 boolean equals(java.lang.Object other)
           
 int hashCode()
           
 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()
           
 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 toWidth)
          Increase the length of this rope to the specified length by appending spaces to this rope.
 Rope padEnd(int toWidth, char padChar)
          Increase the length of this rope to the specified length by repeatedly appending the specified character to this rope.
 Rope padStart(int toWidth)
          Increase the length of this rope to the specified length by prepending spaces to this rope.
 Rope padStart(int toWidth, 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.
 java.util.Iterator<java.lang.Character> reverseIterator()
          Returns a reverse iterator positioned to start at the end of this rope.
 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.
 java.lang.String toString()
           
 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.
 java.lang.Object writeReplace()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ahmadsoft.ropes.Rope
iterator, reverse, reverseIterator, subSequence, write, write
 
Methods inherited from interface java.lang.CharSequence
charAt, length
 

Constructor Detail

AbstractRope

public AbstractRope()
Method Detail

append

public Rope append(char c)
Description copied from interface: Rope
Returns a new rope created by appending the specified character to this rope.

Specified by:
append in interface Rope
Parameters:
c - the specified character.
Returns:
a new rope.

append

public Rope append(java.lang.CharSequence suffix)
Description copied from interface: Rope
Returns a new rope created by appending the specified character sequence to this rope.

Specified by:
append in interface Rope
Parameters:
suffix - the specified suffix.
Returns:
a new rope.

append

public Rope append(java.lang.CharSequence csq,
                   int start,
                   int end)
Description copied from interface: Rope
Returns a new rope created by appending the specified character range to this rope.

Specified by:
append in interface Rope
Parameters:
csq - the specified character.
start - the start index, inclusive.
end - the end index, non-inclusive.
Returns:
a new rope.

compareTo

public int compareTo(java.lang.CharSequence sequence)
Specified by:
compareTo in interface java.lang.Comparable<java.lang.CharSequence>

delete

public Rope delete(int start,
                   int end)
Description copied from interface: Rope
Creats a new rope by delete the specified character substring. The substring begins at the specified 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.

Specified by:
delete in interface Rope
Parameters:
start - The beginning index, inclusive.
end - The ending index, exclusive.
Returns:
This object.

depth

public abstract byte depth()

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

indexOf

public int indexOf(char ch)
Description copied from interface: Rope
Returns the index within this rope of the first occurrence of the specified character. If a character with value 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.

Specified by:
indexOf in interface Rope
Parameters:
ch - a character.
Returns:
the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.

startsWith

public boolean startsWith(java.lang.CharSequence prefix)
Description copied from interface: Rope
Returns true if this rope starts with the specified prefix.

Specified by:
startsWith in interface Rope
Parameters:
prefix - the prefix to test.
Returns:
true if this rope starts with the specified prefix and false otherwise.
See Also:
Rope.startsWith(CharSequence, int)

startsWith

public boolean startsWith(java.lang.CharSequence prefix,
                          int offset)
Description copied from interface: Rope
Returns true if this rope, beginning from a specified offset, starts with the specified prefix.

Specified by:
startsWith in interface Rope
Parameters:
prefix - the prefix to test.
offset - the start offset.
Returns:
true if this rope starts with the specified prefix and false otherwise.

endsWith

public boolean endsWith(java.lang.CharSequence suffix)
Description copied from interface: Rope
Returns true if this rope ends with the specified suffix.

Specified by:
endsWith in interface Rope
Parameters:
suffix - the suffix to test.
Returns:
true if this rope starts with the specified suffix and false otherwise.
See Also:
Rope.endsWith(CharSequence, int)

endsWith

public boolean endsWith(java.lang.CharSequence suffix,
                        int offset)
Description copied from interface: Rope
Returns true if this rope, terminated at a specified offset, ends with the specified suffix.

Specified by:
endsWith in interface Rope
Parameters:
suffix - the suffix to test.
offset - the termination offset, counted from the end of the rope.
Returns:
true if this rope starts with the specified prefix and false otherwise.

indexOf

public int indexOf(char ch,
                   int fromIndex)
Description copied from interface: Rope
Returns the index within this rope of the first occurrence of the specified character, beginning at the specified index. If a character with value 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.

Specified by:
indexOf in interface Rope
Parameters:
ch - a character.
fromIndex - the index to start searching from.
Returns:
the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.

indexOf

public int indexOf(java.lang.CharSequence sequence)
Description copied from interface: Rope
Returns the index within this rope of the first occurrence of the specified string. The value returned is the smallest k such that:
     this.startsWith(str, k)
 
If no such k exists, then -1 is returned.

Specified by:
indexOf in interface Rope
Parameters:
sequence - the string to find.
Returns:
the index of the first occurrence of the specified string, or -1 if the specified string does not occur.

indexOf

public int indexOf(java.lang.CharSequence sequence,
                   int fromIndex)
Description copied from interface: Rope
Returns the index within this rope of the first occurrence of the specified string, beginning at the specified index. The value returned is the smallest k such that:
     k >= fromIndex && this.startsWith(str, k)
 
If no such k exists, then -1 is returned.

Specified by:
indexOf in interface Rope
Parameters:
sequence - the string to find.
fromIndex - the index to start searching from.
Returns:
the index of the first occurrence of the specified string, or -1 if the specified string does not occur.

insert

public Rope insert(int dstOffset,
                   java.lang.CharSequence s)
Description copied from interface: Rope
Creates a new rope by inserting the specified 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.

Specified by:
insert in interface Rope
Parameters:
dstOffset - the offset.
s - the sequence to be inserted
Returns:
a reference to the new Rope.

iterator

public java.util.Iterator<java.lang.Character> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.Character>

trimStart

public Rope trimStart()
Description copied from interface: Rope
Trims all whitespace as well as characters less than 0x20 from the beginning of this string.

Specified by:
trimStart in interface Rope
Returns:
a rope with all leading whitespace trimmed.

matcher

public java.util.regex.Matcher matcher(java.util.regex.Pattern pattern)
Description copied from interface: Rope
Creates a matcher that will match this rope against the specified pattern. This method produces a higher performance matcher than:
 Matcher m = pattern.matcher(this);
 
The difference may be asymptotically better in some cases.

Specified by:
matcher in interface Rope
Parameters:
pattern - the pattern to match this rope against.
Returns:
a matcher.

matches

public boolean matches(java.util.regex.Pattern regex)
Description copied from interface: Rope
Returns true if this rope matches the specified Pattern, or false otherwise.

Specified by:
matches in interface Rope
Parameters:
regex - the specified regular expression.
Returns:
true if this rope matches the specified Pattern, or false otherwise.
See Also:
Pattern

matches

public boolean matches(java.lang.String regex)
Description copied from interface: Rope
Returns true if this rope matches the specified regular expression, or false otherwise.

Specified by:
matches in interface Rope
Parameters:
regex - the specified regular expression.
Returns:
true if this rope matches the specified regular expression, or false otherwise.
See Also:
Pattern

rebalance

public Rope rebalance()
Description copied from interface: Rope
Rebalances the current rope, returning the rebalanced rope. In general, rope rebalancing is handled automatically, but this method is provided to give users more control.

Specified by:
rebalance in interface Rope
Returns:
a rebalanced rope.

reverseIterator

public java.util.Iterator<java.lang.Character> reverseIterator()
Description copied from interface: Rope
Returns a reverse iterator positioned to start at the end of this rope. A reverse iterator moves backwards instead of forwards through a rope.

Specified by:
reverseIterator in interface Rope
Returns:
A reverse iterator positioned at the end of this rope.
See Also:
Rope.reverseIterator(int)

trimEnd

public Rope trimEnd()
Description copied from interface: Rope
Trims all whitespace as well as characters less than 0x20 from the end of this rope.

Specified by:
trimEnd in interface Rope
Returns:
a rope with all trailing whitespace trimmed.

toString

public java.lang.String toString()
Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object

trim

public Rope trim()
Description copied from interface: Rope
Trims all whitespace as well as characters less than 0x20 from the beginning and end of this string.

Specified by:
trim in interface Rope
Returns:
a rope with all leading and trailing whitespace trimmed.

writeReplace

public java.lang.Object writeReplace()
                              throws java.io.ObjectStreamException
Throws:
java.io.ObjectStreamException

padStart

public Rope padStart(int toWidth)
Description copied from interface: Rope
Increase the length of this rope to the specified length by prepending spaces to this rope. If the specified length is less than or equal to the current length of the rope, the rope is returned unmodified.

Specified by:
padStart in interface Rope
Parameters:
toWidth - the desired length.
Returns:
the padded rope.
See Also:
Rope.padStart(int, char)

padStart

public Rope padStart(int toWidth,
                     char padChar)
Description copied from interface: Rope
Increase the length of this rope to the specified length by repeatedly prepending the specified character to this rope. If the specified length is less than or equal to the current length of the rope, the rope is returned unmodified.

Specified by:
padStart in interface Rope
Parameters:
toWidth - the desired length.
padChar - the character to use for padding.
Returns:
the padded rope.
See Also:
Rope.padStart(int, char)

padEnd

public Rope padEnd(int toWidth)
Description copied from interface: Rope
Increase the length of this rope to the specified length by appending spaces to this rope. If the specified length is less than or equal to the current length of the rope, the rope is returned unmodified.

Specified by:
padEnd in interface Rope
Parameters:
toWidth - the desired length.
Returns:
the padded rope.
See Also:
Rope.padStart(int, char)

padEnd

public Rope padEnd(int toWidth,
                   char padChar)
Description copied from interface: Rope
Increase the length of this rope to the specified length by repeatedly appending the specified character to this rope. If the specified length is less than or equal to the current length of the rope, the rope is returned unmodified.

Specified by:
padEnd in interface Rope
Parameters:
toWidth - the desired length.
padChar - the character to use for padding.
Returns:
the padded rope.
See Also:
Rope.padStart(int, char)

isEmpty

public boolean isEmpty()
Description copied from interface: Rope
Returns true if and only if the length of this rope is zero.

Specified by:
isEmpty in interface Rope
Returns:
true if and only if the length of this rope is zero, and false otherwise.


Copyright © 2007 Amin Ahmad. All Rights Reserved.