private static void removePolicyNodeRecurse(List[] policyNodes, PKIXPolicyNode _node) {
    policyNodes[_node.getDepth()].remove(_node);

    if (_node.hasChildren()) {
      Iterator _iter = _node.getChildren();
      while (_iter.hasNext()) {
        PKIXPolicyNode _child = (PKIXPolicyNode) _iter.next();
        removePolicyNodeRecurse(policyNodes, _child);
      }
    }
  }
 protected static PKIXPolicyNode prepareNextCertB2(
     int i, List[] policyNodes, String id_p, PKIXPolicyNode validPolicyTree) {
   Iterator nodes_i = policyNodes[i].iterator();
   while (nodes_i.hasNext()) {
     PKIXPolicyNode node = (PKIXPolicyNode) nodes_i.next();
     if (node.getValidPolicy().equals(id_p)) {
       PKIXPolicyNode p_node = (PKIXPolicyNode) node.getParent();
       p_node.removeChild(node);
       nodes_i.remove();
       for (int k = (i - 1); k >= 0; k--) {
         List nodes = policyNodes[k];
         for (int l = 0; l < nodes.size(); l++) {
           PKIXPolicyNode node2 = (PKIXPolicyNode) nodes.get(l);
           if (!node2.hasChildren()) {
             validPolicyTree = removePolicyNode(validPolicyTree, policyNodes, node2);
             if (validPolicyTree == null) {
               break;
             }
           }
         }
       }
     }
   }
   return validPolicyTree;
 }
  protected static void processCertD1ii(
      int index, List[] policyNodes, DERObjectIdentifier _poid, Set _pq) {
    List policyNodeVec = policyNodes[index - 1];

    for (int j = 0; j < policyNodeVec.size(); j++) {
      PKIXPolicyNode _node = (PKIXPolicyNode) policyNodeVec.get(j);

      if (ANY_POLICY.equals(_node.getValidPolicy())) {
        Set _childExpectedPolicies = new HashSet();
        _childExpectedPolicies.add(_poid.getId());

        PKIXPolicyNode _child =
            new PKIXPolicyNode(
                new ArrayList(), index, _childExpectedPolicies, _node, _pq, _poid.getId(), false);
        _node.addChild(_child);
        policyNodes[index].add(_child);
        return;
      }
    }
  }
  protected static void prepareNextCertB1(
      int i, List[] policyNodes, String id_p, Map m_idp, X509Certificate cert)
      throws AnnotatedException, CertPathValidatorException {
    boolean idp_found = false;
    Iterator nodes_i = policyNodes[i].iterator();
    while (nodes_i.hasNext()) {
      PKIXPolicyNode node = (PKIXPolicyNode) nodes_i.next();
      if (node.getValidPolicy().equals(id_p)) {
        idp_found = true;
        node.expectedPolicies = (Set) m_idp.get(id_p);
        break;
      }
    }

    if (!idp_found) {
      nodes_i = policyNodes[i].iterator();
      while (nodes_i.hasNext()) {
        PKIXPolicyNode node = (PKIXPolicyNode) nodes_i.next();
        if (ANY_POLICY.equals(node.getValidPolicy())) {
          Set pq = null;
          ASN1Sequence policies = (ASN1Sequence) getExtensionValue(cert, CERTIFICATE_POLICIES);
          Enumeration e = policies.getObjects();
          while (e.hasMoreElements()) {
            PolicyInformation pinfo = PolicyInformation.getInstance(e.nextElement());
            if (ANY_POLICY.equals(pinfo.getPolicyIdentifier().getId())) {
              pq = getQualifierSet(pinfo.getPolicyQualifiers());
              break;
            }
          }
          boolean ci = false;
          if (cert.getCriticalExtensionOIDs() != null) {
            ci = cert.getCriticalExtensionOIDs().contains(CERTIFICATE_POLICIES);
          }

          PKIXPolicyNode p_node = (PKIXPolicyNode) node.getParent();
          if (ANY_POLICY.equals(p_node.getValidPolicy())) {
            PKIXPolicyNode c_node =
                new PKIXPolicyNode(new ArrayList(), i, (Set) m_idp.get(id_p), p_node, pq, id_p, ci);
            p_node.addChild(c_node);
            policyNodes[i].add(c_node);
          }
          break;
        }
      }
    }
  }
  protected static PKIXPolicyNode removePolicyNode(
      PKIXPolicyNode validPolicyTree, List[] policyNodes, PKIXPolicyNode _node) {
    PKIXPolicyNode _parent = (PKIXPolicyNode) _node.getParent();

    if (validPolicyTree == null) {
      return null;
    }

    if (_parent == null) {
      for (int j = 0; j < policyNodes.length; j++) {
        policyNodes[j] = new ArrayList();
      }

      return null;
    } else {
      _parent.removeChild(_node);
      removePolicyNodeRecurse(policyNodes, _node);

      return validPolicyTree;
    }
  }
  protected static boolean processCertD1i(
      int index, List[] policyNodes, DERObjectIdentifier pOid, Set pq) {
    List policyNodeVec = policyNodes[index - 1];

    for (int j = 0; j < policyNodeVec.size(); j++) {
      PKIXPolicyNode node = (PKIXPolicyNode) policyNodeVec.get(j);
      Set expectedPolicies = node.getExpectedPolicies();

      if (expectedPolicies.contains(pOid.getId())) {
        Set childExpectedPolicies = new HashSet();
        childExpectedPolicies.add(pOid.getId());

        PKIXPolicyNode child =
            new PKIXPolicyNode(
                new ArrayList(), index, childExpectedPolicies, node, pq, pOid.getId(), false);
        node.addChild(child);
        policyNodes[index].add(child);

        return true;
      }
    }

    return false;
  }