Package org.apache.cassandra.serializers
Class ListSerializer<T>
- java.lang.Object
-
- org.apache.cassandra.serializers.TypeSerializer<T>
-
- org.apache.cassandra.serializers.CollectionSerializer<java.util.List<T>>
-
- org.apache.cassandra.serializers.ListSerializer<T>
-
public class ListSerializer<T> extends CollectionSerializer<java.util.List<T>>
-
-
Field Summary
Fields Modifier and Type Field Description TypeSerializer<T>
elements
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
anyMatch(java.nio.ByteBuffer serializedList, java.util.function.Predicate<java.nio.ByteBuffer> predicate)
<V> boolean
anyMatch(V input, ValueAccessor<V> accessor, java.util.function.Predicate<V> predicate)
<V> java.util.List<T>
deserialize(V input, ValueAccessor<V> accessor)
java.nio.ByteBuffer
getElement(java.nio.ByteBuffer input, int index)
<V> V
getElement(V input, ValueAccessor<V> accessor, int index)
Returns the element at the given index in a list.int
getElementCount(java.util.List<T> value)
com.google.common.collect.Range<java.lang.Integer>
getIndexesRangeFromSerialized(java.nio.ByteBuffer collection, java.nio.ByteBuffer from, java.nio.ByteBuffer to, AbstractType<?> comparator)
Returns the range of indexes corresponding to the specified range of elements in the serialized collection.int
getIndexFromSerialized(java.nio.ByteBuffer collection, java.nio.ByteBuffer key, AbstractType<?> comparator)
Returns the index of an element in a serialized collection.static <T> ListSerializer<T>
getInstance(TypeSerializer<T> elements)
java.nio.ByteBuffer
getSerializedValue(java.nio.ByteBuffer collection, java.nio.ByteBuffer key, AbstractType<?> comparator)
Extract an element from a serialized collection.java.nio.ByteBuffer
getSliceFromSerialized(java.nio.ByteBuffer collection, java.nio.ByteBuffer from, java.nio.ByteBuffer to, AbstractType<?> comparator, boolean frozen)
Returns the slice of a collection directly from its serialized value.java.lang.Class<java.util.List<T>>
getType()
protected java.util.List<java.nio.ByteBuffer>
serializeValues(java.util.List<T> values)
java.lang.String
toString(java.util.List<T> value)
<V> void
validate(V input, ValueAccessor<V> accessor)
-
Methods inherited from class org.apache.cassandra.serializers.CollectionSerializer
copyAsNewCollection, forEach, pack, pack, readCollectionSize, readNonNullValue, readValue, serialize, sizeOfCollectionSize, sizeOfValue, skipValue, skipValue, writeCollectionSize, writeValue
-
Methods inherited from class org.apache.cassandra.serializers.TypeSerializer
deserialize, isNull, isNull, shouldQuoteCQLLiterals, toCQLLiteral, toCQLLiteralNonNull, toCQLLiteralNoQuote, validate
-
-
-
-
Field Detail
-
elements
public final TypeSerializer<T> elements
-
-
Method Detail
-
getInstance
public static <T> ListSerializer<T> getInstance(TypeSerializer<T> elements)
-
serializeValues
protected java.util.List<java.nio.ByteBuffer> serializeValues(java.util.List<T> values)
- Specified by:
serializeValues
in classCollectionSerializer<java.util.List<T>>
-
getElementCount
public int getElementCount(java.util.List<T> value)
- Specified by:
getElementCount
in classCollectionSerializer<java.util.List<T>>
-
validate
public <V> void validate(V input, ValueAccessor<V> accessor)
- Specified by:
validate
in classTypeSerializer<java.util.List<T>>
-
deserialize
public <V> java.util.List<T> deserialize(V input, ValueAccessor<V> accessor)
- Specified by:
deserialize
in classTypeSerializer<java.util.List<T>>
-
anyMatch
public boolean anyMatch(java.nio.ByteBuffer serializedList, java.util.function.Predicate<java.nio.ByteBuffer> predicate)
-
anyMatch
public <V> boolean anyMatch(V input, ValueAccessor<V> accessor, java.util.function.Predicate<V> predicate)
-
getElement
public <V> V getElement(V input, ValueAccessor<V> accessor, int index)
Returns the element at the given index in a list.- Parameters:
input
- a serialized listindex
- the index to get- Returns:
- the serialized element at the given index, or null if the index exceeds the list size
-
getElement
public java.nio.ByteBuffer getElement(java.nio.ByteBuffer input, int index)
-
toString
public java.lang.String toString(java.util.List<T> value)
- Specified by:
toString
in classTypeSerializer<java.util.List<T>>
-
getType
public java.lang.Class<java.util.List<T>> getType()
- Specified by:
getType
in classTypeSerializer<java.util.List<T>>
-
getSerializedValue
public java.nio.ByteBuffer getSerializedValue(java.nio.ByteBuffer collection, java.nio.ByteBuffer key, AbstractType<?> comparator)
Description copied from class:CollectionSerializer
Extract an element from a serialized collection.Note that this is only supported to sets and maps. For sets, this mostly ends up being a check for the presence of the provide key: it will return the key if it's present and
null
otherwise.- Specified by:
getSerializedValue
in classCollectionSerializer<java.util.List<T>>
- Parameters:
collection
- the serialized collection. This cannot benull
.key
- the key to extract (This cannot benull
norByteBufferUtil.UNSET_BYTE_BUFFER
).comparator
- the type to use to compare thekey
value to those in the collection.- Returns:
- the value associated with
key
if one exists,null
otherwise
-
getSliceFromSerialized
public java.nio.ByteBuffer getSliceFromSerialized(java.nio.ByteBuffer collection, java.nio.ByteBuffer from, java.nio.ByteBuffer to, AbstractType<?> comparator, boolean frozen)
Description copied from class:CollectionSerializer
Returns the slice of a collection directly from its serialized value.If the slice contains no elements an empty collection will be returned for frozen collections, and a
null
one for non-frozen collections.- Specified by:
getSliceFromSerialized
in classCollectionSerializer<java.util.List<T>>
- Parameters:
collection
- the serialized collection. This cannot benull
.from
- the left bound of the slice to extract. This cannot benull
but if this isByteBufferUtil.UNSET_BYTE_BUFFER
, then the returned slice starts at the beginning ofcollection
.comparator
- the type to use to compare thefrom
andto
values to those in the collection.frozen
-true
if the collection is a frozen one,false
otherwise- Returns:
- a serialized collection corresponding to slice
[from, to]
ofcollection
.
-
getIndexFromSerialized
public int getIndexFromSerialized(java.nio.ByteBuffer collection, java.nio.ByteBuffer key, AbstractType<?> comparator)
Description copied from class:CollectionSerializer
Returns the index of an element in a serialized collection.Note that this is only supported by sets and maps, but not by lists.
- Specified by:
getIndexFromSerialized
in classCollectionSerializer<java.util.List<T>>
- Parameters:
collection
- The serialized collection. This cannot benull
.key
- The key for which the index must be found. This cannot benull
norByteBufferUtil.UNSET_BYTE_BUFFER
).comparator
- The type to use to compare thekey
value to those in the collection.- Returns:
- The index of the element associated with
key
if one exists,-1
otherwise.
-
getIndexesRangeFromSerialized
public com.google.common.collect.Range<java.lang.Integer> getIndexesRangeFromSerialized(java.nio.ByteBuffer collection, java.nio.ByteBuffer from, java.nio.ByteBuffer to, AbstractType<?> comparator)
Description copied from class:CollectionSerializer
Returns the range of indexes corresponding to the specified range of elements in the serialized collection.Note that this is only supported by sets and maps, but not by lists.
- Specified by:
getIndexesRangeFromSerialized
in classCollectionSerializer<java.util.List<T>>
- Parameters:
collection
- The serialized collection. This cannot benull
.from
- The left bound of the slice to extract. This cannot benull
but if this isByteBufferUtil.UNSET_BYTE_BUFFER
, then the returned slice starts at the beginning of the collection.to
- The left bound of the slice to extract. This cannot benull
but if this isByteBufferUtil.UNSET_BYTE_BUFFER
, then the returned slice ends at the end of the collection.comparator
- The type to use to compare thefrom
andto
values to those in the collection.- Returns:
- The range of indexes corresponding to specified range of elements.
-
-