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

com.kolibrifx.common.collections.Maps Maven / Gradle / Ivy

/*
 * Copyright (c) 2010-2017, KolibriFX AS. Licensed under the Apache License, version 2.0.
 */

package com.kolibrifx.common.collections;

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

public final class Maps {

    private Map map;

    private Maps(final Supplier> mapSupplier) {
        this.map = mapSupplier.get();
    }

    public Maps add(final K k, final V v) {
        map.put(k, v);
        return this;
    }

    public Maps all(final Map d) {
        map.putAll(d);
        return this;
    }

    public Map build() {
        map = Collections.unmodifiableMap(map);
        return map;
    }

    public static  Maps newHashMap() {
        return new Maps<>(HashMap::new);
    }

    public static  Maps newHashMap(final K key, final V value) {
        final Maps maps = new Maps<>(HashMap::new);
        return maps.add(key, value);
    }

    public static  Maps newMap(final Supplier> mapSupplier) {
        return new Maps<>(mapSupplier);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy