# ProtoUtils

Artifact: [androidx.test.espresso:espresso-remote](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/remote/ProtoUtils.java+class:androidx.test.espresso.remote.ProtoUtils)

*** ** * ** ***

<br />

```
public final class ProtoUtils
```

<br />

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/espresso/remote/ProtoUtils#capitalizeFirstChar(java.lang.String)(https://developer.android.com/reference/java/lang/String.html aString)` Capitalizes the first char of a String. |
| `static T` | `<T extends https://developer.android.com/reference/java/lang/Enum.html> https://developer.android.com/reference/androidx/test/espresso/remote/ProtoUtils#checkedGetEnumForProto(int,java.lang.Class<T>)(int protoEnumIndex, https://developer.android.com/reference/java/lang/Class.html<T> enumClass)` Maps an enum proto message type to a internal representation enum type T. |
| `static https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/reflect/Field.html>` | `https://developer.android.com/reference/androidx/test/espresso/remote/ProtoUtils#getFilteredFieldList(java.lang.Class<?>,java.util.List<java.lang.String>)( https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html> targetFieldNames )` Returns a filtered view of a class's declared `https://developer.android.com/reference/java/lang/reflect/Field.html` list. |

## Public methods

### capitalizeFirstChar

```
public static String capitalizeFirstChar(String aString)
```

Capitalizes the first char of a String.

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html aString` | the String to capitalize |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | 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 https://developer.android.com/reference/java/lang/Enum.html>` | the generic type of the enum representation |
| `int protoEnumIndex` | the proto enum index of the value returned by the unwrapped proto message |
| `https://developer.android.com/reference/java/lang/Class.html<T> enumClass` | the enum class to map against |

| Returns |
|---|---|
| `T` | the enum constant for a proto enum index |

### getFilteredFieldList

```
public static List<Field> getFilteredFieldList(
    Class<@NonNull ?> clazz,
    List<String> targetFieldNames
)
```

Returns a filtered view of a class's declared `https://developer.android.com/reference/java/lang/reflect/Field.html` list.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz` | the class to introspect |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html> targetFieldNames` | the field names to filter from a class `https://developer.android.com/reference/java/lang/reflect/Field.html` list |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/reflect/Field.html>` | a filtered list of class `https://developer.android.com/reference/java/lang/reflect/Field.html`s |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NoSuchFieldException.html` | if a field name does not exist in `clazz` |