com.funambol.util
Class ChunkedString

java.lang.Object
  extended by com.funambol.util.ChunkedString

public class ChunkedString
extends java.lang.Object

This class allow to process substrings of a bigger string without allocate additional memory, but using the original buffer. The original string is not modified by this class.


Constructor Summary
ChunkedString(ChunkedString cs)
          Creates a ChunkedString from another ChunkedString and two indexes relative to the chunk
ChunkedString(ChunkedString cs, int a, int b)
          Creates a ChunkedString from another ChunkedString and two indexes relative to the chunk
ChunkedString(java.lang.String s)
          Creates a ChunkedString from a plain String, with length equal to the whole string.
ChunkedString(java.lang.String s, int a, int b)
          Creates a ChunkedString from a plain String and two indexes
 
Method Summary
 char charAt(int index)
          Returns the character at the specified position, relative to the chunk.
 boolean equals(java.lang.String s)
          Returns true if s is equals to the current chunk
 boolean equalsIgnoreCase(java.lang.String s)
          Returns true if s is equals to the current chunk, ignoring case.
 ChunkedString getNextChunk(java.lang.String sep)
          Gets the next chunk, using the given separator, as another ChunkedString, without allocating memory.
 ChunkedString getNextChunk(java.lang.String[] sep)
          Gets the smallest chunk, using one of the given separators, as a ChunkedString.
 java.lang.String getNextString(java.lang.String sep)
          Gets the next chunk, using the given separator, as a plain String.
 java.lang.String getNextString(java.lang.String[] sep)
          Gets the smallest chunk, using one of the given separators, as a plain String.
 int indexOf(ChunkedString s)
          Returns the index within this chunk of the first occurrence of the specified substring.
 int indexOf(java.lang.String s)
          Returns the index within this chunk of the first occurrence of the specified substring.
 int indexOf(java.lang.String s, int newStartPoint)
          Returns the index within this chunk of the first occurrence of the specified substring.
 boolean isEmpty()
          Returns true if the chunk is empty (i.e.
 int length()
          Returns the length of the substring.
 boolean moveEnd(int n)
          Move the backward the end index of 'n' characters.
 boolean moveStart(int n)
          Move the forward start index of 'n' characters.
 void reset()
          Reset the chunk indexes to the lenght of the whole buffer.
 ChunkedString[] split(java.lang.String sep)
          Split the string into an array of strings using one of the separator in 'sep'.
 boolean startsWith(java.lang.String s)
          Returns true if the chunk is starts with the specified substring.
 ChunkedString substring(int newStart)
          Creates a new ChunkedString from the specified indexes.
 ChunkedString substring(int newStart, int newEnd)
          Creates a new ChunkedString from the specified indexes.
 java.lang.String toString()
          Return a copy of the string limited by the chunk indexes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChunkedString

public ChunkedString(java.lang.String s)
Creates a ChunkedString from a plain String, with length equal to the whole string.

Parameters:
s - the string

ChunkedString

public ChunkedString(java.lang.String s,
                     int a,
                     int b)
              throws java.lang.IndexOutOfBoundsException
Creates a ChunkedString from a plain String and two indexes

Parameters:
s - the string
a - the start index
b - the end index
Throws:
java.lang.IndexOutOfBoundsException

ChunkedString

public ChunkedString(ChunkedString cs,
                     int a,
                     int b)
Creates a ChunkedString from another ChunkedString and two indexes relative to the chunk

Parameters:
cs - the string
a - the start index
b - the end index

ChunkedString

public ChunkedString(ChunkedString cs)
Creates a ChunkedString from another ChunkedString and two indexes relative to the chunk

Parameters:
cs - the string
a - the start index
b - the end index
Method Detail

getNextString

public java.lang.String getNextString(java.lang.String sep)
Gets the next chunk, using the given separator, as a plain String. If the separator is not found, return the rest of the chunk. The start position of the object is moved after the end of the returned chunk.


getNextString

public java.lang.String getNextString(java.lang.String[] sep)
Gets the smallest chunk, using one of the given separators, as a plain String. If the separator is not found, return the rest of the chunk. The start position of the object is moved after the end of the returned chunk.

Parameters:
sep - an array of string used as separators. if two or more strings are found at the same index the first one in the array is used as the separator

getNextChunk

public ChunkedString getNextChunk(java.lang.String[] sep)
Gets the smallest chunk, using one of the given separators, as a ChunkedString. If the separator is not found, return the rest of the chunk. The start position of the object is moved after the end of the returned chunk.

Parameters:
sep - an array of string used as separators. if two or more strings are found at the same index the first one in the array is used as the separator

getNextChunk

public ChunkedString getNextChunk(java.lang.String sep)
Gets the next chunk, using the given separator, as another ChunkedString, without allocating memory. If the separator is not found, return the rest of the chunk. The start position of the object is moved after the end of the returned chunk.


charAt

public char charAt(int index)
            throws java.lang.IndexOutOfBoundsException
Returns the character at the specified position, relative to the chunk.

Parameters:
index - the index of the character relatoive to the chunk.
Returns:
the character at the specified index of this chunk. The first character is at index 0.
Throws:
IndexOutOfBoundException - If the given index is out of the chunk boundaries.
java.lang.IndexOutOfBoundsException

split

public ChunkedString[] split(java.lang.String sep)
Split the string into an array of strings using one of the separator in 'sep'.

Parameters:
s - the string to tokenize
sep - a list of separator to use
Returns:
the array of tokens (an array of size 1 with the original string if no separator found)

equals

public boolean equals(java.lang.String s)
Returns true if s is equals to the current chunk


equalsIgnoreCase

public boolean equalsIgnoreCase(java.lang.String s)
Returns true if s is equals to the current chunk, ignoring case.


isEmpty

public boolean isEmpty()
Returns true if the chunk is empty (i.e. start>=end)


indexOf

public int indexOf(java.lang.String s)
Returns the index within this chunk of the first occurrence of the specified substring.


indexOf

public int indexOf(java.lang.String s,
                   int newStartPoint)
Returns the index within this chunk of the first occurrence of the specified substring.


indexOf

public int indexOf(ChunkedString s)
Returns the index within this chunk of the first occurrence of the specified substring.


substring

public ChunkedString substring(int newStart,
                               int newEnd)
Creates a new ChunkedString from the specified indexes.


substring

public ChunkedString substring(int newStart)
Creates a new ChunkedString from the specified indexes.


length

public int length()
Returns the length of the substring.


startsWith

public boolean startsWith(java.lang.String s)
Returns true if the chunk is starts with the specified substring.


reset

public void reset()
Reset the chunk indexes to the lenght of the whole buffer.


moveStart

public boolean moveStart(int n)
Move the forward start index of 'n' characters.

Parameters:
n - the number of characters to move the index. If n is negative start is moved backward.
Returns:
true if the start index is still valid after the move false if a boundary has been reached (start was < 0 if for n negative, or greater than end for n positive). In the this case, start is made equal to the boundary.

moveEnd

public boolean moveEnd(int n)
Move the backward the end index of 'n' characters. If n is negative, end is moved forward.

Parameters:
n - the number of characters to move the index
Returns:
true if the end index is still valid after the move false if a boundary has been reached (end was less than start if for n positive, or greater than buffer length for n positive). In this case, end is made equal to the boundary.

toString

public java.lang.String toString()
Return a copy of the string limited by the chunk indexes.

Overrides:
toString in class java.lang.Object


Copyright © 2001-2009 Funambol.