Example usage for java.util ListIterator previous

List of usage examples for java.util ListIterator previous

Introduction

In this page you can find the example usage for java.util ListIterator previous.

Prototype

E previous();

Source Link

Document

Returns the previous element in the list and moves the cursor position backwards.

Usage

From source file:org.squashtest.tm.service.importer.ImportLog.java

/**
 *
 * <p>The logs for the datasets also contain the logs for the dataset parameter values.
 * Since they were inserted separately we need to purge them from redundant informations.</p>
 *
 * <p>To ensure consistency we need to check that, for each imported line, there can be
 *   a log entry with status OK if this is the unique log entry for that line.
 *   From a procedural point of view we need, for each imported lines, to remove a log entry
 *   if it has a status OK and ://  w  w w. j  a  va 2 s .c  om
 * <ul>
 *    <li>there was already a status OK for that line, or</li>
 *    <li>there is at least 1 warning or error</li>
 * </ul>
 * </p>
 *
 */

/*
 * NB : This code relies on the fact that the log entries are sorted by import line number then by status,
 * and that the status OK comes first.
 *
 * Basically the job boils down to the following rules :
 *
 * for each line, for each entry, if there was a previous element with status OK on this line -> remove it.
 *
 */
public void packLogs() {

    LinkedList<LogEntry> listiterableLogs = new LinkedList<>(findAllFor(DATASET));

    Integer precLine = null;
    boolean okFoundOnPrecEntry = false;

    ListIterator<LogEntry> iter = listiterableLogs.listIterator();

    while (iter.hasNext()) {

        LogEntry entry = iter.next();
        Integer curLine = entry.getLine();
        ImportStatus curStatus = entry.getStatus();

        /*
         * if we found an occurence on the previous entry
         * and the current entry concerns the same line and
         * remove it.
         */
        if (okFoundOnPrecEntry && curLine.equals(precLine)) {

            // finding the previous element actually means
            // to backtrack twice (because the cursor points
            // to the next element already)

            iter.previous();
            iter.previous();

            iter.remove();

            // now we replace the cursor where it was before
            // the 'if'.
            iter.next();

        }

        // now we set our flag according to the status of the
        // current entry and update precLine
        okFoundOnPrecEntry = curStatus == OK;
        precLine = curLine;
    }

    // once complete we replace the original list with the filtered one
    findAllFor(DATASET).clear();
    logEntriesPerType.putAll(DATASET, listiterableLogs);

}

From source file:org.apache.hadoop.hbase.regionserver.RegionMergeTransaction.java

/**
 * @param server Hosting server instance (May be null when testing).
 * @param services Services of regionserver, used to online regions.
 * @throws IOException If thrown, rollback failed. Take drastic action.
 * @return True if we successfully rolled back, false if we got to the point
 *         of no return and so now need to abort the server to minimize
 *         damage./*from  ww  w  .  j  a v  a2  s  . c om*/
 */
@SuppressWarnings("deprecation")
public boolean rollback(final Server server, final RegionServerServices services) throws IOException {
    assert this.mergedRegionInfo != null;
    // Coprocessor callback
    if (rsCoprocessorHost != null) {
        rsCoprocessorHost.preRollBackMerge(this.region_a, this.region_b);
    }

    boolean result = true;
    ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size());
    // Iterate in reverse.
    while (iterator.hasPrevious()) {
        JournalEntry je = iterator.previous();
        switch (je) {

        case SET_MERGING_IN_ZK:
            if (server != null && server.getZooKeeper() != null) {
                cleanZK(server, this.mergedRegionInfo);
            }
            break;

        case CREATED_MERGE_DIR:
            this.region_a.writestate.writesEnabled = true;
            this.region_b.writestate.writesEnabled = true;
            this.region_a.getRegionFileSystem().cleanupMergesDir();
            break;

        case CLOSED_REGION_A:
            try {
                // So, this returns a seqid but if we just closed and then reopened,
                // we should be ok. On close, we flushed using sequenceid obtained
                // from hosting regionserver so no need to propagate the sequenceid
                // returned out of initialize below up into regionserver as we
                // normally do.
                this.region_a.initialize();
            } catch (IOException e) {
                LOG.error(
                        "Failed rollbacking CLOSED_REGION_A of region " + this.region_a.getRegionNameAsString(),
                        e);
                throw new RuntimeException(e);
            }
            break;

        case OFFLINED_REGION_A:
            if (services != null)
                services.addToOnlineRegions(this.region_a);
            break;

        case CLOSED_REGION_B:
            try {
                this.region_b.initialize();
            } catch (IOException e) {
                LOG.error(
                        "Failed rollbacking CLOSED_REGION_A of region " + this.region_b.getRegionNameAsString(),
                        e);
                throw new RuntimeException(e);
            }
            break;

        case OFFLINED_REGION_B:
            if (services != null)
                services.addToOnlineRegions(this.region_b);
            break;

        case STARTED_MERGED_REGION_CREATION:
            this.region_a.getRegionFileSystem().cleanupMergedRegion(this.mergedRegionInfo);
            break;

        case PONR:
            // We got to the point-of-no-return so we need to just abort. Return
            // immediately. Do not clean up created merged regions.
            return false;

        default:
            throw new RuntimeException("Unhandled journal entry: " + je);
        }
    }
    // Coprocessor callback
    if (rsCoprocessorHost != null) {
        rsCoprocessorHost.postRollBackMerge(this.region_a, this.region_b);
    }

    return result;
}

From source file:com.bt.aloha.dialog.state.DialogInfo.java

public void setRouteList(ListIterator<?> recordRouteHeaderIterator, boolean backwards) {
    routeList = new RouteList();
    if (recordRouteHeaderIterator == null)
        return;/*  w ww .j  av  a  2  s .c  o  m*/

    if (backwards)
        while (recordRouteHeaderIterator.hasNext())
            recordRouteHeaderIterator.next();

    while (backwards ? recordRouteHeaderIterator.hasPrevious() : recordRouteHeaderIterator.hasNext()) {
        RecordRouteHeader recordRouteHeader = backwards
                ? (RecordRouteHeader) recordRouteHeaderIterator.previous()
                : (RecordRouteHeader) recordRouteHeaderIterator.next();
        Route route = new Route();
        AddressImpl address = (AddressImpl) ((AddressImpl) recordRouteHeader.getAddress()).clone();
        route.setAddress(address);
        NameValueList nameValueList = new NameValueList();
        Iterator<?> paramIterator = recordRouteHeader.getParameterNames();
        while (paramIterator.hasNext()) {
            String paramName = (String) paramIterator.next();
            nameValueList.set(paramName, recordRouteHeader.getParameter(paramName));
        }
        route.setParameters(nameValueList);
        log.debug(String.format("Added route address %s, params %s to route set for dialog %s", address,
                nameValueList.toString(), getId()));
        routeList.add(route);
    }
}

From source file:org.apache.hadoop.hbase.regionserver.SplitTransaction.java

/**
 * @param server Hosting server instance (May be null when testing).
 * @param services/*from ww w.j av a  2 s  .  co  m*/
 * @throws IOException If thrown, rollback failed.  Take drastic action.
 * @return True if we successfully rolled back, false if we got to the point
 * of no return and so now need to abort the server to minimize damage.
 */
@SuppressWarnings("deprecation")
public boolean rollback(final Server server, final RegionServerServices services) throws IOException {
    // Coprocessor callback
    if (this.parent.getCoprocessorHost() != null) {
        this.parent.getCoprocessorHost().preRollBackSplit();
    }

    boolean result = true;
    ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size());
    // Iterate in reverse.
    while (iterator.hasPrevious()) {
        JournalEntry je = iterator.previous();
        switch (je) {

        case SET_SPLITTING_IN_ZK:
            if (server != null && server.getZooKeeper() != null) {
                cleanZK(server, this.parent.getRegionInfo());
            }
            break;

        case CREATE_SPLIT_DIR:
            this.parent.writestate.writesEnabled = true;
            this.parent.getRegionFileSystem().cleanupSplitsDir();
            break;

        case CLOSED_PARENT_REGION:
            try {
                // So, this returns a seqid but if we just closed and then reopened, we
                // should be ok. On close, we flushed using sequenceid obtained from
                // hosting regionserver so no need to propagate the sequenceid returned
                // out of initialize below up into regionserver as we normally do.
                // TODO: Verify.
                this.parent.initialize();
            } catch (IOException e) {
                LOG.error("Failed rollbacking CLOSED_PARENT_REGION of region "
                        + this.parent.getRegionNameAsString(), e);
                throw new RuntimeException(e);
            }
            break;

        case STARTED_REGION_A_CREATION:
            this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_a);
            break;

        case STARTED_REGION_B_CREATION:
            this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_b);
            break;

        case OFFLINED_PARENT:
            if (services != null)
                services.addToOnlineRegions(this.parent);
            break;

        case PONR:
            // We got to the point-of-no-return so we need to just abort. Return
            // immediately.  Do not clean up created daughter regions.  They need
            // to be in place so we don't delete the parent region mistakenly.
            // See HBASE-3872.
            return false;

        default:
            throw new RuntimeException("Unhandled journal entry: " + je);
        }
    }
    // Coprocessor callback
    if (this.parent.getCoprocessorHost() != null) {
        this.parent.getCoprocessorHost().postRollBackSplit();
    }
    return result;
}

From source file:com.fastbootmobile.encore.app.fragments.PlaylistViewFragment.java

private void playNext() {
    // playNext adds elements after the current playing one. If we want to play the playlist
    // in the proper order, we need to put it backwards.
    ListIterator<String> it = mPlaylist.songsList().listIterator();
    while (it.hasNext()) {
        it.next();/*from w w w .j  a v  a 2  s .  co  m*/
    }

    final ProviderAggregator aggregator = ProviderAggregator.getDefault();
    while (it.hasPrevious()) {
        PlaybackProxy.playNext(aggregator.retrieveSong(it.previous(), mPlaylist.getProvider()));
    }
}

From source file:org.apache.poi.ss.format.CellNumberFormatter.java

private Special previousNumber() {
    ListIterator<Special> it = specials.listIterator(specials.size());
    while (it.hasPrevious()) {
        Special s = it.previous();
        if (isDigitFmt(s)) {
            Special numStart = s;/* w  w  w  . j av  a2  s .  c o  m*/
            Special last = s;
            while (it.hasPrevious()) {
                s = it.previous();
                if (last.pos - s.pos > 1) // it has to be continuous digits
                    break;
                if (isDigitFmt(s))
                    numStart = s;
                else
                    break;
                last = s;
            }
            return numStart;
        }
    }
    return null;
}

From source file:org.apache.hadoop.hbase.regionserver.IndexSplitTransaction.java

/**
 * @param server Hosting server instance (May be null when testing).
 * @param services/*from ww  w .j  av a 2  s. com*/
 * @throws IOException If thrown, rollback failed.  Take drastic action.
 * @return True if we successfully rolled back, false if we got to the point
 * of no return and so now need to abort the server to minimize damage.
 */
@Override
@SuppressWarnings("deprecation")
public boolean rollback(final Server server, final RegionServerServices services) throws IOException {
    // Coprocessor callback
    if (this.parent.getCoprocessorHost() != null) {
        this.parent.getCoprocessorHost().preRollBackSplit();
    }

    boolean result = true;
    ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size());
    // Iterate in reverse.
    while (iterator.hasPrevious()) {
        JournalEntry je = iterator.previous();
        switch (je) {

        case SET_SPLITTING_IN_ZK:
            if (server != null && server.getZooKeeper() != null) {
                cleanZK(server, this.parent.getRegionInfo());
            }
            break;

        case CREATE_SPLIT_DIR:
            this.parent.writestate.writesEnabled = true;
            this.parent.getRegionFileSystem().cleanupSplitsDir();
            break;

        case CLOSED_PARENT_REGION:
            try {
                // So, this returns a seqid but if we just closed and then reopened, we
                // should be ok. On close, we flushed using sequenceid obtained from
                // hosting regionserver so no need to propagate the sequenceid returned
                // out of initialize below up into regionserver as we normally do.
                // TODO: Verify.
                this.parent.initialize();
            } catch (IOException e) {
                LOG.error("Failed rollbacking CLOSED_PARENT_REGION of region "
                        + this.parent.getRegionInfo().getRegionNameAsString(), e);
                throw new RuntimeException(e);
            }
            break;

        case STARTED_REGION_A_CREATION:
            this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_a);
            break;

        case STARTED_REGION_B_CREATION:
            this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_b);
            break;

        case OFFLINED_PARENT:
            if (services != null)
                services.addToOnlineRegions(this.parent);
            break;

        case PONR:
            // We got to the point-of-no-return so we need to just abort. Return
            // immediately.  Do not clean up created daughter regions.  They need
            // to be in place so we don't delete the parent region mistakenly.
            // See HBASE-3872.
            return false;

        default:
            throw new RuntimeException("Unhandled journal entry: " + je);
        }
    }
    // Coprocessor callback
    if (this.parent.getCoprocessorHost() != null) {
        this.parent.getCoprocessorHost().postRollBackSplit();
    }
    return result;
}

From source file:org.libreplan.business.resources.entities.Resource.java

private CriterionSatisfaction getPrevious(ListIterator<CriterionSatisfaction> listIterator) {
    listIterator.previous();
    try {//w  ww .j  a v a 2s  .com
        if (listIterator.hasPrevious()) {
            CriterionSatisfaction result = listIterator.previous();
            listIterator.next();
            return result;
        }
        return null;
    } finally {
        listIterator.next();
    }
}

From source file:org.apache.fop.layoutmgr.AbstractBreaker.java

/**
 * Gets the next block list (sequence) and adds it to a list of block lists
 * if it's not empty.//from   w  ww .ja  v a2  s.  c  o  m
 *
 * @param childLC LayoutContext to use
 * @param nextSequenceStartsOn indicates on what page the next sequence
 * should start
 * @param positionAtIPDChange last element on the part before an IPD change
 * @param restartAtLM the layout manager from which to restart, if IPD
 * change occurs between two LMs
 * @param firstElements elements from non-restartable LMs on the new page
 * @return the page on which the next content should appear after a hard
 * break
 */
protected int getNextBlockList(LayoutContext childLC, int nextSequenceStartsOn, Position positionAtIPDChange,
        LayoutManager restartAtLM, List<KnuthElement> firstElements) {
    updateLayoutContext(childLC);
    //Make sure the span change signal is reset
    childLC.signalSpanChange(Constants.NOT_SET);

    BlockSequence blockList;
    List<KnuthElement> returnedList;
    if (firstElements == null) {
        returnedList = getNextKnuthElements(childLC, alignment);
    } else if (positionAtIPDChange == null) {
        /*
         * No restartable element found after changing IPD break. Simply add the
         * non-restartable elements found after the break.
         */
        returnedList = firstElements;
        /*
         * Remove the last 3 penalty-filler-forced break elements that were added by
         * the Knuth algorithm. They will be re-added later on.
         */
        ListIterator iter = returnedList.listIterator(returnedList.size());
        for (int i = 0; i < 3; i++) {
            iter.previous();
            iter.remove();
        }
    } else {
        returnedList = getNextKnuthElements(childLC, alignment, positionAtIPDChange, restartAtLM);
        returnedList.addAll(0, firstElements);
    }
    if (returnedList != null) {
        if (returnedList.isEmpty()) {
            nextSequenceStartsOn = handleSpanChange(childLC, nextSequenceStartsOn);
            return nextSequenceStartsOn;
        }
        blockList = new BlockSequence(nextSequenceStartsOn, getCurrentDisplayAlign());

        //Only implemented by the PSLM
        nextSequenceStartsOn = handleSpanChange(childLC, nextSequenceStartsOn);

        Position breakPosition = null;
        if (ElementListUtils.endsWithForcedBreak(returnedList)) {
            KnuthPenalty breakPenalty = (KnuthPenalty) ListUtil.removeLast(returnedList);
            breakPosition = breakPenalty.getPosition();
            log.debug("PLM> break - " + getBreakClassName(breakPenalty.getBreakClass()));
            switch (breakPenalty.getBreakClass()) {
            case Constants.EN_PAGE:
                nextSequenceStartsOn = Constants.EN_ANY;
                break;
            case Constants.EN_COLUMN:
                //TODO Fix this when implementing multi-column layout
                nextSequenceStartsOn = Constants.EN_COLUMN;
                break;
            case Constants.EN_ODD_PAGE:
                nextSequenceStartsOn = Constants.EN_ODD_PAGE;
                break;
            case Constants.EN_EVEN_PAGE:
                nextSequenceStartsOn = Constants.EN_EVEN_PAGE;
                break;
            default:
                throw new IllegalStateException("Invalid break class: " + breakPenalty.getBreakClass());
            }
        }
        blockList.addAll(returnedList);
        BlockSequence seq;
        seq = blockList.endBlockSequence(breakPosition);
        if (seq != null) {
            blockLists.add(seq);
        }
    }
    return nextSequenceStartsOn;
}

From source file:org.apache.openjpa.jdbc.kernel.exps.PCPath.java

/**
 * Return the last action that gets a field.
 *//*from  w w  w  .j av  a  2s.  c  om*/
private Action lastFieldAction() {
    if (_actions == null)
        return null;

    if (isXPath())
        return (Action) _actions.getLast();

    ListIterator itr = _actions.listIterator(_actions.size());
    Action prev;
    while (itr.hasPrevious()) {
        prev = (Action) itr.previous();
        if (prev.op == Action.GET || prev.op == Action.GET_OUTER || prev.op == Action.GET_KEY)
            return prev;
    }
    return null;
}