Package com.google.protobuf.util
Class FieldMaskUtil
- java.lang.Object
-
- com.google.protobuf.util.FieldMaskUtil
-
public final class FieldMaskUtil extends java.lang.ObjectUtility helper functions to work withFieldMask.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFieldMaskUtil.MergeOptionsOptions to customize merging behavior.static classFieldMaskUtil.TrimOptionsOptions to customize trimming behavior.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FieldMaskfromFieldNumbers(java.lang.Class<? extends Message> type, int... fieldNumbers)Constructs a FieldMask from the passed field numbers.static FieldMaskfromFieldNumbers(java.lang.Class<? extends Message> type, java.lang.Iterable<java.lang.Integer> fieldNumbers)Constructs a FieldMask from the passed field numbers.static FieldMaskfromJsonString(java.lang.String value)Converts a field mask from a Proto3 JSON string, that is splitting the paths along commas and converting from camel case to snake case.static FieldMaskfromString(java.lang.Class<? extends Message> type, java.lang.String value)Parses from a string to a FieldMask and validates all field paths.static FieldMaskfromString(java.lang.String value)Parses from a string to a FieldMask.static FieldMaskfromStringList(Descriptors.Descriptor descriptor, java.lang.Iterable<java.lang.String> paths)Constructs a FieldMask for a list of field paths in a certain type.static FieldMaskfromStringList(java.lang.Class<? extends Message> type, java.lang.Iterable<java.lang.String> paths)Constructs a FieldMask for a list of field paths in a certain type.static FieldMaskfromStringList(java.lang.Iterable<java.lang.String> paths)Constructs a FieldMask for a list of field paths in a certain type.static FieldMaskintersection(FieldMask mask1, FieldMask mask2)Calculates the intersection of two FieldMasks.static booleanisValid(Descriptors.Descriptor descriptor, FieldMask fieldMask)Checks whether paths in a given fields mask are valid.static booleanisValid(Descriptors.Descriptor descriptor, java.lang.String path)Checks whether paths in a given fields mask are valid.static booleanisValid(java.lang.Class<? extends Message> type, FieldMask fieldMask)Checks whether paths in a given fields mask are valid.static booleanisValid(java.lang.Class<? extends Message> type, java.lang.String path)Checks whether a given field path is valid.static voidmerge(FieldMask mask, Message source, Message.Builder destination)Merges fields specified by a FieldMask from one message to another.static voidmerge(FieldMask mask, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options)Merges fields specified by a FieldMask from one message to another with the specified merge options.static FieldMasknormalize(FieldMask mask)Converts a FieldMask to its canonical form.static FieldMasksubtract(FieldMask firstMask, FieldMask secondMask, FieldMask... otherMasks)SubtractssecondMaskandotherMasksfromfirstMask.static java.lang.StringtoJsonString(FieldMask fieldMask)Converts a field mask to a Proto3 JSON string, that is converting from snake case to camel case and joining all paths into one string with commas.static java.lang.StringtoString(FieldMask fieldMask)Converts a FieldMask to a string.static <P extends Message>
Ptrim(FieldMask mask, P source)Returns the result of keeping only the masked fields of the given proto.static <P extends Message>
Ptrim(FieldMask mask, P source, FieldMaskUtil.TrimOptions options)Returns the result of keeping only the masked fields of the given proto with the specified trim options.static FieldMaskunion(FieldMask firstMask, FieldMask secondMask, FieldMask... otherMasks)Creates a union of two or more FieldMasks.
-
-
-
Method Detail
-
toString
public static java.lang.String toString(FieldMask fieldMask)
Converts a FieldMask to a string.
-
fromString
public static FieldMask fromString(java.lang.String value)
Parses from a string to a FieldMask.
-
fromString
public static FieldMask fromString(java.lang.Class<? extends Message> type, java.lang.String value)
Parses from a string to a FieldMask and validates all field paths.- Throws:
java.lang.IllegalArgumentException- if any of the field path is invalid.
-
fromStringList
public static FieldMask fromStringList(java.lang.Class<? extends Message> type, java.lang.Iterable<java.lang.String> paths)
Constructs a FieldMask for a list of field paths in a certain type.- Throws:
java.lang.IllegalArgumentException- if any of the field path is not valid
-
fromStringList
public static FieldMask fromStringList(Descriptors.Descriptor descriptor, java.lang.Iterable<java.lang.String> paths)
Constructs a FieldMask for a list of field paths in a certain type.- Throws:
java.lang.IllegalArgumentException- if any of the field path is not valid.
-
fromStringList
public static FieldMask fromStringList(java.lang.Iterable<java.lang.String> paths)
Constructs a FieldMask for a list of field paths in a certain type. Does not validate the given paths.
-
fromFieldNumbers
public static FieldMask fromFieldNumbers(java.lang.Class<? extends Message> type, int... fieldNumbers)
Constructs a FieldMask from the passed field numbers.- Throws:
java.lang.IllegalArgumentException- if any of the fields are invalid for the message.
-
fromFieldNumbers
public static FieldMask fromFieldNumbers(java.lang.Class<? extends Message> type, java.lang.Iterable<java.lang.Integer> fieldNumbers)
Constructs a FieldMask from the passed field numbers.- Throws:
java.lang.IllegalArgumentException- if any of the fields are invalid for the message.
-
toJsonString
public static java.lang.String toJsonString(FieldMask fieldMask)
Converts a field mask to a Proto3 JSON string, that is converting from snake case to camel case and joining all paths into one string with commas.
-
fromJsonString
public static FieldMask fromJsonString(java.lang.String value)
Converts a field mask from a Proto3 JSON string, that is splitting the paths along commas and converting from camel case to snake case.
-
isValid
public static boolean isValid(java.lang.Class<? extends Message> type, FieldMask fieldMask)
Checks whether paths in a given fields mask are valid.
-
isValid
public static boolean isValid(Descriptors.Descriptor descriptor, FieldMask fieldMask)
Checks whether paths in a given fields mask are valid.
-
isValid
public static boolean isValid(java.lang.Class<? extends Message> type, java.lang.String path)
Checks whether a given field path is valid.
-
isValid
public static boolean isValid(@Nullable Descriptors.Descriptor descriptor, java.lang.String path)Checks whether paths in a given fields mask are valid.
-
normalize
public static FieldMask normalize(FieldMask mask)
Converts a FieldMask to its canonical form. In the canonical form of a FieldMask, all field paths are sorted alphabetically and redundant field paths are removed.
-
union
public static FieldMask union(FieldMask firstMask, FieldMask secondMask, FieldMask... otherMasks)
Creates a union of two or more FieldMasks.
-
subtract
public static FieldMask subtract(FieldMask firstMask, FieldMask secondMask, FieldMask... otherMasks)
SubtractssecondMaskandotherMasksfromfirstMask.This method disregards proto structure. That is, if
firstMaskis "foo" andsecondMaskis "foo.bar", the response will always be "foo" without considering the internal proto structure of message "foo".
-
intersection
public static FieldMask intersection(FieldMask mask1, FieldMask mask2)
Calculates the intersection of two FieldMasks.
-
merge
public static void merge(FieldMask mask, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options)
Merges fields specified by a FieldMask from one message to another with the specified merge options. The destination will remain unchanged if an empty FieldMask is provided.
-
merge
public static void merge(FieldMask mask, Message source, Message.Builder destination)
Merges fields specified by a FieldMask from one message to another.
-
trim
public static <P extends Message> P trim(FieldMask mask, P source, FieldMaskUtil.TrimOptions options)
Returns the result of keeping only the masked fields of the given proto with the specified trim options.Note that the behavior with the default
FieldMaskUtil.TrimOptionsis for unset primitive fields indicated in the field mask to be explicitly set to their default values. Usenew TrimOptions().setRetainPrimitiveFieldUnsetState(true)to retain the unset state of primitive fields.
-
trim
public static <P extends Message> P trim(FieldMask mask, P source)
Returns the result of keeping only the masked fields of the given proto.This method is equivalent to
trim(FieldMask, Message, TrimOptions)with defaultFieldMaskUtil.TrimOptions.Note that unset primitive fields indicated in the field mask will be explicitly set to their default values.
-
-