org.ahmadsoft.ropes.impl
Class FlatCharArrayRope

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

public final class FlatCharArrayRope
extends AbstractRope

A rope constructed from a character array. This rope is even flatter than a regular flat rope.

Author:
Amin Ahmad
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.ahmadsoft.ropes.Rope
BUILDER
 
Constructor Summary
FlatCharArrayRope(char[] sequence)
          Constructs a new rope from a character array.
FlatCharArrayRope(char[] sequence, int offset, int length)
          Constructs a new rope from a character array range.
 
Method Summary
 char charAt(int index)
           
 byte depth()
           
 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, int fromIndex)
          Returns the index within this rope of the first occurrence of the specified string, beginning at the specified index.
 java.util.Iterator<java.lang.Character> iterator(int start)
          Returns an iterator positioned to start at the specified index.
 int length()
           
 Rope reverse()
          Reverses this rope.
 java.util.Iterator<java.lang.Character> reverseIterator(int start)
          Returns a reverse iterator positioned to start at the specified index.
 Rope subSequence(int start, int end)
           
 java.lang.String toString()
           
 java.lang.String toString(int offset, int length)
          Returns a String representation of a range in this rope.
 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 class org.ahmadsoft.ropes.impl.AbstractRope
append, append, append, compareTo, delete, endsWith, endsWith, equals, hashCode, indexOf, insert, isEmpty, iterator, matcher, matches, matches, padEnd, padEnd, padStart, padStart, rebalance, reverseIterator, startsWith, startsWith, trim, trimEnd, trimStart, writeReplace
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ahmadsoft.ropes.Rope
append, append, append, delete, endsWith, endsWith, indexOf, insert, isEmpty, matcher, matches, matches, padEnd, padEnd, padStart, padStart, rebalance, reverseIterator, startsWith, startsWith, trim, trimEnd, trimStart
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

FlatCharArrayRope

public FlatCharArrayRope(char[] sequence)
Constructs a new rope from a character array.

Parameters:
sequence - the character array.

FlatCharArrayRope

public FlatCharArrayRope(char[] sequence,
                         int offset,
                         int length)
Constructs a new rope from a character array range.

Parameters:
sequence - the character array.
offset - the offset in the array.
length - the length of the array.
Method Detail

charAt

public char charAt(int index)
Specified by:
charAt in interface java.lang.CharSequence

depth

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

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
Overrides:
indexOf in class AbstractRope
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.

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
Overrides:
indexOf in class AbstractRope
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,
                   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
Overrides:
indexOf in class AbstractRope
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.

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.

Specified by:
iterator in interface Rope
Parameters:
start - the start position.
Returns:
an iterator positioned to start at the specified index.

length

public int length()
Specified by:
length in interface java.lang.CharSequence

reverse

public Rope reverse()
Description copied from interface: Rope
Reverses this rope.

Specified by:
reverse in interface Rope
Returns:
a reversed copy of this rope.

reverseIterator

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

Specified by:
reverseIterator in interface Rope
Parameters:
start - the start position.
Returns:
a reverse iterator positioned to start at the specified index from the end of the rope. For example, a value of 1 indicates the iterator should start 1 character before the end of the rope.
See Also:
Rope.reverseIterator()

subSequence

public Rope subSequence(int start,
                        int end)
Specified by:
subSequence in interface java.lang.CharSequence
Specified by:
subSequence in interface Rope

toString

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

toString

public java.lang.String toString(int offset,
                                 int length)
Returns a String representation of a range in this rope.

Parameters:
offset - the offset.
length - the length.
Returns:
a String representation of a range in this rope.

write

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

Specified by:
write in interface Rope
Parameters:
out - the writer object.
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 a range of this rope to a Writer.

Specified by:
write in interface Rope
Parameters:
out - the writer object.
offset - the range offset.
length - the range length.
Throws:
java.io.IOException


Copyright © 2007 Amin Ahmad. All Rights Reserved.