Package com.google.protobuf.util
Class FieldMaskTree
- java.lang.Object
-
- com.google.protobuf.util.FieldMaskTree
-
final class FieldMaskTree extends java.lang.Object
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 Modifier and Type Class Description private static class
FieldMaskTree.Node
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
FIELD_PATH_SEPARATOR_REGEX
private static java.util.logging.Logger
logger
private FieldMaskTree.Node
root
-
Constructor Summary
Constructors Constructor Description FieldMaskTree()
Creates an empty FieldMaskTree.FieldMaskTree(FieldMask mask)
Creates a FieldMaskTree for a given FieldMask.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) FieldMaskTree
addFieldPath(java.lang.String path)
Adds a field path to the tree.private static void
getFieldPaths(FieldMaskTree.Node node, java.lang.String path, java.util.List<java.lang.String> paths)
Gathers all field paths in a sub-tree.(package private) void
intersectFieldPath(java.lang.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, java.util.List<java.lang.String> parts, int index)
Removesparts
fromnode
recursively.(package private) FieldMaskTree
removeFieldPath(java.lang.String path)
Removespath
from the tree.(package private) FieldMaskTree
removeFromFieldMask(FieldMask mask)
Removes all field paths inmask
from this tree.(package private) FieldMask
toFieldMask()
Converts this tree to a FieldMask.java.lang.String
toString()
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
FIELD_PATH_SEPARATOR_REGEX
private static final java.lang.String FIELD_PATH_SEPARATOR_REGEX
- See Also:
- Constant Field Values
-
root
private final FieldMaskTree.Node root
-
-
Constructor Detail
-
FieldMaskTree
FieldMaskTree()
Creates an empty FieldMaskTree.
-
FieldMaskTree
FieldMaskTree(FieldMask mask)
Creates a FieldMaskTree for a given FieldMask.
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
addFieldPath
@CanIgnoreReturnValue FieldMaskTree addFieldPath(java.lang.String path)
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
@CanIgnoreReturnValue FieldMaskTree mergeFromFieldMask(FieldMask mask)
Merges all field paths in a FieldMask into this tree.
-
removeFieldPath
@CanIgnoreReturnValue FieldMaskTree removeFieldPath(java.lang.String path)
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, java.util.List<java.lang.String> parts, int index)
Removesparts
fromnode
recursively.- Returns:
- a boolean value indicating whether current
node
should be removed.
-
removeFromFieldMask
@CanIgnoreReturnValue FieldMaskTree removeFromFieldMask(FieldMask mask)
Removes all field paths inmask
from this tree.
-
toFieldMask
FieldMask toFieldMask()
Converts this tree to a FieldMask.
-
getFieldPaths
private static void getFieldPaths(FieldMaskTree.Node node, java.lang.String path, java.util.List<java.lang.String> paths)
Gathers all field paths in a sub-tree.
-
intersectFieldPath
void intersectFieldPath(java.lang.String path, FieldMaskTree output)
Adds the intersection of this tree with the givenpath
tooutput
.
-
merge
void merge(Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options)
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
.
-
-