All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dongliu.commons.collection.ExHashMap Maven / Gradle / Ivy

The newest version!
package net.dongliu.commons.collection;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Expanded hash map
 *
 * @author Liu Dong
 */
public class ExHashMap extends HashMap implements ExMap {
    private static final long serialVersionUID = 5987932063950184578L;

    public ExHashMap(int initialCapacity, float loadFactor) {
        super(initialCapacity, loadFactor);
    }

    public ExHashMap(int initialCapacity) {
        super(initialCapacity);
    }

    public ExHashMap() {
    }

    public ExHashMap(Map m) {
        super(m);
    }

    /**
     * Create mutable empty map
     */
    public static  ExHashMap of() {
        return new ExHashMap<>();
    }

    /**
     * Create mutable map
     */
    @SafeVarargs
    public static  ExHashMap of(Pair... pairs) {
        ExHashMap map = new ExHashMap<>();
        for (Pair pair : pairs) {
            map.put(pair.getKey(), pair.getValue());
        }
        return map;
    }

    /**
     * Create mutable map
     */
    public static  ExHashMap of(Collection> pairs) {
        ExHashMap map = new ExHashMap<>();
        for (Pair pair : pairs) {
            map.put(pair.getKey(), pair.getValue());
        }
        return map;
    }


    /**
     * create mutable map
     */
    public static  ExHashMap of(K key, V value) {
        ExHashMap map = new ExHashMap<>();
        map.put(key, value);
        return map;
    }

    /**
     * create mutable map
     */
    public static  ExHashMap of(K key1, V value1,
                                            K key2, V value2) {
        ExHashMap map = new ExHashMap<>();
        map.put(key1, value1);
        map.put(key2, value2);
        return map;
    }

    /**
     * create mutable map
     */
    public static  ExHashMap of(K key1, V value1,
                                            K key2, V value2,
                                            K key3, V value3) {
        ExHashMap map = new ExHashMap<>();
        map.put(key1, value1);
        map.put(key2, value2);
        map.put(key3, value3);
        return map;
    }

    /**
     * create mutable map
     */
    public static  ExHashMap of(K key1, V value1,
                                            K key2, V value2,
                                            K key3, V value3,
                                            K key4, V value4) {
        ExHashMap map = new ExHashMap<>();
        map.put(key1, value1);
        map.put(key2, value2);
        map.put(key3, value3);
        map.put(key4, value4);
        return map;
    }

    /**
     * create mutable map
     */
    public static  ExHashMap of(K key1, V value1,
                                            K key2, V value2,
                                            K key3, V value3,
                                            K key4, V value4,
                                            K key5, V value5) {
        ExHashMap map = new ExHashMap<>();
        map.put(key1, value1);
        map.put(key2, value2);
        map.put(key3, value3);
        map.put(key4, value4);
        map.put(key5, value5);
        return map;
    }

    /**
     * create mutable map
     */
    public static  ExHashMap of(K key1, V value1,
                                            K key2, V value2,
                                            K key3, V value3,
                                            K key4, V value4,
                                            K key5, V value5,
                                            K key6, V value6) {
        ExHashMap map = new ExHashMap<>();
        map.put(key1, value1);
        map.put(key2, value2);
        map.put(key3, value3);
        map.put(key4, value4);
        map.put(key5, value5);
        map.put(key6, value6);
        return map;
    }

    /**
     * create mutable map
     */
    public static  ExHashMap of(K key1, V value1,
                                            K key2, V value2,
                                            K key3, V value3,
                                            K key4, V value4,
                                            K key5, V value5,
                                            K key6, V value6,
                                            K key7, V value7) {
        ExHashMap map = new ExHashMap<>();
        map.put(key1, value1);
        map.put(key2, value2);
        map.put(key3, value3);
        map.put(key4, value4);
        map.put(key5, value5);
        map.put(key6, value6);
        map.put(key7, value7);
        return map;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy