/**
   * Instantiates a new Iterator. Be sure that any desired restrictions have already been placed on
   * the CodedNodeSets before passing into this constructor
   *
   * @param codedNodeSets the coded node sets
   * @param sortOptions the sort options
   * @param filterOptions the filter options
   * @param restrictToProperties the restrict to properties
   * @param restrictToPropertyTypes the restrict to property types
   * @param resolve the resolve
   * @throws LBException the LB exception
   */
  public QuickUnionIterator(
      Vector<CodedNodeSet> codedNodeSets,
      SortOptionList sortOptions,
      LocalNameList filterOptions,
      LocalNameList restrictToProperties,
      PropertyType[] restrictToPropertyTypes,
      boolean resolve)
      throws LBException {

    for (CodedNodeSet cns : codedNodeSets) {
      // KLO 012310
      if (cns != null) {
        try {
          ResolvedConceptReferencesIterator iterator =
              cns.resolve(
                  sortOptions,
                  filterOptions,
                  restrictToProperties,
                  restrictToPropertyTypes,
                  resolve);
          if (iterator != null) {
            _iterators.add(iterator);
          }
        } catch (Exception ex) {
          _logger.error("QuickUnionIterator constructor - cns.resolve throws exception???");
          // ex.printStackTrace();
          System.out.println(
              "WARNING: QuickUnionIteratorWrapper constructor - cns.resolve throws exception???");
        }
      }
    }

    Collections.sort(_iterators, new IteratorSizeComparator());
  }
  @Test
  public void testGetTargetCodesToNodeList() throws Exception {
    LexBIGService lbs = ServiceHolder.instance().getLexBIGService();

    CodedNodeGraph mappingGraph = lbs.getNodeGraph(MAPPING_SCHEME_URI, null, null);

    CodedNodeSet cns =
        mappingGraph.restrictToTargetCodeSystem(PARTS_SCHEME).toNodeList(null, false, true, 0, -1);

    ResolvedConceptReferencesIterator itr = cns.resolve(null, null, null);

    int count = 0;

    Set<String> foundCodes = new HashSet<String>();

    while (itr.hasNext()) {
      count++;
      foundCodes.add(itr.next().getCode());
    }

    assertEquals(3, foundCodes.size());

    assertTrue(foundCodes.contains("R0001"));
    assertTrue(foundCodes.contains("E0001"));
    assertTrue(foundCodes.contains("P0001"));
  }
  public void testNextInt() {
    try {
      LexBIGService lbs = ServiceHolder.instance().getLexBIGService();
      CodedNodeSet cns = lbs.getCodingSchemeConcepts("NCI Thesaurus", null);
      cns = cns.restrictToMatchingDesignations("heart", null, "startsWith", null);

      ResolvedConceptReferencesIterator rcrl = cns.resolve(null, null, null, null, false);

      ResolvedConceptReferenceList list1 = rcrl.next(10);
      ResolvedConceptReferenceList list2 = rcrl.next(10);

      assertFalse(compareResolvedConceptReferenceList(list1, list2));
    } catch (Exception e) {
      fail("Exception Thrown: " + e.getMessage());
      e.printStackTrace();
    }
  }
  /**
   * Get concept Entity by code
   *
   * @param codingScheme
   * @param code
   * @return
   */
  public ResolvedConceptReference getConceptByCode(String codingScheme, String code) {
    CodedNodeSet cns = null;
    ResolvedConceptReferencesIterator iterator = null;

    try {
      LexBIGService lbSvc = RemoteServerUtil.createLexBIGService();
      cns = lbSvc.getCodingSchemeConcepts(codingScheme, null);
      ConceptReferenceList crefs = createConceptReferenceList(new String[] {code}, codingScheme);
      cns.restrictToCodes(crefs);
      iterator = cns.resolve(null, null, null);
      if (iterator.numberRemaining() > 0) {
        ResolvedConceptReference ref = (ResolvedConceptReference) iterator.next();
        return ref;
      }
    } catch (LBException e) {
      _logger.info("Error: " + e.getMessage());
    }

    return null;
  }
  public void testNext() {
    try {
      LexBIGService lbs = ServiceHolder.instance().getLexBIGService();
      CodedNodeSet cns = lbs.getCodingSchemeConcepts("NCI Thesaurus", null);
      cns = cns.restrictToMatchingDesignations("heart", null, "startsWith", null);

      ResolvedConceptReferencesIterator rcrl = cns.resolve(null, null, null, null, false);

      String conceptCode = null;

      while (rcrl.hasNext()) {
        ResolvedConceptReference ref = rcrl.next();
        String currentCode = ref.getConceptCode();
        assertFalse(currentCode.equals(conceptCode));
        conceptCode = currentCode;
      }
    } catch (Exception e) {
      fail("Exception Thrown: " + e.getMessage());
      e.printStackTrace();
    }
  }
  /**
   * Return Iterator for codedNodeGraph
   *
   * @param cng
   * @param graphFocus
   * @param resolveForward
   * @param resolveBackward
   * @param resolveAssociationDepth
   * @param maxToReturn
   * @return
   */
  public ResolvedConceptReferencesIterator codedNodeGraph2CodedNodeSetIterator(
      CodedNodeGraph cng,
      ConceptReference graphFocus,
      boolean resolveForward,
      boolean resolveBackward,
      int resolveAssociationDepth,
      int maxToReturn) {
    CodedNodeSet cns = null;

    try {
      cns =
          cng.toNodeList(
              graphFocus, resolveForward, resolveBackward, resolveAssociationDepth, maxToReturn);
      if (cns == null) return null;
      return cns.resolve(null, null, null);
    } catch (Exception ex) {
      _logger.warn(ex.getMessage());
    }

    return null;
  }