org.ahmadsoft.ropes.impl
Class AbstractRope

java.lang.Object
  extended by org.ahmadsoft.ropes.impl.AbstractRope
All Implemented Interfaces:
java.lang.CharSequence, java.lang.Comparable<java.lang.CharSequence>, java.lang.Iterable<java.lang.Character>, Rope
Direct Known Subclasses:
ConcatenationRope, FlatRope, 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

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 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.
 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()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ahmadsoft.ropes.Rope
iterator, matcher, rebalance, 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.

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()

hashCode

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

equals

public boolean equals(java.lang.Object other)
Overrides:
equals 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 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.

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.

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>

compareTo

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

toString

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