com.caucho.util
Class CharSegment

java.lang.Object
  extended by com.caucho.util.CharSegment
All Implemented Interfaces:
java.lang.CharSequence
Direct Known Subclasses:
CharBuffer

public class CharSegment
extends java.lang.Object
implements java.lang.CharSequence

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(char[] cb, int offset, 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.
 int indexOf(java.lang.String s)
           
 int indexOf(java.lang.String s, int start)
           
 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.CharSequence subSequence(int start, int end)
          Returns a subsequence
 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 final int length()
Returns the character count of the buffer's contents.

Specified by:
length in interface java.lang.CharSequence

getLength

public final int getLength()
Returns the buffer length


getOffset

public final int getOffset()

charAt

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

Specified by:
charAt in interface java.lang.CharSequence

getLastChar

public char getLastChar()
Returns the last character of the buffer

Throws:
java.lang.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


subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
Returns a subsequence

Specified by:
subSequence in interface java.lang.CharSequence

indexOf

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


indexOf

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


lastIndexOf

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


lastIndexOf

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


indexOf

public int indexOf(java.lang.String s)

indexOf

public int indexOf(java.lang.String s,
                   int start)

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


equals

public final boolean equals(char[] cb,
                            int offset,
                            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 final 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.

Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object