io.tarantool.driver.mappers.converters.value.ArrayValueToMultiValueListConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cartridge-driver Show documentation
Show all versions of cartridge-driver Show documentation
Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework
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