com.robertboothby.djenni.util.MapSupplierHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
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.
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 extends K> keys, Supplier extends V> 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);
};
}
}