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

com.github.sviperll.maven.plugin.mustache.MapFiller Maven / Gradle / Ivy

There is a newer version: 0.24-beta2
Show newest version
/*
 * Copyright 2015 Victor Nazarov .
 */
package com.github.sviperll.maven.plugin.mustache;

import java.util.Map;
import java.util.TreeMap;

/**
 *
 * @author Victor Nazarov <[email protected]>
 */
class MapFiller {
    private final Map result;

    MapFiller(Map result) {
        this.result = result;
    }

    @SuppressWarnings("unchecked")
    void put(String key, String value) {
        int index = key.indexOf('.');
        if (index < 0)
            result.put(key, value);
        else {
            String prefix = key.substring(0, index);
            Object mapObject = result.get(prefix);
            Map map;
            if (mapObject != null && mapObject instanceof Map)
                map = (Map)mapObject;
            else {
                map = new TreeMap();
                result.put(prefix, map);
            }
            MapFiller filler = new MapFiller(map);
            filler.put(key.substring(index + 1), value);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy