org.ahmadsoft.ropes.impl
Class SubstringRope

java.lang.Object
  extended by org.ahmadsoft.ropes.impl.AbstractRope
      extended by org.ahmadsoft.ropes.impl.SubstringRope
All Implemented Interfaces:
java.lang.CharSequence, java.lang.Comparable<java.lang.CharSequence>, java.lang.Iterable<java.lang.Character>, Rope

public class SubstringRope
extends AbstractRope

Represents a lazily-evaluated substring of another rope. For performance reasons, the target rope must be a FlatRope.

Author:
aahmad

Field Summary
 
Fields inherited from interface org.ahmadsoft.ropes.Rope
BUILDER
 
Constructor Summary
SubstringRope(FlatRope rope, int offset, int length)
           
 
Method Summary
 char charAt(int index)
           
 byte depth()
           
 Rope getRope()
          Returns the rope underlying this one.
 java.util.Iterator<java.lang.Character> iterator(int start)
          Returns an iterator positioned to start at the specified index.
 int length()
           
 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)
           
 java.lang.String toString()
           
 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 class org.ahmadsoft.ropes.impl.AbstractRope
append, append, append, compareTo, delete, equals, hashCode, indexOf, insert, iterator
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SubstringRope

public SubstringRope(FlatRope rope,
                     int offset,
                     int length)
Method Detail

charAt

public char charAt(int index)

depth

public byte depth()
Specified by:
depth in class AbstractRope

getRope

public Rope getRope()
Returns the rope underlying this one.

Returns:
the rope underlying this one.

iterator

public java.util.Iterator<java.lang.Character> iterator(int start)
Description copied from interface: Rope
Returns an iterator positioned to start at the specified index.

Parameters:
start - the start position.
Returns:
an iterator positioned to start at the specified index.

length

public int length()

subSequence

public Rope subSequence(int start,
                        int end)

toString

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

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.

Returns:
a rebalanced rope.

write

public void write(java.io.Writer out)
           throws java.io.IOException
Description copied from interface: Rope
Write this rope.

Throws:
java.io.IOException

write

public void write(java.io.Writer out,
                  int offset,
                  int length)
           throws java.io.IOException
Description copied from interface: Rope
Write this rope.

Throws:
java.io.IOException

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 many cases.

Parameters:
pattern - the pattern to match this rope against.
Returns:
a matcher.