docs: @Requires("isValidPattern(pattern)")
    public R get(String pattern) {
      String canon = pattern.replace('/', '.');
      boolean exact = !canon.endsWith(".*");
      if (!exact) {
        canon = canon.substring(0, canon.length() - 2);
      }
  
      String[] parts = canon.split("\\.");
      TernaryNode current = root;
      R best = null;
      for (int i = 0; i < parts.length; ++i) {
        TernaryNode next = current.children.get(parts[i]);
        if (next == null) {
          break;
        }
        if (next.rule != null) {
          if (next.exact) {
            if (exact && i == parts.length - 1) {
              best = next.rule;
            }
          } else {
            best = next.rule;
          }
        }
        current = next;
      }
      return best;
    }