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

com.gojek.de.stencil.utils.StencilUtils Maven / Gradle / Ivy

There is a newer version: 4.2.2
Show newest version
package com.gojek.de.stencil.utils;

import com.gojek.de.stencil.models.DescriptorAndTypeName;
import com.google.protobuf.Descriptors;

import java.util.HashMap;
import java.util.Map;

/**
 * Utility method to parse the types and packages based on the descriptors.
 */
public class StencilUtils {

    /**
     * Gets a map of proto package name and typeName from the supplied map of model descriptors
     *
     * @param allDescriptors - Stencil modelled descriptors
     * @return - map of proto package and java type
     */
    public static Map getTypeNameToPackageNameMap(final Map allDescriptors) {
        Map typeNameMap = new HashMap();
        allDescriptors.entrySet().stream().forEach((mapEntry) -> {
            DescriptorAndTypeName descriptorAndTypeName = (DescriptorAndTypeName) mapEntry.getValue();
            if (descriptorAndTypeName != null) {
                typeNameMap.put(descriptorAndTypeName.getTypeName(), mapEntry.getKey());
            }
        });
        return typeNameMap;
    }

    /**
     * Gets a map of type and the descriptor from the supplied map of model descriptors
     *
     * @param allDescriptors - Stencil modelled descriptors
     * @return - map of type and the respective protobuff descriptor
     */
    public static Map getAllProtobufDescriptors(final Map allDescriptors) {
        Map descriptorMap = new HashMap();
        allDescriptors.entrySet().stream().forEach((mapEntry) -> {
            DescriptorAndTypeName descriptorAndTypeName = (DescriptorAndTypeName) mapEntry.getValue();
            if (descriptorAndTypeName != null) {
                descriptorMap.put(mapEntry.getKey(), descriptorAndTypeName.getDescriptor());
            }
        });
        return descriptorMap;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy