Package com.google.protobuf.util
Class FieldMaskTree
java.lang.Object
com.google.protobuf.util.FieldMaskTree
A tree representation of a FieldMask. Each leaf node in this tree represent a field path in the
FieldMask.
For example, FieldMask "foo.bar,foo.baz,bar.baz" as a tree will be:
[root] -+- foo -+- bar
| |
| +- baz
|
+- bar --- baz
By representing FieldMasks with this tree structure we can easily convert a FieldMask to a canonical form, merge two FieldMasks, calculate the intersection to two FieldMasks and traverse all fields specified by the FieldMask in a message tree.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Loggerprivate final FieldMaskTree.Node -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty FieldMaskTree.FieldMaskTree(FieldMask mask) Creates a FieldMaskTree for a given FieldMask. -
Method Summary
Modifier and TypeMethodDescription(package private) FieldMaskTreeaddFieldPath(String path) Adds a field path to the tree.private static voidgetFieldPaths(FieldMaskTree.Node node, String path, List<String> paths) Gathers all field paths in a sub-tree.(package private) voidintersectFieldPath(String path, FieldMaskTree output) Adds the intersection of this tree with the givenpathtooutput.(package private) voidmerge(Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) Merges all fields specified by this FieldMaskTree fromsourcetodestination.private static voidmerge(FieldMaskTree.Node node, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) Merges all fields specified by a sub-tree fromsourcetodestination.(package private) FieldMaskTreemergeFromFieldMask(FieldMask mask) Merges all field paths in a FieldMask into this tree.private static booleanremoveFieldPath(FieldMaskTree.Node node, List<String> parts, int index) Removespartsfromnoderecursively.(package private) FieldMaskTreeremoveFieldPath(String path) Removespathfrom the tree.(package private) FieldMaskTreeremoveFromFieldMask(FieldMask mask) Removes all field paths inmaskfrom this tree.(package private) FieldMaskConverts this tree to a FieldMask.toString()
-
Field Details
-
logger
-
FIELD_PATH_SEPARATOR_REGEX
- See Also:
-
root
-
-
Constructor Details
-
FieldMaskTree
FieldMaskTree()Creates an empty FieldMaskTree. -
FieldMaskTree
FieldMaskTree(FieldMask mask) Creates a FieldMaskTree for a given FieldMask.
-
-
Method Details
-
toString
-
addFieldPath
Adds a field path to the tree. In a FieldMask, every field path matches the specified field as well as all its sub-fields. For example, a field path "foo.bar" matches field "foo.bar" and also "foo.bar.baz", etc. When adding a field path to the tree, redundant sub-paths will be removed. That is, after adding "foo.bar" to the tree, "foo.bar.baz" will be removed if it exists, which will turn the tree node for "foo.bar" to a leaf node. Likewise, if the field path to add is a sub-path of an existing leaf node, nothing will be changed in the tree. -
mergeFromFieldMask
Merges all field paths in a FieldMask into this tree. -
removeFieldPath
Removespathfrom the tree.-
When removing a field path from the tree:
- All sub-paths will be removed. That is, after removing "foo.bar" from the tree, "foo.bar.baz" will be removed.
- If all children of a node have been removed, the node itself will be removed as well. That is, if "foo" only has one child "bar" and "foo.bar" only has one child "baz", removing "foo.bar.barz" would remove both "foo" and "foo.bar". If "foo" has both "bar" and "moo" as children, removing "foo.bar" would leave the path "foo.moo" intact.
- If the field path to remove is a non-exist sub-path, nothing will be changed.
-
removeFieldPath
Removespartsfromnoderecursively.- Returns:
- a boolean value indicating whether current
nodeshould be removed.
-
removeFromFieldMask
Removes all field paths inmaskfrom this tree. -
toFieldMask
FieldMask toFieldMask()Converts this tree to a FieldMask. -
getFieldPaths
Gathers all field paths in a sub-tree. -
intersectFieldPath
Adds the intersection of this tree with the givenpathtooutput. -
merge
Merges all fields specified by this FieldMaskTree fromsourcetodestination. -
merge
private static void merge(FieldMaskTree.Node node, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) Merges all fields specified by a sub-tree fromsourcetodestination.
-