net.sf.asyncobjects.io
Class TextData

java.lang.Object
  extended by net.sf.asyncobjects.io.TextData
All Implemented Interfaces:
Serializable, CharSequence, Comparable<TextData>, BatchedData<TextData>

public class TextData
extends Object
implements CharSequence, BatchedData<TextData>, Serializable

A textual data batch. It has fast concat access and iteration but slow charAt(int).

Author:
const
See Also:
Serialized Form

Field Summary
static TextData EMPTY
          empty text data
 
Method Summary
 char charAt(int index)
           
 int compareTo(TextData o)
          Compare text data
static TextData concat(TextData... toConcat)
          Concatenate text data
 TextData concat(TextData data)
          Concatenate
 TextData drop(int n)
          Get new data with first n elements dropped
static TextData empty()
           
 boolean equals(Object obj)
           
 TextData flatten()
           
static TextData fromStrings(String... strings)
          Create text data from sequence of strings
static TextData get(CharBuffer cb)
          Get text data from character buffer
 int hashCode()
          Implemetned like String.hashCode()
 TextData head(int n)
          Get data with first n elements
 boolean isEmpty()
           
 CharacterIterator iterator()
           
 int length()
           
 Promise<TextData> promise()
          Return a promise that wraps this value
 TextData put(CharBuffer cb)
          Put data to character buffer
 TextData subrange(int start, int end)
          Get subrange of data
 TextData subSequence(int start, int end)
           
 String toString()
           
 String[] toStrings()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final TextData EMPTY
empty text data

Method Detail

concat

public static TextData concat(TextData... toConcat)
Concatenate text data

Parameters:
toConcat - data to concat
Returns:
a text data that represents concatentated array

fromStrings

public static TextData fromStrings(String... strings)
Create text data from sequence of strings

Parameters:
strings - a data to create
Returns:
created data

empty

public static TextData empty()
Returns:
empty text data

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface BatchedData<TextData>
Returns:
true if this data is empty

charAt

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

length

public int length()
Specified by:
length in interface CharSequence
Specified by:
length in interface BatchedData<TextData>
Returns:
length of data
See Also:
CharSequence.length()

subSequence

public TextData subSequence(int start,
                            int end)
Specified by:
subSequence in interface CharSequence
See Also:
CharSequence.subSequence(int, int)

concat

public TextData concat(TextData data)
Concatenate

Specified by:
concat in interface BatchedData<TextData>
Parameters:
data - a text data to concat with
Returns:
concatenated data
See Also:
BatchedData.concat(net.sf.asyncobjects.io.BatchedData)

drop

public TextData drop(int n)
Description copied from interface: BatchedData
Get new data with first n elements dropped

Specified by:
drop in interface BatchedData<TextData>
Parameters:
n - cut point
Returns:
data after position
See Also:
BatchedData.drop(int)

head

public TextData head(int n)
Description copied from interface: BatchedData
Get data with first n elements

Specified by:
head in interface BatchedData<TextData>
Parameters:
n - amount to cut from beginning of the data
Returns:
data with first n bytes of the data
See Also:
BatchedData.head(int)

subrange

public TextData subrange(int start,
                         int end)
Description copied from interface: BatchedData
Get subrange of data

Specified by:
subrange in interface BatchedData<TextData>
Parameters:
start - a start posiion
end - a limit
Returns:
a data that represents subrange
See Also:
BatchedData.subrange(int, int)

iterator

public CharacterIterator iterator()
Returns:
an iterator that is positioned before the first character

compareTo

public int compareTo(TextData o)
Compare text data

Specified by:
compareTo in interface Comparable<TextData>
Parameters:
o - compare to
Returns:
comparison result
See Also:
Comparable.compareTo(java.lang.Object)

promise

public Promise<TextData> promise()
Description copied from interface: BatchedData
Return a promise that wraps this value

Specified by:
promise in interface BatchedData<TextData>
Returns:
a promise
See Also:
BatchedData.promise()

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Implemetned like String.hashCode()

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

put

public TextData put(CharBuffer cb)
Put data to character buffer

Parameters:
cb - a char buffer to use
Returns:
remander of the data

get

public static TextData get(CharBuffer cb)
Get text data from character buffer

Parameters:
cb - a character buffer
Returns:
a text data

toStrings

public String[] toStrings()
Returns:
a list of strings that compose this text data

toString

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

flatten

public TextData flatten()
Returns:
a flattened object that consists only of one segment


Copyright 2002-2007 Constantine Plotnikov. All Rights Reserved.