Class FieldMasks
java.lang.Object
com.google.ads.googleads.lib.utils.FieldMasks
Utility methods for working with field masks.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends com.google.protobuf.GeneratedMessageV3>
com.google.protobuf.FieldMaskallSetFieldsOf(T message) Computes a FieldMask based on all of the fields of message that have been set.static <T extends com.google.protobuf.GeneratedMessageV3>
com.google.protobuf.FieldMaskcompare(T original, T modified) Compares two protobuf message objects and computes a FieldMask based on the differences between the two objects.static <T> List<T>getFieldValue(String fieldMaskPath, com.google.protobuf.Message entity) Gets the field value of a message from a field mask path.
-
Constructor Details
-
FieldMasks
public FieldMasks()
-
-
Method Details
-
compare
public static <T extends com.google.protobuf.GeneratedMessageV3> com.google.protobuf.FieldMask compare(T original, T modified) Compares two protobuf message objects and computes a FieldMask based on the differences between the two objects. This method can be used to help construct the FieldMask object required by some API methods.Example usage:
Foo originalFoo = client.getFoo(); Foo updatedFoo = originalFoo.toBuilder().setBar("new-bar").build(); FieldMask fieldMask = FieldMasks.compare(originalFoo, updatedFoo); client.updateFoo(updatedFoo, fieldMask);- Parameters:
original- The original protobuf message object.modified- The modified protobuf message object.- Returns:
- A FieldMask reflecting the changes between the original and modified objects.
-
allSetFieldsOf
public static <T extends com.google.protobuf.GeneratedMessageV3> com.google.protobuf.FieldMask allSetFieldsOf(T message) Computes a FieldMask based on all of the fields of message that have been set.For a message object
foo,FieldMasks.allSetFieldsOf(foo)is equivalent toFieldMasks.compare(foo.getDefaultInstanceForType(), foo) -
getFieldValue
Gets the field value of a message from a field mask path.- Parameters:
fieldMaskPath- The field mask path.entity- The entity to retrieve values from.- Returns:
- the values referred to by the path. This is a list since the path may include a repeated field, in which case we include all values recursively. If this method doesn't throw it will always return a list. The list will be empty if the field isn't present in the message.
- Throws:
IllegalStateException- if the field doesn't exist in the message.
-