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

io.virtdata.basicsmappers.from_long.to_string.MapTemplate Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package io.virtdata.basicsmappers.from_long.to_string;

import io.virtdata.annotations.ThreadSafeMapper;

import java.util.HashMap;
import java.util.Map;
import java.util.function.LongFunction;
import java.util.function.LongToIntFunction;

@ThreadSafeMapper
public class MapTemplate implements LongFunction> {

    private final LongToIntFunction sizeFunc;
    private final LongFunction keyFunc;
    private final LongFunction valueFunc;

    public MapTemplate(LongToIntFunction sizeFunc,
                       LongFunction keyFunc,
                       LongFunction valueFunc) {
        this.sizeFunc = sizeFunc;
        this.keyFunc = keyFunc;
        this.valueFunc = valueFunc;
    }

    @Override
    public Map apply(long value) {
        int size = sizeFunc.applyAsInt(value);
        HashMap map = new HashMap<>(size);
        for (int i = 0; i < size; i++) {
            map.put(keyFunc.apply(value+i),valueFunc.apply(value+i));
        }
        return map;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy