Example usage for java.util List listIterator

List of usage examples for java.util List listIterator

Introduction

In this page you can find the example usage for java.util List listIterator.

Prototype

ListIterator<E> listIterator();

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

From source file:gobblin.salesforce.SalesforceExtractor.java

/**
 * Get Record set using salesforce specific API(Bulk API)
 * @param schema/databasename// w w  w.  ja va  2  s.  c  om
 * @param entity/tablename
 * @param list of all predicate conditions
   * @return iterator with batch of records
 */
private List<String> getQueryResultIds(String schema, String entity, List<Predicate> predicateList)
        throws Exception {
    if (!bulkApiLogin()) {
        throw new IllegalArgumentException("Invalid Login");
    }

    try {
        // Set bulk job attributes
        this.bulkJob.setObject(entity);
        this.bulkJob.setOperation(OperationEnum.query);
        this.bulkJob.setConcurrencyMode(ConcurrencyMode.Parallel);

        // Result type as CSV
        this.bulkJob.setContentType(ContentType.CSV);

        this.bulkJob = bulkConnection.createJob(this.bulkJob);
        this.bulkJob = bulkConnection.getJobStatus(this.bulkJob.getId());

        // Construct query with the predicates
        String query = this.updatedQuery;
        if (!isNullPredicate(predicateList)) {
            String limitString = this.getLimitFromInputQuery(query);
            query = query.replace(limitString, "");

            Iterator<Predicate> i = predicateList.listIterator();
            while (i.hasNext()) {
                Predicate predicate = i.next();
                query = SqlQueryUtils.addPredicate(query, predicate.getCondition());
            }

            query = query + limitString;
        }

        this.log.info("QUERY:" + query);
        ByteArrayInputStream bout = new ByteArrayInputStream(
                query.getBytes(ConfigurationKeys.DEFAULT_CHARSET_ENCODING));

        this.bulkBatchInfo = bulkConnection.createBatchFromStream(this.bulkJob, bout);

        int retryInterval = 30 + (int) Math.ceil((float) this.getExpectedRecordCount() / 10000) * 2;
        this.log.info("Salesforce bulk api retry interval in seconds:" + retryInterval);

        // Get batch info with complete resultset (info id - refers to the resultset id corresponding to entire resultset)
        this.bulkBatchInfo = bulkConnection.getBatchInfo(this.bulkJob.getId(), this.bulkBatchInfo.getId());
        if (this.bulkBatchInfo.getState() == BatchStateEnum.Failed) {
            throw new RuntimeException("Failed to get bulk batch info for jobId "
                    + this.bulkBatchInfo.getJobId() + " error - " + this.bulkBatchInfo.getStateMessage());
        }

        while ((this.bulkBatchInfo.getState() != BatchStateEnum.Completed)
                && (this.bulkBatchInfo.getState() != BatchStateEnum.Failed)) {
            Thread.sleep(retryInterval * 1000);
            this.bulkBatchInfo = bulkConnection.getBatchInfo(this.bulkJob.getId(), this.bulkBatchInfo.getId());
            this.log.debug("Bulk Api Batch Info:" + this.bulkBatchInfo);
            this.log.info("Waiting for bulk resultSetIds");
        }

        // Get resultset ids from the batch info
        QueryResultList list = bulkConnection.getQueryResultList(this.bulkJob.getId(),
                this.bulkBatchInfo.getId());

        return Arrays.asList(list.getResult());

    } catch (Exception e) {
        throw new RuntimeException(
                "Failed to get query result ids from salesforce using bulk api; error - " + e.getMessage(), e);
    }
}

From source file:gov.nih.nci.ncicb.cadsr.contexttree.service.impl.CDEBrowserTreeServiceImpl.java

private void addAllcscsiNodes(List cscsiList, Map cscsiMap, String contextId, LazyActionTreeNode csNode,
        List templateTypes, Map cscsiholderMap) {
    if (cscsiList == null || cscsiMap == null || csNode == null || cscsiholderMap == null)
        return;//from   ww w. j  a  v a  2  s .  c om

    ListIterator it = cscsiList.listIterator();

    while (it.hasNext()) {
        String cscsiId = (String) it.next();

        ClassSchemeItem cscsi = (ClassSchemeItem) cscsiMap.get(cscsiId);
        LazyActionTreeNode node = new LazyActionTreeNode("Folder", cscsi.getClassSchemeItemName(), false);
        csNode.addLeaf(node);
        Map categoryMap = addInitialCategoryNodes(node, templateTypes);
        CsCSICatetegoryHolder cscsiCatHolder = new CsCSICatetegoryHolder();
        cscsiCatHolder.setNode(node);
        cscsiCatHolder.setCategoryHolder(categoryMap);
        cscsiholderMap.put(cscsiId, cscsiCatHolder);
    }
}

