package com.bocloud.ims.entity.common;

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

public class MapBuilder<K, V> {

    private final Map<K, V> map;

    public MapBuilder(Map<K, V> map) {
        this.map = map;
    }

    public static MapBuilder<String, Object> init() {
        Map<String, Object> map = new HashMap<>();
        return new MapBuilder<>(map);
    }

    public static <K, V> MapBuilder<K, V> init(Supplier<Map<K, V>> init) {
        Map<K, V> map = init.get();
        return new MapBuilder<>(map);
    }

    public MapBuilder<K, V> put(K k, V v) {
        this.map.put(k, v);
        return this;
    }

    public MapBuilder<K, V> remove(K k) {
        this.map.remove(k);
        return this;
    }

    public Map<K, V> get() {
        return this.map;
    }
}
