public abstract static class TypeCodec.AbstractCollectionCodec<E,C extends Collection<E>> extends TypeCodec<C>
TypeCodec.AbstractCollectionCodec<E,C extends Collection<E>>, TypeCodec.AbstractMapCodec<K,V>, TypeCodec.AbstractTupleCodec<T>, TypeCodec.AbstractUDTCodec<T>, TypeCodec.PrimitiveBooleanCodec, TypeCodec.PrimitiveByteCodec, TypeCodec.PrimitiveDoubleCodec, TypeCodec.PrimitiveFloatCodec, TypeCodec.PrimitiveIntCodec, TypeCodec.PrimitiveLongCodec, TypeCodec.PrimitiveShortCodec
Modifier | Constructor and Description |
---|---|
protected |
AbstractCollectionCodec(DataType.CollectionType cqlType,
TypeToken<C> javaType,
TypeCodec<E> eltCodec) |
Modifier and Type | Method and Description |
---|---|
boolean |
accepts(Object value)
Return
true if this codec is capable of serializing
the given object. |
C |
deserialize(ByteBuffer bytes,
ProtocolVersion protocolVersion)
Deserialize the given
ByteBuffer instance according to the CQL type
handled by this codec. |
String |
format(C value)
Format the given value as a valid CQL literal according
to the CQL type handled by this codec.
|
protected abstract C |
newInstance(int size)
Return a new instance of
C with the given estimated size. |
C |
parse(String value)
Parse the given CQL literal into an instance of the Java type
handled by this codec.
|
ByteBuffer |
serialize(C value,
ProtocolVersion protocolVersion)
Serialize the given value according to the CQL type
handled by this codec.
|
accepts, accepts, ascii, bigint, blob, cboolean, cdouble, cfloat, cint, counter, custom, date, decimal, getCqlType, getJavaType, inet, list, map, set, smallInt, time, timestamp, timeUUID, tinyInt, toString, tuple, userType, uuid, varchar, varint
protected AbstractCollectionCodec(DataType.CollectionType cqlType, TypeToken<C> javaType, TypeCodec<E> eltCodec)
public ByteBuffer serialize(C value, ProtocolVersion protocolVersion)
TypeCodec
Implementation notes:
null
input as
the equivalent of an empty collection.serialize
in class TypeCodec<C extends Collection<E>>
value
- An instance of T; may be null
.protocolVersion
- the protocol version to use when serializing
bytes
. In most cases, the proper value to provide for this argument
is the value returned by ProtocolOptions.getProtocolVersion()
(which
is the protocol version in use by the driver).ByteBuffer
instance containing the serialized form of Tpublic C deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
TypeCodec
ByteBuffer
instance according to the CQL type
handled by this codec.
Implementation notes:
null
or a default value for the corresponding Java type, if applicable;null
;
they should return empty collections instead (the driver's default collection codecs all comply with this rule).ByteBuffer
should never be consumed by read operations that
modify its current position; if necessary,
ByteBuffer.duplicate()
duplicate} it before consuming.deserialize
in class TypeCodec<C extends Collection<E>>
bytes
- A ByteBuffer
instance containing the serialized form of T;
may be null
or empty.protocolVersion
- the protocol version to use when serializing
bytes
. In most cases, the proper value to provide for this argument
is the value returned by ProtocolOptions.getProtocolVersion()
(which
is the protocol version in use by the driver).public String format(C value)
TypeCodec
"NULL"
for null
inputs.format
in class TypeCodec<C extends Collection<E>>
value
- An instance of T; may be null
.public C parse(String value)
TypeCodec
"NULL"
;
in most cases, implementations should interpret these inputs has equivalent to a null
reference.parse
in class TypeCodec<C extends Collection<E>>
value
- The CQL string to parse, may be null
or empty.null
on a null input
.public boolean accepts(Object value)
TypeCodec
true
if this codec is capable of serializing
the given object. Note that the object's Java type is inferred
from the object' runtime (raw) type, contrary
to TypeCodec.accepts(TypeToken)
which is capable of
handling generic types.
This method is intended mostly to be used by the QueryBuilder when no type information is available when the codec is used.
Implementation notes:
TypeToken.isAssignableFrom(TypeToken)
and it's strongly recommended not to modify this behavior.
This means that, by default, a codec will accept
any subtype of the Java type that it has been created for.accepts
in class TypeCodec<C extends Collection<E>>
value
- The Java type this codec should serialize from and deserialize to; cannot be null
.true
if the codec is capable of serializing
the given javaType
, and false
otherwise.protected abstract C newInstance(int size)
C
with the given estimated size.size
- The estimated size of the collection to create.C
with the given estimated size.