From source file:org.apache.fop.layoutmgr.inline.TextLayoutManager.java

/** {@inheritDoc} */
public List addALetterSpaceTo(final List oldList, int depth) {
    // old list contains only a box, or the sequence: box penalty glue box;
    // look at the Position stored in the first element in oldList
    // which is always a box
    ListIterator oldListIterator = oldList.listIterator();
    KnuthElement knuthElement = (KnuthElement) oldListIterator.next();
    Position pos = knuthElement.getPosition();
    LeafPosition leafPos = (LeafPosition) pos.getPosition(depth);
    int index = leafPos.getLeafPos();
    //element could refer to '-1' position, for non-collapsed spaces (?)
    if (index > -1) {
        AreaInfo areaInfo = getAreaInfo(index);
        areaInfo.letterSpaceCount++;/* w w  w .  j a  v a 2 s  . co  m*/
        areaInfo.addToAreaIPD(letterSpaceIPD);
        if (TextLayoutManager.BREAK_CHARS.indexOf(foText.charAt(tempStart - 1)) >= 0) {
            // the last character could be used as a line break
            // append new elements to oldList
            oldListIterator = oldList.listIterator(oldList.size());
            oldListIterator
                    .add(new KnuthPenalty(0, KnuthPenalty.FLAGGED_PENALTY, true, auxiliaryPosition, false));
            oldListIterator.add(new KnuthGlue(letterSpaceIPD, auxiliaryPosition, false));
        } else if (letterSpaceIPD.isStiff()) {
            // constant letter space: replace the box
            // give it the unwrapped position of the replaced element
            oldListIterator.set(new KnuthInlineBox(areaInfo.areaIPD.getOpt(), alignmentContext, pos, false));
        } else {
            // adjustable letter space: replace the glue
            oldListIterator.next(); // this would return the penalty element
            oldListIterator.next(); // this would return the glue element
            oldListIterator.set(
                    new KnuthGlue(letterSpaceIPD.mult(areaInfo.letterSpaceCount), auxiliaryPosition, true));
        }
    }
    return oldList;
}

From source file:gov.nih.nci.ncicb.cadsr.contexttree.service.impl.CDEBrowserTreeServiceImpl.java

private void addAllcscsiNodes(List cscsiList, Map cscsiMap, String contextId, DefaultMutableTreeNode csNode,
        List templateTypes, Map cscsiholderMap, TreeIdGenerator idGen) {
    if (cscsiList == null || cscsiMap == null || csNode == null || cscsiholderMap == null)
        return;// ww  w  .  j a  v a2s. co  m

    ListIterator it = cscsiList.listIterator();

    while (it.hasNext()) {
        String cscsiId = (String) it.next();

        ClassSchemeItem cscsi = (ClassSchemeItem) cscsiMap.get(cscsiId);
        String aUniquesId = contextId + cscsi.getCsCsiIdseq() + System.currentTimeMillis();
        DefaultMutableTreeNode node = this.getWebNode(cscsi.getClassSchemeItemName(), aUniquesId);
        csNode.add(node);
        aUniquesId = idGen.getNewId();
        Map categoryMap = addInitialCategoryNodes(node, aUniquesId, templateTypes);
        CsCsiCategorytHolder cscsiCatHolder = new CsCsiCategorytHolder();
        cscsiCatHolder.setNode(node);
        cscsiCatHolder.setCategoryHolder(categoryMap);
        cscsiholderMap.put(cscsiId, cscsiCatHolder);
    }
}

From source file:org.docx4j.fonts.fop.fonts.truetype.TTFFile.java

private boolean readUnicodeCmap(FontFileReader in, long cmapUniOffset, int encodingID) throws IOException {
    //Read CMAP table and correct mtxTab.index
    int mtxPtr = 0;

    // Read unicode cmap
    seekTab(in, "cmap", cmapUniOffset);
    int cmapFormat = in.readTTFUShort();
    /*int cmap_length =*/ in.readTTFUShort(); //skip cmap length

    if (log.isDebugEnabled()) {
        log.debug("CMAP format: " + cmapFormat);
    }//from   w  w  w. j  av  a2 s  . c o m

    if (cmapFormat == 4) {
        in.skip(2); // Skip version number
        int cmapSegCountX2 = in.readTTFUShort();
        int cmapSearchRange = in.readTTFUShort();
        int cmapEntrySelector = in.readTTFUShort();
        int cmapRangeShift = in.readTTFUShort();

        if (log.isDebugEnabled()) {
            log.debug("segCountX2   : " + cmapSegCountX2);
            log.debug("searchRange  : " + cmapSearchRange);
            log.debug("entrySelector: " + cmapEntrySelector);
            log.debug("rangeShift   : " + cmapRangeShift);
        }

        int[] cmapEndCounts = new int[cmapSegCountX2 / 2];
        int[] cmapStartCounts = new int[cmapSegCountX2 / 2];
        int[] cmapDeltas = new int[cmapSegCountX2 / 2];
        int[] cmapRangeOffsets = new int[cmapSegCountX2 / 2];

        for (int i = 0; i < (cmapSegCountX2 / 2); i++) {
            cmapEndCounts[i] = in.readTTFUShort();
        }

        in.skip(2); // Skip reservedPad

        for (int i = 0; i < (cmapSegCountX2 / 2); i++) {
            cmapStartCounts[i] = in.readTTFUShort();
        }

        for (int i = 0; i < (cmapSegCountX2 / 2); i++) {
            cmapDeltas[i] = in.readTTFShort();
        }

        //int startRangeOffset = in.getCurrentPos();

        for (int i = 0; i < (cmapSegCountX2 / 2); i++) {
            cmapRangeOffsets[i] = in.readTTFUShort();
        }

        int glyphIdArrayOffset = in.getCurrentPos();

        BitSet eightBitGlyphs = new BitSet(256);

        // Insert the unicode id for the glyphs in mtxTab
        // and fill in the cmaps ArrayList

        for (int i = 0; i < cmapStartCounts.length; i++) {

            if (log.isTraceEnabled()) {
                log.trace(i + ": " + cmapStartCounts[i] + " - " + cmapEndCounts[i]);
            }
            if (log.isDebugEnabled()) {
                if (isInPrivateUseArea(cmapStartCounts[i], cmapEndCounts[i])) {
                    log.debug("Font contains glyphs in the Unicode private use area:"
                            + Integer.toHexString(cmapStartCounts[i]) + " - "
                            + Integer.toHexString(cmapEndCounts[i]));
                }
            }

            for (int j = cmapStartCounts[i]; j <= cmapEndCounts[i]; j++) {

                // Update lastChar
                if (j < 256 && j > lastChar) {
                    lastChar = (short) j;
                }

                if (j < 256) {
                    eightBitGlyphs.set(j);
                }

                if (mtxPtr < mtxTab.length) {
                    int glyphIdx;
                    // the last character 65535 = .notdef
                    // may have a range offset
                    if (cmapRangeOffsets[i] != 0 && j != 65535) {
                        int glyphOffset = glyphIdArrayOffset + ((cmapRangeOffsets[i] / 2)
                                + (j - cmapStartCounts[i]) + (i) - cmapSegCountX2 / 2) * 2;
                        in.seekSet(glyphOffset);
                        glyphIdx = (in.readTTFUShort() + cmapDeltas[i]) & 0xffff;

                        unicodeMapping.add(new UnicodeMapping(glyphIdx, j));
                        mtxTab[glyphIdx].getUnicodeIndex().add(new Integer(j));

                        if (encodingID == 0 && j >= 0xF020 && j <= 0xF0FF) {
                            //Experimental: Mapping 0xF020-0xF0FF to 0x0020-0x00FF
                            //Tested with Wingdings and Symbol TTF fonts which map their
                            //glyphs in the region 0xF020-0xF0FF.
                            int mapped = j - 0xF000;
                            if (!eightBitGlyphs.get(mapped)) {
                                //Only map if Unicode code point hasn't been mapped before
                                unicodeMapping.add(new UnicodeMapping(glyphIdx, mapped));
                                mtxTab[glyphIdx].getUnicodeIndex().add(new Integer(mapped));
                            }
                        }

                        // Also add winAnsiWidth
                        List v = (List) ansiIndex.get(new Integer(j));
                        if (v != null) {
                            Iterator e = v.listIterator();
                            while (e.hasNext()) {
                                Integer aIdx = (Integer) e.next();
                                ansiWidth[aIdx.intValue()] = mtxTab[glyphIdx].getWx();

                                if (log.isTraceEnabled()) {
                                    log.trace("Added width " + mtxTab[glyphIdx].getWx() + " uni: " + j
                                            + " ansi: " + aIdx.intValue());
                                }
                            }
                        }

                        if (log.isTraceEnabled()) {
                            log.trace("Idx: " + glyphIdx + " Delta: " + cmapDeltas[i] + " Unicode: " + j
                                    + " name: " + mtxTab[glyphIdx].getName());
                        }
                    } else {
                        glyphIdx = (j + cmapDeltas[i]) & 0xffff;

                        if (glyphIdx < mtxTab.length) {
                            mtxTab[glyphIdx].getUnicodeIndex().add(new Integer(j));
                        } else {
                            log.debug("Glyph " + glyphIdx + " out of range: " + mtxTab.length);
                        }

                        unicodeMapping.add(new UnicodeMapping(glyphIdx, j));
                        if (glyphIdx < mtxTab.length) {
                            mtxTab[glyphIdx].getUnicodeIndex().add(new Integer(j));
                        } else {
                            log.debug("Glyph " + glyphIdx + " out of range: " + mtxTab.length);
                        }

                        // Also add winAnsiWidth
                        List v = (List) ansiIndex.get(new Integer(j));
                        if (v != null) {
                            Iterator e = v.listIterator();
                            while (e.hasNext()) {
                                Integer aIdx = (Integer) e.next();
                                ansiWidth[aIdx.intValue()] = mtxTab[glyphIdx].getWx();
                            }
                        }

                        //getLogger().debug("IIdx: " +
                        //    mtxPtr +
                        //    " Delta: " + cmap_deltas[i] +
                        //    " Unicode: " + j +
                        //    " name: " +
                        //    mtxTab[(j+cmap_deltas[i]) & 0xffff].name);

                    }
                    if (glyphIdx < mtxTab.length) {
                        if (mtxTab[glyphIdx].getUnicodeIndex().size() < 2) {
                            mtxPtr++;
                        }
                    }
                }
            }
        }
    } else {
        log.error("Cmap format not supported: " + cmapFormat);
        return false;
    }
    return true;
}

From source file:org.apache.gobblin.salesforce.SalesforceExtractor.java

@Override
public List<Command> getHighWatermarkMetadata(String schema, String entity, String watermarkColumn,
        List<Predicate> predicateList) throws HighWatermarkException {
    log.debug("Build url to retrieve high watermark");
    String query = "SELECT " + watermarkColumn + " FROM " + entity;
    String defaultPredicate = " " + watermarkColumn + " != null";
    String defaultSortOrder = " ORDER BY " + watermarkColumn + " desc LIMIT 1";

    String existingPredicate = "";
    if (this.updatedQuery != null) {
        String queryLowerCase = this.updatedQuery.toLowerCase();
        int startIndex = queryLowerCase.indexOf(" where ");
        if (startIndex > 0) {
            existingPredicate = this.updatedQuery.substring(startIndex);
        }//from w w w  .j a va  2  s .c  o  m
    }
    query = query + existingPredicate;

    String limitString = getLimitFromInputQuery(query);
    query = query.replace(limitString, "");

    Iterator<Predicate> i = predicateList.listIterator();
    while (i.hasNext()) {
        Predicate predicate = i.next();
        query = SqlQueryUtils.addPredicate(query, predicate.getCondition());
    }
    query = SqlQueryUtils.addPredicate(query, defaultPredicate);
    query = query + defaultSortOrder;
    log.info("QUERY: " + query);

    try {
        return constructGetCommand(this.sfConnector.getFullUri(getSoqlUrl(query)));
    } catch (Exception e) {
        throw new HighWatermarkException(
                "Failed to get salesforce url for high watermark; error - " + e.getMessage(), e);
    }
}

From source file:it.eng.spagobi.commons.presentation.tags.ListTag.java

/**
 * Starting from the module <code>buttonsSB</code> object, 
 * creates all buttons for the jsp list. 
 * @param buttons The list of the buttons 
 * /*  w  ww .  jav  a 2  s .c  o  m*/
 * @throws JspException If any exception occurs.
 */

protected StringBuffer makeButton(List buttons) throws JspException {

    StringBuffer htmlStream = new StringBuffer();

    Iterator iter = buttons.listIterator();
    while (iter.hasNext()) {
        SourceBeanAttribute buttonSBA = (SourceBeanAttribute) iter.next();
        SourceBean buttonSB = (SourceBean) buttonSBA.getValue();

        String buttonName = buttonSB.getName();
        SourceBean conditionsSB = (SourceBean) buttonSB.getAttribute("CONDITIONS");
        SourceBean row;
        try {
            row = new SourceBean("ROWS");
            boolean conditionsVerified = verifyConditions(conditionsSB, row);

            if (ChannelUtilities.isWebRunning()) {
                String onlyPort = (String) buttonSB.getAttribute("onlyPortletRunning");
                if ((onlyPort != null) && onlyPort.equalsIgnoreCase("true")) {
                    continue;
                }
            }
            if (!conditionsVerified) {
                // if conditions are not verified puts an empty column
                _htmlStream
                        .append(" <td class='header-button-column-portlet-section' width='40px'>&nbsp;</td>\n");
                continue;
            }

            List parameters = buttonSB.getAttributeAsList("PARAMETER");
            HashMap paramsMap = getParametersMap(parameters, null);

            String img = (String) buttonSB.getAttribute("image");
            String labelCode = (String) buttonSB.getAttribute("label");

            //String label = PortletUtilities.getMessage(labelCode, "messages");
            String label = msgBuilder.getMessage(labelCode, _bundle, httpRequest);
            String buttonUrl = createUrl(paramsMap);
            buttonUrl = StringEscapeUtils.escapeHtml(buttonUrl);

            htmlStream.append("<td class=\"header-button-column-portlet-section\">\n");
            htmlStream.append(
                    "<a href='" + buttonUrl + "'><img class=\"header-button-image-portlet-section\" title='"
                            + label + "' alt='" + label + "' src='"
                            + urlBuilder.getResourceLinkByTheme(httpRequest, img, currTheme) + "' /></a>\n");
            htmlStream.append("</td>\n");
        } catch (SourceBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return htmlStream;
}

From source file:co.cask.cdap.common.conf.Configuration.java

private <T> void toString(List<T> resources, StringBuilder sb) {
    ListIterator<T> i = resources.listIterator();
    while (i.hasNext()) {
        if (i.nextIndex() != 0) {
            sb.append(", ");
        }/* w  w w  . j a  v  a  2 s  . com*/
        sb.append(i.next());
    }
}

From source file:omr.sheet.LinesBuilder.java

/**
 * Staff are detected in the list of (raw) peaks, simply by looking for
 * regular series of peaks.//from   ww w.  jav a  2 s.c o  m
 *
 * @param peaks the raw list of peaks found
 */
private void retrieveStaves(List<Peak> peaks) throws StepException {
    // One single iterator, since from peak area to peak area, we keep
    // moving forward in an ordered list of vertices
    ArrayList<GlyphSection> vertices = new ArrayList<GlyphSection>(lag.getVertices());
    Collections.sort(vertices, Section.idComparator);

    ListIterator<GlyphSection> vi = vertices.listIterator();

    // Maximum deviation accepted in the series of peaks in a staff
    final double maxDeviation = scale.toPixelsDouble(constants.maxInterlineDeviation);

    // Maximum difference in interval between a 6th line and the average
    // interval in the previous 5 lines
    final double maxDiff = scale.toPixelsDouble(constants.maxInterlineDiffFrac);

    // Desired length of series (TODO)
    final int interlineNb = 4;

    int firstPeak = 0;
    int lastPeak = 0;
    Population intervals = new Population();
    LineBuilder.reset();

    // Use a new staff retriever
    StaffBuilder staffBuilder = new StaffBuilder(sheet, lag, vi);

    // Browse through the peak list
    Peak prevPeak = null;

    for (ListIterator<Peak> li = peaks.listIterator(); li.hasNext();) {
        // Get peak at hand
        Peak peak = li.next();

        if (logger.isFineEnabled()) {
            logger.fine((li.nextIndex() - 1) + " " + peak);
        }

        // If very first one, we don't yet have intervals
        if (li.nextIndex() == 1) {
            prevPeak = peak;

            continue;
        }

        // Compute interval with previous peak
        double interval = computeInterval(prevPeak, peak);

        if (logger.isFineEnabled()) {
            logger.fine("interval=" + interval);
        }

        intervals.includeValue(interval);
        prevPeak = peak;

        // Check for regularity of current series
        if (intervals.getCardinality() > 1) {
            double stdDev = intervals.getStandardDeviation();

            if (logger.isFineEnabled()) {
                logger.fine("stdDev=" + (float) stdDev);
            }

            if (stdDev > maxDeviation) {
                if (logger.isFineEnabled()) {
                    logger.fine("Interval gap detected");
                }

                intervals.reset(interval);
            } else if (intervals.getCardinality() == interlineNb) {
                if (logger.isFineEnabled()) {
                    logger.fine("End of staff");
                }

                // We have a suitable series.  However, let's look for a
                // better sixth one if any on the other side of the staff
                lastPeak = li.nextIndex() - 1;
                firstPeak = lastPeak - interlineNb;

                if (li.hasNext()) {
                    Peak nextPeak = li.next();
                    interval = computeInterval(peak, nextPeak);

                    if ((Math.abs(interval - intervals.getMeanValue()) <= maxDiff) // Good candidate, compare with first one
                            && (nextPeak.getMax() > peaks.get(firstPeak).getMax())) {
                        if (logger.isFineEnabled()) {
                            logger.fine("Moving to sixth line");
                        }

                        // Fix computation of interval value
                        intervals.excludeValue(computeInterval(peaks.get(firstPeak), peaks.get(firstPeak + 1)));
                        intervals.includeValue(interval);

                        // Update indices
                        firstPeak++;
                        lastPeak++;
                    } else {
                        li.previous(); // Undo the move to the sixth peak
                    }
                }

                // We now have a set of peaks that signals a staff area
                if (logger.isFineEnabled()) {
                    logger.fine("Staff from peaks " + firstPeak + " to " + lastPeak);
                }

                staves.add(staffBuilder.buildInfo(peaks.subList(firstPeak, lastPeak + 1),
                        intervals.getMeanValue()));

                if (logger.isFineEnabled()) {
                    System.out.println();
                }

                // Move to the next peak, candidate for starting a new
                // staff
                if (li.hasNext()) {
                    intervals.reset();
                    prevPeak = li.next();

                    if (logger.isFineEnabled()) {
                        logger.fine((li.nextIndex() - 1) + " " + prevPeak);
                    }
                }
            }
        }
    }
}

From source file:org.ambraproject.service.article.BrowseServiceImpl.java

/**
 *
 *//*from w  ww .  ja va2s  .  co  m*/
@Override
public List<TOCArticleGroup> buildArticleGroups(IssueInfo issue, List<TOCArticleGroup> articleGroups,
        String authId) {

    //There are some pretty big inefficiencies here.  We load up complete article classes when
    //we only need doi/title/authors.  A new TOCArticle class should probably be created once article lazy
    //loading is working correctly
    List<TOCArticle> articlesInIssue = articleService.getArticleTOCEntries(issue.getArticleUriList(), authId);

    /*
     * For every article that is of the same ArticleType as a TOCArticleGroup, add it to that group.
     * Articles can appear in multiple TOCArticleGroups.
     */
    for (TOCArticle ai : articlesInIssue)
        for (TOCArticleGroup ag : articleGroups)
            for (ArticleType articleType : ai.getArticleTypes())
                if (ag.getArticleType().equals(articleType)) {
                    ag.addArticle(ai);
                    break;
                }

    Iterator iter = articleGroups.listIterator();
    Integer i = 0;

    while (iter.hasNext()) {
        TOCArticleGroup ag = (TOCArticleGroup) iter.next();
        // remove the group if it has no articles
        if (ag.articles.size() == 0) {
            iter.remove();
            continue;
        }
        // If we respect order then don't sort.
        if (!issue.isRespectOrder()) {
            ag.setId("tocGrp_" + (i++));
            ag.sortArticles();
        }
    }

    return articleGroups;
}