io.virtdata.libbasics.shared.from_long.to_collection.StringMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
package io.virtdata.libbasics.shared.from_long.to_collection;
import io.virtdata.annotations.*;
import java.util.HashMap;
import java.util.function.LongFunction;
import java.util.function.LongToIntFunction;
/**
* Create a {@code Map} from a long input
* based on three functions,
* the first to determine the map size, and the second to populate
* the map with key objects, and the third to populate the map with
* value objects. The long input fed to the second and third functions
* is incremented between entries. Regardless of the object type provided
* by the second and third functions, {@link java.lang.Object#toString()}
* is used to determine the key and value to add to the map.
*
* To create Maps of any key and value types, simply use {@link Map} with
* an specific key and value mapping functions.
*/
@Categories({Category.collections})
@ThreadSafeMapper
public class StringMap implements LongFunction> {
private final LongToIntFunction sizeFunc;
private final LongFunction[] keyFuncs;
private final LongFunction[] valueFuncs;
private final Mode mode;
@Example({"StringMap(HashRange(3,7),NumberNameToString(),HashRange(1300,1700))",
"create a map of size 3-7 entries, with a key of type " +
"string and a value of type int (Integer by autoboxing)"})
public StringMap(LongToIntFunction sizeFunc,
LongFunction