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

rx.marble.MapHelper Maven / Gradle / Ivy

There is a newer version: 1.3
Show newest version
package rx.marble;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Helper inspired from guava's ImmutableMap.of() factory method
 */
public class MapHelper {

    public static  Map of(String k, V v) {
        return Collections.singletonMap(k,v);
    }

    public static  Map of(String k1, V v1, String k2, V v2) {
        Map map = new HashMap<>();
        map.put(k1, v1);
        map.put(k2, v2);
        return map;
    }

    public static  Map of(String k1, V v1, String k2, V v2, String k3, V v3) {
        Map result = of(k1, v1, k2, v2);
        result.put(k3, v3);
        return result;
    }

    public static  Map of(String k1, V v1, String k2, V v2, String k3, V v3, String k4, V v4) {
        Map result = of(k1, v1, k2, v2, k3, v3);
        result.put(k4, v4);
        return result;
    }

    public static  Map of(String k1, V v1, String k2, V v2, String k3, V v3, String k4, V v4, String k5, V v5) {
        Map result = of(k1, v1, k2, v2, k3, v3, k4, v4);
        result.put(k5, v5);
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy