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

com.redis.riot.file.ToMapFunction Maven / Gradle / Ivy

There is a newer version: 4.1.9
Show newest version
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>> functions;

    @SuppressWarnings("unchecked")
    public ToMapFunction(Function>... functions) {
        this(Arrays.asList(functions));

    }

    public ToMapFunction(List>> functions) {
        Assert.notEmpty(functions, "At least one function must be given");
        this.functions = functions;
    }

    @Override
    public Map apply(T t) {
        Iterator>> 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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy