org.mobicents.media.server.utils
Class Text

java.lang.Object
  extended by org.mobicents.media.server.utils.Text
All Implemented Interfaces:
CharSequence
Direct Known Subclasses:
EncodingName

public class Text
extends Object
implements CharSequence

Case insensitive text block representation. This class provides time deterministic and fast methods for creating and comparing short character strings like format names, attribute values, etc.

Author:
kulikov

Field Summary
protected  byte[] chars
           
protected  int len
           
protected  int pos
           
 
Constructor Summary
  Text()
          Create an empty text object.
  Text(byte[] data, int pos, int len)
          Creates new instance and straining it into memory.
  Text(int i)
          Creates new text matching to specified integer number.
  Text(String s)
          Creates new instance with specified text.
protected Text(Text another)
          Creates new object with specified text.
 
Method Summary
 char charAt(int index)
          (Non Java-doc.)
 boolean contains(char c)
          Checks does specified symbol is present in this text.
 void copy(Text destination)
          Copies reference to another text object.
 void copyRemainder(Text other)
          Copies substring from the current line upto the end to the specified destination.
 int divide(char[] separators, Text[] parts)
           
 int divide(char separator, Text[] parts)
          Divides text into parts using given separator and writes results into the parts array.
 void duplicate(Text destination)
          Copies data from this buffer to another buffer.
 boolean equals(Object other)
           
 int hashCode()
           
 boolean hasMoreLines()
          Shows is this text contains more lines.
 int length()
          (Non Java-doc.)
 Text nextLine()
          Extracts next line from this text.
 Collection<Text> split(char separator)
          Splits text into partitions.
 void strain(byte[] data, int pos, int len)
          Strains this object into the memory area.
 CharSequence subSequence(int start, int end)
          (Non Java-doc.)
 int toInteger()
          Converts string value to integer
 String toString()
           
 void trim()
          Removes whitespace from the head and tail of the string.
 void write(ByteBuffer buffer)
          Writes this text into byte buffer.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

chars

protected byte[] chars

pos

protected int pos

len

protected int len
Constructor Detail

Text

public Text()
Create an empty text object. This object later can be strained on some memory area


Text

protected Text(Text another)
Creates new object with specified text.

Parameters:
another - the text object.

Text

public Text(String s)
Creates new instance with specified text.

Parameters:
s - the text value.

Text

public Text(int i)
Creates new text matching to specified integer number.

Parameters:
i - the integer number.

Text

public Text(byte[] data,
            int pos,
            int len)
Creates new instance and straining it into memory.

Parameters:
data - memory
pos - initial position
len - the length from the initial position
Method Detail

strain

public void strain(byte[] data,
                   int pos,
                   int len)
Strains this object into the memory area.

Parameters:
data - the memory area
pos - the initial position
len - the length of area to use

length

public int length()
(Non Java-doc.)

Specified by:
length in interface CharSequence
See Also:
CharSequence.length()

charAt

public char charAt(int index)
(Non Java-doc.)

Specified by:
charAt in interface CharSequence
See Also:
CharSequence.charAt(int)

copy

public void copy(Text destination)
Copies reference to another text object.

Parameters:
destination - the another text object

duplicate

public void duplicate(Text destination)
Copies data from this buffer to another buffer.

Parameters:
destination - the pointer to another buffer.

divide

public int divide(char separator,
                  Text[] parts)
Divides text into parts using given separator and writes results into the parts array.

Parameters:
separator - the character used for splitting
parts - the array used to hold parts of the text
Returns:
the number of parts.

divide

public int divide(char[] separators,
                  Text[] parts)

subSequence

public CharSequence subSequence(int start,
                                int end)
(Non Java-doc.)

Specified by:
subSequence in interface CharSequence
See Also:
CharSequence.subSequence(int, int);

split

public Collection<Text> split(char separator)
Splits text into partitions.

Parameters:
separator - character used for partitioning
Returns:
array of text strings.

trim

public void trim()
Removes whitespace from the head and tail of the string.


nextLine

public Text nextLine()
Extracts next line from this text.

Returns:

hasMoreLines

public boolean hasMoreLines()
Shows is this text contains more lines.

Returns:
true if there are more lines

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Specified by:
toString in interface CharSequence
Overrides:
toString in class Object

toInteger

public int toInteger()
Converts string value to integer

Returns:
integer value

write

public void write(ByteBuffer buffer)
Writes this text into byte buffer.

Parameters:
buffer - the buffer for writing.

copyRemainder

public void copyRemainder(Text other)
Copies substring from the current line upto the end to the specified destination.

Parameters:
other - the destination object

contains

public boolean contains(char c)
Checks does specified symbol is present in this text.

Parameters:
c - the character to verify.
Returns:
true if character c is presented in this text and false otherwise.


Copyright © 2011. All Rights Reserved.