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 String
private static final Logger
private 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) FieldMaskTree
addFieldPath
(String path) Adds a field path to the tree.private static void
getFieldPaths
(FieldMaskTree.Node node, String path, List<String> paths) Gathers all field paths in a sub-tree.(package private) void
intersectFieldPath
(String path, FieldMaskTree output) Adds the intersection of this tree with the givenpath
tooutput
.(package private) void
merge
(Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) Merges all fields specified by this FieldMaskTree fromsource
todestination
.private static void
merge
(FieldMaskTree.Node node, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) Merges all fields specified by a sub-tree fromsource
todestination
.(package private) FieldMaskTree
mergeFromFieldMask
(FieldMask mask) Merges all field paths in a FieldMask into this tree.private static boolean
removeFieldPath
(FieldMaskTree.Node node, List<String> parts, int index) Removesparts
fromnode
recursively.(package private) FieldMaskTree
removeFieldPath
(String path) Removespath
from the tree.(package private) FieldMaskTree
removeFromFieldMask
(FieldMask mask) Removes all field paths inmask
from this tree.(package private) FieldMask
Converts 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
Removespath
from 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
@CanIgnoreReturnValue private static boolean removeFieldPath(FieldMaskTree.Node node, List<String> parts, int index) Removesparts
fromnode
recursively.- Returns:
- a boolean value indicating whether current
node
should be removed.
-
removeFromFieldMask
Removes all field paths inmask
from 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 givenpath
tooutput
. -
merge
Merges all fields specified by this FieldMaskTree fromsource
todestination
. -
merge
private static void merge(FieldMaskTree.Node node, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) Merges all fields specified by a sub-tree fromsource
todestination
.
-