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

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

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

import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * Custom property provider for proto tree nodes.
 *
 * @author Kostiantyn Shchepanovskyi
 */
public class PropertyProviderImpl implements PropertyProvider {

    private final Map> propertyProviders = new HashMap<>();

    @Override
    public boolean hasProperty(String propertyName) {
        return propertyProviders.containsKey(propertyName);
    }

    @SuppressWarnings("unchecked")
    @Override
    public Object getProperty(Object object, String propertyName) {
        Function provider = (Function) propertyProviders.get(propertyName);
        Preconditions.checkNotNull(provider,
                "Cannot find property '%s' for %s",
                propertyName, object);
        return provider.apply(object);
    }

    @Override
    public void register(String property, Function function) {
        propertyProviders.put(property, function);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy