Class FieldMasks
- java.lang.Object
-
- com.google.ads.googleads.lib.utils.FieldMasks
-
public class FieldMasks extends java.lang.ObjectUtility methods for working with field masks.
-
-
Constructor Summary
Constructors Constructor Description FieldMasks()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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> java.util.List<T>getFieldValue(java.lang.String fieldMaskPath, com.google.protobuf.Message entity)Gets the field value of a message from a field mask path.
-
-
-
Method Detail
-
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
public static <T> java.util.List<T> getFieldValue(java.lang.String fieldMaskPath, com.google.protobuf.Message entity)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:
java.lang.IllegalStateException- if the field doesn't exist in the message.
-
-