package dev.zontreck.ariaslib.util; import java.util.HashMap; import java.util.Map; /** * Utility class to assist in creating a dictionary programmatically in one line of code. */ public class Maps { /** * This takes a list of entries and returns a HashMap * @param entries The entries you want in your hashmap * @return The map itself * @param Any typed parameter * @param Any typed parameter */ public static Map of(Entry... entries) { Map map = new HashMap<>(); for(Entry E : entries) { map.put(E.key, E.value); } return map; } /** * A virtual entry used only by the Maps#of function. * @see Maps#of(Entry[]) * @param Any typed parameter * @param Any typed parameter */ public static class Entry { public final A key; public final B value; /** * Initializes the readonly entry * @param a The dictionary key * @param b The value */ public Entry(A a, B b) { this.key=a; this.value=b; } } }