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

io.protostuff.generator.AbstractExtensionProvider Maven / Gradle / Ivy

There is a newer version: 3.1.40
Show newest version
package io.protostuff.generator;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import org.stringtemplate.v4.AttributeRenderer;

/**
 * Base class for extension providers.
 *
 * @author Kostiantyn Shchepanovskyi
 */
public class AbstractExtensionProvider implements ExtensionProvider {

    private final Map, AttributeRenderer> attributeRenderers;

    private final Map, PropertyProvider> extenderMap;

    public AbstractExtensionProvider() {
        extenderMap = new HashMap<>();
        attributeRenderers = new HashMap<>();
    }

    /**
     * Register custom property for specified node type.
     */
    public final  void registerProperty(Class object, String property, Function function) {
        PropertyProvider extender = extenderMap.computeIfAbsent(object,
                aClass -> new PropertyProviderImpl());
        extender.register(property, function);
    }

    @Override
    public Map, AttributeRenderer> attributeRenderers() {
        return Collections.unmodifiableMap(attributeRenderers);
    }

    @Override
    public Map, PropertyProvider> propertyProviders() {
        return Collections.unmodifiableMap(extenderMap);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy