public final class ProtoUtils


Contains various utility methods to ease use of protos and increased readability in code.

Summary

Public methods

static String

Capitalizes the first char of a String.

static T
<T extends Enum> checkedGetEnumForProto(int protoEnumIndex, Class<T> enumClass)

Maps an enum proto message type to a internal representation enum type T.

static List<Field>
getFilteredFieldList(
    Class<Object> clazz,
    List<String> targetFieldNames
)

Returns a filtered view of a class's declared Field list.

Public methods

capitalizeFirstChar

public static String capitalizeFirstChar(String aString)

Capitalizes the first char of a String.

Examples: "espresso" -> "Espresso", "Espresso" -> "Espresso"

Parameters
String aString

the String to capitalize

Returns
String

capitalized String or original String, if aString was empty

checkedGetEnumForProto

public static T <T extends Enum> checkedGetEnumForProto(int protoEnumIndex, Class<T> enumClass)

Maps an enum proto message type to a internal representation enum type T.

Parameters
<T extends Enum>

the generic type of the enum representation

int protoEnumIndex

the proto enum index of the value returned by the unwrapped proto message

Class<T> enumClass

the enum class to map against

Returns
T

the enum constant for a proto enum index

getFilteredFieldList

public static List<FieldgetFilteredFieldList(
    Class<Object> clazz,
    List<String> targetFieldNames
)

Returns a filtered view of a class's declared Field list.

Parameters
Class<Object> clazz

the class to introspect

List<String> targetFieldNames

the field names to filter from a class Field list

Returns
List<Field>

a filtered list of class Fields

Throws
java.lang.NoSuchFieldException

if a field name does not exist in clazz