package org.zwobble.mammoth.internal.util; import com.google.common.collect.ImmutableMap; import java.util.Map; import java.util.Optional; import java.util.function.Function; public class MammothMaps { public static Map map() { return ImmutableMap.of(); } public static Map map(K key1, V value1) { return ImmutableMap.of(key1, value1); } public static Map map(K key1, V value1, K key2, V value2) { return ImmutableMap.of(key1, value1, key2, value2); } public static Map map(K key1, V value1, K key2, V value2, K key3, V value3) { return ImmutableMap.of(key1, value1, key2, value2, key3, value3); } public static Optional lookup(Map map, K key) { return Optional.ofNullable(map.get(key)); } public static Map toMap(Iterable iterable, Function> function) { ImmutableMap.Builder builder = ImmutableMap.builder(); for (T element : iterable) { builder.put(function.apply(element)); } return builder.build(); } }