Class FieldMaskTree

java.lang.Object
com.google.protobuf.util.FieldMaskTree

final class FieldMaskTree extends 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.

  • Field Details

  • Constructor Details

    • FieldMaskTree

      FieldMaskTree()
      Creates an empty FieldMaskTree.
    • FieldMaskTree

      FieldMaskTree(FieldMask mask)
      Creates a FieldMaskTree for a given FieldMask.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • addFieldPath

      FieldMaskTree addFieldPath(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

      FieldMaskTree mergeFromFieldMask(FieldMask mask)
      Merges all field paths in a FieldMask into this tree.
    • removeFieldPath

      FieldMaskTree removeFieldPath(String path)
      Removes path 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 has 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 "qux" as children, removing "foo.bar" would leave the path "foo.qux" intact.
      • If the field path to remove is a non-exist sub-path, nothing will be changed.
    • removeFieldPath

      private static boolean removeFieldPath(FieldMaskTree.Node node, List<String> parts, int index)
      Removes parts from node recursively.
      Returns:
      a boolean value indicating whether current node should be removed.
    • removeFromFieldMask

      FieldMaskTree removeFromFieldMask(FieldMask mask)
      Removes all field paths in mask from this tree.
    • toFieldMask

      FieldMask toFieldMask()
      Converts this tree to a FieldMask.
    • getFieldPaths

      private static void getFieldPaths(FieldMaskTree.Node node, String path, List<String> paths)
      Gathers all field paths in a sub-tree.
    • intersectFieldPath

      void intersectFieldPath(String path, FieldMaskTree output)
      Adds the intersection of this tree with the given path to output.
    • merge

      void merge(Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options)
      Merges all fields specified by this FieldMaskTree from source to destination.
    • merge

      private static void merge(FieldMaskTree.Node node, String path, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options)
      Merges all fields specified by a sub-tree from source to destination.