com.redis.riot.file.ToMapFunction Maven / Gradle / Ivy
package com.redis.riot.file;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
public class ToMapFunction implements Function> {
private final List extends Function>> functions;
@SuppressWarnings("unchecked")
public ToMapFunction(Function>... functions) {
this(Arrays.asList(functions));
}
public ToMapFunction(List extends Function>> functions) {
Assert.notEmpty(functions, "At least one function must be given");
this.functions = functions;
}
@Override
public Map apply(T t) {
Iterator extends Function>> iterator = functions.iterator();
Map map = iterator.next().apply(t);
while (iterator.hasNext()) {
Map values = iterator.next().apply(t);
if (!CollectionUtils.isEmpty(values)) {
map.putAll(values);
}
}
return map;
}
}