Class MapSerializer<K,V>


public class MapSerializer<K,V> extends CollectionSerializer<T>
  • Field Details

  • Method Details

    • getInstance

      public static <K, V> MapSerializer<K,V> getInstance(TypeSerializer<K> keys, TypeSerializer<V> values, ValueComparators comparators)
    • serializeValues

      public List<ByteBuffer> serializeValues(Map<K,V> map)
      Specified by:
      serializeValues in class CollectionSerializer<Map<K,V>>
    • getElementCount

      public int getElementCount(Map<K,V> value)
      Specified by:
      getElementCount in class CollectionSerializer<Map<K,V>>
    • validate

      public <T> void validate(T input, ValueAccessor<T> accessor)
      Specified by:
      validate in class TypeSerializer<Map<K,V>>
    • deserialize

      public <I> Map<K,V> deserialize(I input, ValueAccessor<I> accessor)
      Specified by:
      deserialize in class TypeSerializer<Map<K,V>>
    • getSerializedValue

      public ByteBuffer getSerializedValue(ByteBuffer collection, 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 class CollectionSerializer<Map<K,V>>
      Parameters:
      collection - the serialized collection. This cannot be null.
      key - the key to extract (This cannot be null nor ByteBufferUtil.UNSET_BYTE_BUFFER).
      comparator - the type to use to compare the key value to those in the collection.
      Returns:
      the value associated with key if one exists, null otherwise
    • toString

      public String toString(Map<K,V> value)
      Specified by:
      toString in class TypeSerializer<Map<K,V>>
    • getType

      public Class<Map<K,V>> getType()
      Specified by:
      getType in class TypeSerializer<Map<K,V>>
    • forEach

      public void forEach(ByteBuffer input, Consumer<ByteBuffer> action)
      Overrides:
      forEach in class CollectionSerializer<Map<K,V>>
    • getSliceFromSerialized

      public ByteBuffer getSliceFromSerialized(ByteBuffer collection, ByteBuffer from, 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 class CollectionSerializer<T>
      Parameters:
      collection - the serialized collection. This cannot be null.
      from - the left bound of the slice to extract. This cannot be null but if this is ByteBufferUtil.UNSET_BYTE_BUFFER, then the returned slice starts at the beginning of collection.
      comparator - the type to use to compare the from and to 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] of collection.
    • getIndexFromSerialized

      public int getIndexFromSerialized(ByteBuffer collection, 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 class CollectionSerializer<T>
      Parameters:
      collection - The serialized collection. This cannot be null.
      key - The key for which the index must be found. This cannot be null nor ByteBufferUtil.UNSET_BYTE_BUFFER).
      comparator - The type to use to compare the key 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<Integer> getIndexesRangeFromSerialized(ByteBuffer collection, ByteBuffer from, 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 class CollectionSerializer<T>
      Parameters:
      collection - The serialized collection. This cannot be null.
      from - The left bound of the slice to extract. This cannot be null but if this is ByteBufferUtil.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 be null but if this is ByteBufferUtil.UNSET_BYTE_BUFFER, then the returned slice ends at the end of the collection.
      comparator - The type to use to compare the from and to values to those in the collection.
      Returns:
      The range of indexes corresponding to specified range of elements.