com.gojek.de.stencil.utils.StencilUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stencil Show documentation
Show all versions of stencil Show documentation
Library to pull latest proto descriptors from a remote server
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;
}
}