com.caucho.util
Class CharSegment

java.lang.Object
  |
  +--com.caucho.util.CharSegment
Direct Known Subclasses:
CharBuffer

public class CharSegment
extends java.lang.Object

CharSegment is a section of a character buffer


Field Summary
protected  char[] buffer
           
protected  int length
           
protected  int offset
           
 
Constructor Summary
CharSegment()
           
CharSegment(char[] buffer, int offset, int length)
          Constructs a char segment based on a char array.
 
Method Summary
 char charAt(int i)
          Returns the char at the specified offset.
 boolean endsWith(CharSegment cb)
          Returns true if the CharSegment ends with the char segment.
 boolean endsWith(java.lang.String string)
          Returns true if the CharSegment ends with the string.
 boolean equals(char[] cb, int length)
          Returns true if the CharSegment equals the char array.
 boolean equals(CharSegment cb)
          Returns true if the two char segments are equal.
 boolean equals(java.lang.Object a)
           
 boolean equalsIgnoreCase(CharSegment b)
          Returns true if the two CharSegments are equivalent ignoring the case.
 boolean equalsIgnoreCase(java.lang.String a)
          Returns true if the CharSegment equals the string.
 char[] getBuffer()
          Returns the buffer's char array.
 void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
          Copies characters to the destination buffer.
 char getLastChar()
          Returns the last character of the buffer
 int getLength()
          Returns the buffer length
 int getOffset()
           
 int hashCode()
          Returns the buffer's hash code
 int indexOf(char ch)
          Returns the index of a character in the CharSegment.
 int indexOf(char ch, int start)
          Returns the index of a character in the CharSegment starting from an offset.
 void init(char[] buffer, int offset, int length)
          Sets the char segment to a new buffer triple.
 int lastIndexOf(char ch)
          Returns the last index of a character in the CharSegment.
 int lastIndexOf(char ch, int start)
          Returns the last index of a character in the CharSegment starting from an offset.
 int length()
          Returns the character count of the buffer's contents.
 boolean matches(java.lang.Object a)
           
 boolean matches(java.lang.String sa)
          Returns true if the charSegment matches the string.
 boolean matchesIgnoreCase(java.lang.String sa)
          Returns true if the CharSegment matches the string, ignoring the case.
 boolean regionMatches(int off1, CharSegment buf, int off2, int len)
           
 boolean regionMatches(int off1, java.lang.String buf, int off2, int len)
           
 boolean regionMatchesIgnoreCase(int off1, CharSegment buf, int off2, int len)
           
 boolean startsWith(java.lang.String string)
          Returns true if the CharSegment starts with the string.
 java.lang.String substring(int start)
          Returns a substring
 java.lang.String substring(int start, int end)
          Returns a substring
 CharSegment toLowerCase()
          Converts the contents of the segment to lower case.
 java.lang.String toString()
          String representation of the buffer.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

buffer

protected char[] buffer

offset

protected int offset

length

protected int length
Constructor Detail

CharSegment

public CharSegment()

CharSegment

public CharSegment(char[] buffer,
                   int offset,
                   int length)
Constructs a char segment based on a char array.
Method Detail

init

public void init(char[] buffer,
                 int offset,
                 int length)
Sets the char segment to a new buffer triple.

length

public int length()
Returns the character count of the buffer's contents.

getLength

public int getLength()
Returns the buffer length

getOffset

public int getOffset()

charAt

public char charAt(int i)
Returns the char at the specified offset.

getLastChar

public char getLastChar()
Returns the last character of the buffer
Throws:
IndexOutOfBoundsException - for an empty buffer

getBuffer

public char[] getBuffer()
Returns the buffer's char array.

getChars

public void getChars(int srcBegin,
                     int srcEnd,
                     char[] dst,
                     int dstBegin)
Copies characters to the destination buffer.

substring

public java.lang.String substring(int start)
Returns a substring

substring

public java.lang.String substring(int start,
                                  int end)
Returns a substring

indexOf

public int indexOf(char ch)
Returns the index of a character in the CharSegment.

indexOf

public int indexOf(char ch,
                   int start)
Returns the index of a character in the CharSegment starting from an offset.

lastIndexOf

public int lastIndexOf(char ch)
Returns the last index of a character in the CharSegment.

lastIndexOf

public int lastIndexOf(char ch,
                       int start)
Returns the last index of a character in the CharSegment starting from an offset.

hashCode

public int hashCode()
Returns the buffer's hash code
Overrides:
hashCode in class java.lang.Object

equals

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

equals

public final boolean equals(CharSegment cb)
Returns true if the two char segments are equal.

equals

public final boolean equals(char[] cb,
                            int length)
Returns true if the CharSegment equals the char array.

equalsIgnoreCase

public final boolean equalsIgnoreCase(java.lang.String a)
Returns true if the CharSegment equals the string.

equalsIgnoreCase

public final boolean equalsIgnoreCase(CharSegment b)
Returns true if the two CharSegments are equivalent ignoring the case.

matches

public boolean matches(java.lang.Object a)

matches

public boolean matches(java.lang.String sa)
Returns true if the charSegment matches the string.

matchesIgnoreCase

public boolean matchesIgnoreCase(java.lang.String sa)
Returns true if the CharSegment matches the string, ignoring the case.

regionMatches

public boolean regionMatches(int off1,
                             CharSegment buf,
                             int off2,
                             int len)

regionMatches

public boolean regionMatches(int off1,
                             java.lang.String buf,
                             int off2,
                             int len)

regionMatchesIgnoreCase

public boolean regionMatchesIgnoreCase(int off1,
                                       CharSegment buf,
                                       int off2,
                                       int len)

startsWith

public boolean startsWith(java.lang.String string)
Returns true if the CharSegment starts with the string.

endsWith

public boolean endsWith(java.lang.String string)
Returns true if the CharSegment ends with the string.

endsWith

public boolean endsWith(CharSegment cb)
Returns true if the CharSegment ends with the char segment.

toLowerCase

public CharSegment toLowerCase()
Converts the contents of the segment to lower case.

toString

public java.lang.String toString()
String representation of the buffer.
Overrides:
toString in class java.lang.Object