code: private TreeMap<Integer, TreeRule> fetchRuleLevel() {
      TreeMap<Integer, TreeRule> current_level = null;
      
      // iterate until we find some rules on a level or we run out
      while (current_level == null && rule_idx <= max_rule_level) {
        current_level = tree.getRules().get(rule_idx);
        if (current_level != null) {
          return current_level;
        } else {
          rule_idx++;
        }
      }
      
      // no more levels
      return null;
    }
docs: A helper that fetches the next level in the rule set. If a user removes
  an entire rule level, we want to be able to skip it gracefully without
  throwing an exception. This will loop until we hit {@link #max_rule_level}
  or we find a valid rule.
  @return The rules on the current {@link #rule_idx} level or the next valid
  level if {@link #rule_idx} is invalid. Returns null if we've run out of
  rules.