Package com.streambase.sb
Class Tuple.DefaultTupleFormatter
- java.lang.Object
-
- com.streambase.sb.Tuple.DefaultTupleFormatter
-
- All Implemented Interfaces:
Tuple.TupleFormatter
- Enclosing class:
- Tuple
public static class Tuple.DefaultTupleFormatter extends Object implements Tuple.TupleFormatter
A default formatter that converts each type to String using Java default String conversions. The intent of this formatter is human consumption, not CSV parsing. Special formatting is performed for:- Timestamp, via
Timestamp.toString() - Blobs, displayed in their entirety as Strings (using US-ASCII characters, or
the charset declared via the
streambase.tuple-charsetsystem property) - Tuples, displayed as a comma-separated string of each of its field's stringification using this formatter
- Lists, displayed as a [] enclosed string of each element stringified using this formatter, delimited by comma
- Functions, displayed using a JSON syntax
- Null values, returned as
Tuple.NULL_STRING
A shared instance is available at
Tuple.getTupleFormatter().- Since:
- 7.1 this formatter is now used recursively for list elements and tuple sub-fields
-
-
Constructor Summary
Constructors Constructor Description DefaultTupleFormatter()See the class documentation forTuple.DefaultTupleFormatterfor details
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CharSequenceformatBlob(ByteArrayView blob)Return a string representation of the given StreamBase blob valueCharSequenceformatBool(Boolean b)Return a string representation of the given StreamBase boolean valueCharSequenceformatDouble(Double d)Return a string representation of the given StreamBase double valueCharSequenceformatFunction(Function f)Return a string representation of the given StreamBase functionCharSequenceformatInt(Integer i)Return a string representation of the given StreamBase integer valueCharSequenceformatList(CompleteDataType elementType, List<?> l)Return a string representation of the given StreamBase listCharSequenceformatLong(Long l)Return a string representation of the given StreamBase long valueCharSequenceformatString(String s)Return a string representation of the given StreamBase string valueCharSequenceformatTimestamp(Timestamp t)Return a string representation of the given StreamBase timestamp valueCharSequenceformatTuple(Tuple t)Return a string representation of the given StreamBase Tuple valueprotected StringgetNullString()This value will be returned by this formatter when any null field value is asked to be formatted.
-
-
-
Constructor Detail
-
DefaultTupleFormatter
public DefaultTupleFormatter()
See the class documentation forTuple.DefaultTupleFormatterfor details
-
-
Method Detail
-
getNullString
protected String getNullString()
This value will be returned by this formatter when any null field value is asked to be formatted. Clients may override.- Returns:
- by default, this implementation returns
Tuple.NULL_STRING
-
formatBlob
public CharSequence formatBlob(ByteArrayView blob)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase blob value- Specified by:
formatBlobin interfaceTuple.TupleFormatter- Parameters:
blob- may be null- Returns:
- a non-null string representation of the value given
-
formatTimestamp
public CharSequence formatTimestamp(Timestamp t)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase timestamp value- Specified by:
formatTimestampin interfaceTuple.TupleFormatter- Parameters:
t- may be null- Returns:
- a non-null string representation of the value given
-
formatString
public CharSequence formatString(String s)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase string value- Specified by:
formatStringin interfaceTuple.TupleFormatter- Parameters:
s- may be null- Returns:
- a non-null string representation of the value given
-
formatInt
public CharSequence formatInt(Integer i)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase integer value- Specified by:
formatIntin interfaceTuple.TupleFormatter- Parameters:
i- may be null- Returns:
- a non-null string representation of the value given
-
formatDouble
public CharSequence formatDouble(Double d)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase double value- Specified by:
formatDoublein interfaceTuple.TupleFormatter- Parameters:
d- may be null- Returns:
- a non-null string representation of the value given
-
formatLong
public CharSequence formatLong(Long l)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase long value- Specified by:
formatLongin interfaceTuple.TupleFormatter- Parameters:
l- may be null- Returns:
- a non-null string representation of the value given
-
formatBool
public CharSequence formatBool(Boolean b)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase boolean value- Specified by:
formatBoolin interfaceTuple.TupleFormatter- Parameters:
b- may be null- Returns:
- a non-null string representation of the value given
-
formatTuple
public CharSequence formatTuple(Tuple t)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase Tuple value- Specified by:
formatTuplein interfaceTuple.TupleFormatter- Parameters:
t- may be null- Returns:
- a non-null string representation of the value given
-
formatList
public CharSequence formatList(CompleteDataType elementType, List<?> l)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase list- Specified by:
formatListin interfaceTuple.TupleFormatter- Parameters:
elementType- the data type of all list elementsl- may be null- Returns:
- a non-null string representation of the value given
-
formatFunction
public CharSequence formatFunction(Function f)
Description copied from interface:Tuple.TupleFormatterReturn a string representation of the given StreamBase function- Specified by:
formatFunctionin interfaceTuple.TupleFormatter- Parameters:
f- may be null- Returns:
- a non-null string representation of the value given
-
-