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-charset
system 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.DefaultTupleFormatter
for details
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CharSequence
formatBlob(ByteArrayView blob)
Return a string representation of the given StreamBase blob valueCharSequence
formatBool(Boolean b)
Return a string representation of the given StreamBase boolean valueCharSequence
formatDouble(Double d)
Return a string representation of the given StreamBase double valueCharSequence
formatFunction(Function f)
Return a string representation of the given StreamBase functionCharSequence
formatInt(Integer i)
Return a string representation of the given StreamBase integer valueCharSequence
formatList(CompleteDataType elementType, List<?> l)
Return a string representation of the given StreamBase listCharSequence
formatLong(Long l)
Return a string representation of the given StreamBase long valueCharSequence
formatString(String s)
Return a string representation of the given StreamBase string valueCharSequence
formatTimestamp(Timestamp t)
Return a string representation of the given StreamBase timestamp valueCharSequence
formatTuple(Tuple t)
Return a string representation of the given StreamBase Tuple valueprotected String
getNullString()
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.DefaultTupleFormatter
for 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.TupleFormatter
Return a string representation of the given StreamBase blob value- Specified by:
formatBlob
in 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.TupleFormatter
Return a string representation of the given StreamBase timestamp value- Specified by:
formatTimestamp
in 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.TupleFormatter
Return a string representation of the given StreamBase string value- Specified by:
formatString
in 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.TupleFormatter
Return a string representation of the given StreamBase integer value- Specified by:
formatInt
in 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.TupleFormatter
Return a string representation of the given StreamBase double value- Specified by:
formatDouble
in 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.TupleFormatter
Return a string representation of the given StreamBase long value- Specified by:
formatLong
in 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.TupleFormatter
Return a string representation of the given StreamBase boolean value- Specified by:
formatBool
in 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.TupleFormatter
Return a string representation of the given StreamBase Tuple value- Specified by:
formatTuple
in 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.TupleFormatter
Return a string representation of the given StreamBase list- Specified by:
formatList
in 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.TupleFormatter
Return a string representation of the given StreamBase function- Specified by:
formatFunction
in interfaceTuple.TupleFormatter
- Parameters:
f
- may be null- Returns:
- a non-null string representation of the value given
-
-