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

com.robertboothby.djenni.util.MapSupplierHelper Maven / Gradle / Ivy

Go to download

This module holds the core components of the Djenni data generator framework. By itself it provides most of the components to create an efficient end to end data generation framework for a specific domain. It contains the core SupplierBuilder interfaces, implementations for the core Java data types and useful test components. It is intended to be used in conjunction with the source-generator module that will speed up delivery of domain specific data generation and also with common domain modules (TBD) that deliver standard generators for common frameworks such as JAXB.

There is a newer version: 0.2.0
Show newest version
package com.robertboothby.djenni.util;

import com.robertboothby.djenni.core.StreamableSupplier;

import java.util.AbstractMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * This class contains static utility methods to make it easier to work with Maps.
 */
public class MapSupplierHelper {

    /**
     * Create a supplier of Map.Entry based on the key and value suppliers passed in.
     * @param keys The supplier of keys.
     * @param values The supplier of values.
     * @param  The type of the keys.
     * @param  The type of the values.
     * @return A supplier of map entries.
     */
    public static  Supplier> supplyEntries(Supplier keys, Supplier values){
        return () -> new AbstractMap.SimpleImmutableEntry<>(keys.get(), values.get());
    }

    /**
     * Create a supplier of Map.Entry based on a key supplier and a function that derives the value from the key.
     * @param keys The key supplier.
     * @param values The function that will derive the value from the key
     * @param  The type of the key.
     * @param  THe type of the value.
     * @return A supplier of map entries.
     */
    public static  StreamableSupplier> supplyEntries(Supplier keys, Function values) {
        return () -> {
            K key = keys.get();
            return new AbstractMap.SimpleImmutableEntry<>(key, values.apply(key));
        };
    }

    /**
     * Create a supplier of Map.Entry based on a value supplier and a function that derives the key from the value.
     * @param keys The function that will derive the key from the value.
     * @param values The value supplier.
     * @param  The type of the key.
     * @param  THe type of the value.
     * @return A supplier of map entries.
     */
    public static  Supplier> supplyEntries(Function keys, Supplier values) {
        return () -> {
            V value = values.get();
            return new AbstractMap.SimpleImmutableEntry<>(keys.apply(value), value);
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy