/**
   * Create the ValueObject collection to hold the set of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectSet - Set of ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem
   *     objects.
   */
  public static ims.ocrr.vo.SpecimenWorkListItemListVoCollection
      createSpecimenWorkListItemListVoCollectionFromSpecimenWorkListItem(
          DomainObjectMap map, java.util.Set domainObjectSet) {
    ims.ocrr.vo.SpecimenWorkListItemListVoCollection voList =
        new ims.ocrr.vo.SpecimenWorkListItemListVoCollection();
    if (null == domainObjectSet) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    java.util.Iterator iterator = domainObjectSet.iterator();
    while (iterator.hasNext()) {
      ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem domainObject =
          (ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem) iterator.next();
      ims.ocrr.vo.SpecimenWorkListItemListVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }
    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject collection to hold the list of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectList - List of ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem
   *     objects.
   */
  public static ims.ocrr.vo.SpecimenWorkListItemListVoCollection
      createSpecimenWorkListItemListVoCollectionFromSpecimenWorkListItem(
          DomainObjectMap map, java.util.List domainObjectList) {
    ims.ocrr.vo.SpecimenWorkListItemListVoCollection voList =
        new ims.ocrr.vo.SpecimenWorkListItemListVoCollection();
    if (null == domainObjectList) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    for (int i = 0; i < domainObjectList.size(); i++) {
      ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem domainObject =
          (ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem) domainObjectList.get(i);
      ims.ocrr.vo.SpecimenWorkListItemListVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }

    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  public static java.util.Set extractSpecimenWorkListItemSet(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.ocrr.vo.SpecimenWorkListItemListVoCollection voCollection,
      java.util.Set domainObjectSet,
      HashMap domMap) {
    int size = (null == voCollection) ? 0 : voCollection.size();
    if (domainObjectSet == null) {
      domainObjectSet = new java.util.HashSet();
    }
    java.util.Set newSet = new java.util.HashSet();
    for (int i = 0; i < size; i++) {
      ims.ocrr.vo.SpecimenWorkListItemListVo vo = voCollection.get(i);
      ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem domainObject =
          SpecimenWorkListItemListVoAssembler.extractSpecimenWorkListItem(
              domainFactory, vo, domMap);

      // TODO: This can only occur in the situation of a stale object exception. For now leave it to
      // the Interceptor to handle it.
      if (domainObject == null) {
        continue;
      }

      // Trying to avoid the hibernate collection being marked as dirty via its public interface
      // methods. (like add)
      if (!domainObjectSet.contains(domainObject)) domainObjectSet.add(domainObject);
      newSet.add(domainObject);
    }
    java.util.Set removedSet = new java.util.HashSet();
    java.util.Iterator iter = domainObjectSet.iterator();
    // Find out which objects need to be removed
    while (iter.hasNext()) {
      ims.domain.DomainObject o = (ims.domain.DomainObject) iter.next();
      if ((o == null || o.getIsRIE() == null || !o.getIsRIE().booleanValue())
          && !newSet.contains(o)) {
        removedSet.add(o);
      }
    }
    iter = removedSet.iterator();
    // Remove the unwanted objects
    while (iter.hasNext()) {
      domainObjectSet.remove(iter.next());
    }
    return domainObjectSet;
  }
  public static java.util.List extractSpecimenWorkListItemList(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.ocrr.vo.SpecimenWorkListItemListVoCollection voCollection,
      java.util.List domainObjectList,
      HashMap domMap) {
    int size = (null == voCollection) ? 0 : voCollection.size();
    if (domainObjectList == null) {
      domainObjectList = new java.util.ArrayList();
    }
    for (int i = 0; i < size; i++) {
      ims.ocrr.vo.SpecimenWorkListItemListVo vo = voCollection.get(i);
      ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem domainObject =
          SpecimenWorkListItemListVoAssembler.extractSpecimenWorkListItem(
              domainFactory, vo, domMap);

      // TODO: This can only occur in the situation of a stale object exception. For now leave it to
      // the Interceptor to handle it.
      if (domainObject == null) {
        continue;
      }

      int domIdx = domainObjectList.indexOf(domainObject);
      if (domIdx == -1) {
        domainObjectList.add(i, domainObject);
      } else if (i != domIdx && i < domainObjectList.size()) {
        Object tmp = domainObjectList.get(i);
        domainObjectList.set(i, domainObjectList.get(domIdx));
        domainObjectList.set(domIdx, tmp);
      }
    }

    // Remove all ones in domList where index > voCollection.size() as these should
    // now represent the ones removed from the VO collection. No longer referenced.
    int i1 = domainObjectList.size();
    while (i1 > size) {
      domainObjectList.remove(i1 - 1);
      i1 = domainObjectList.size();
    }
    return domainObjectList;
  }