Add null check for name

This commit is contained in:
chimp1984 2020-08-30 14:40:21 -05:00
parent 3e728c69f7
commit 008ae93b88
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -66,6 +66,10 @@ public class ProtoUtil {
*/
@Nullable
public static <E extends Enum<E>> E enumFromProto(Class<E> enumType, String name) {
if (name == null) {
return null;
}
E result = Enums.getIfPresent(enumType, name).orNull();
if (result == null) {
log.error("Invalid value for enum " + enumType.getSimpleName() + ": " + name);
@ -77,7 +81,8 @@ public class ProtoUtil {
return result;
}
public static <T extends Message> Iterable<T> collectionToProto(Collection<? extends Proto> collection, Class<T> messageType) {
public static <T extends Message> Iterable<T> collectionToProto(Collection<? extends Proto> collection,
Class<T> messageType) {
return collection.stream()
.map(e -> {
final Message message = e.toProtoMessage();
@ -92,7 +97,8 @@ public class ProtoUtil {
.collect(Collectors.toList());
}
public static <T> Iterable<T> collectionToProto(Collection<? extends Proto> collection, Function<? super Message, T> extra) {
public static <T> Iterable<T> collectionToProto(Collection<? extends Proto> collection,
Function<? super Message, T> extra) {
return collection.stream().map(o -> extra.apply(o.toProtoMessage())).collect(Collectors.toList());
}
}