Java tutorial
//package com.java2s; //License from project: LGPL import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Supplier; public class Main { /** * The size increase of the created sets and maps to compensate the not full load factor of the maps and sets. */ private static final float SIZE_NORMALIZATION = 1.1f; /** The load factor for maps and sets. */ private static final float LOAD_FACTOR = 0.95f; /** * Create a supplier that provides {@link LinkedHashMap} of the given size. * * @param <K> * the key type * @param <V> * the value type * @param size * the size of the new map * @return the supplier * @see #createLinkedHashMap(int) */ public static <K, V> Supplier<Map<K, V>> provideLinkedHashMap(int size) { return () -> createLinkedHashMap(size); } /** * Creates the linked hash map instance that will hold the given amount of elements. The returned instance is * optimized for that size and will not grow until the given number of elements are added. * <p> * The method is same as <code>new LinkedHashMap<K, V>((int) (size * 1.1), 0.95f)</code> * * @param <K> * the key type * @param <V> * the value type * @param size * the preferred size * @return the map instance */ public static <K, V> Map<K, V> createLinkedHashMap(int size) { return new LinkedHashMap<>((int) (size * SIZE_NORMALIZATION), LOAD_FACTOR); } }