Class NumberTreeUtil


  • public final class NumberTreeUtil
    extends java.lang.Object
    Looks up a value in a PDF "number tree" (/Nums leaf array of [key1, value1, key2, value2, ...] pairs, optionally split across /Kids with /Limits ranges for large trees) -- the structure used by /StructTreeRoot/ParentTree, /PageLabels and a handful of other PDF constructs.

    Thread-safety: this class holds no state of its own (every method is static, and each call builds its own fresh visited-set for cycle detection) -- call either method freely and concurrently from any number of threads, including several at once walking the very same tree (COSDictionary/COSArray reads here are read-only).

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static COSBase lookup​(COSDictionary root, int key)
      Returns the value stored under key in the number tree rooted at root, or null.
      static int maxKey​(COSDictionary root)
      The highest key stored anywhere in the number tree rooted at root (searching every /Kids subtree, ignoring /Limits since those are advisory and this needs the true maximum regardless), or -1 if root is null or the tree has no entries at all.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • lookup

        public static COSBase lookup​(COSDictionary root,
                                     int key)
        Returns the value stored under key in the number tree rooted at root, or null.
      • maxKey

        public static int maxKey​(COSDictionary root)
        The highest key stored anywhere in the number tree rooted at root (searching every /Kids subtree, ignoring /Limits since those are advisory and this needs the true maximum regardless), or -1 if root is null or the tree has no entries at all. Used by a caller that wants to append fresh, never-colliding keys to an existing number tree -- e.g. adding new /StructTreeRoot/ParentTree entries for annotations a feature just added to an already-tagged PDF -- when the tree's own /ParentTreeNextKey-style hint (a convention specific to ParentTree, not a general number-tree feature) isn't present or trusted.