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

tech.ferus.util.config.transformer.MapTransformer Maven / Gradle / Ivy

Go to download

ConfigKeys is a simple wrapper for zml's Configurate, providing a more stream-lined way to access configuration on-the-fly.

The newest version!
package tech.ferus.util.config.transformer;

import com.google.common.collect.Maps;
import ninja.leaping.configurate.ConfigurationNode;

import java.util.Map;

/**
 * Intended to transform convert a {@link ConfigurationNode} map
 * into a map of whatever is specified.
 *
 * @param  the type of key to convert to
 * @param  the type of value to convert to
 */
public class MapTransformer implements Transformer> {

    @SuppressWarnings("unchecked")
    @Override
    public Map transform(final ConfigurationNode node) throws TransformerException {
        if (!node.hasMapChildren()) {
            throw new TransformerException("Node isn't in a map format and cannot be transformed.");
        }

        final Map collect = Maps.newHashMap();
        try {
            for (final Map.Entry entry : node.getChildrenMap().entrySet()) {
                collect.put((K) entry.getKey(), (V) entry.getValue().getValue());
            }
        } catch (final Exception e) {
            throw new TransformerException(e);
        }

        return collect;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy