All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.tarantool.driver.mappers.converters.value.ArrayValueToMultiValueListConverter Maven / Gradle / Ivy

Go to download

Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework

There is a newer version: 0.14.0
Show newest version
package io.tarantool.driver.mappers.converters.value;

import io.tarantool.driver.mappers.converters.ValueConverter;
import org.msgpack.value.ArrayValue;
import org.msgpack.value.Value;

import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
 * {@link ArrayValue} to {@link List} converter for given item type
 *
 * @author Alexey Kuzin
 */
public class ArrayValueToMultiValueListConverter, V extends Value>
    implements ValueConverter {

    private static final long serialVersionUID = 20200708L;

    private final ValueConverter valueConverter;
    private final Supplier containerSupplier;

    /**
     * Basic constructor
     *
     * @param valueConverter    converter for result items
     * @param containerSupplier supplier for an empty collection of the result type
     */
    public ArrayValueToMultiValueListConverter(ValueConverter valueConverter, Supplier containerSupplier) {
        this.valueConverter = valueConverter;
        this.containerSupplier = containerSupplier;
    }

    @Override
    public R fromValue(ArrayValue value) {
        return value.list().stream()
            .map(v -> valueConverter.fromValue((V) v))
            .collect(Collectors.toCollection(containerSupplier));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy