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:com.haulmont.cuba.core.sys.MetadataImpl.java

protected void invokePostConstructMethods(Entity entity)
        throws InvocationTargetException, IllegalAccessException {
    List<Method> postConstructMethods = new ArrayList<>(4);
    List<String> methodNames = new ArrayList<>(4);
    Class clazz = entity.getClass();
    while (clazz != Object.class) {
        Method[] classMethods = clazz.getDeclaredMethods();
        for (Method method : classMethods) {
            if (method.isAnnotationPresent(PostConstruct.class) && !methodNames.contains(method.getName())) {
                postConstructMethods.add(method);
                methodNames.add(method.getName());
            }//  w w w  . ja v a 2  s. co m
        }
        clazz = clazz.getSuperclass();
    }

    ListIterator<Method> iterator = postConstructMethods.listIterator(postConstructMethods.size());
    while (iterator.hasPrevious()) {
        Method method = iterator.previous();
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        method.invoke(entity);
    }
}

From source file:com.google.gwt.emultest.java.util.ListTestBase.java

public void testListIteratorAddInSeveralPositions() {
    List l = makeEmptyList();// w  w w.  j a v  a  2  s. c o m
    ListIterator i = l.listIterator();
    l.add(new Integer(0));
    for (int n = 2; n < 5; n += 2) {
        l.add(new Integer(n));
    }
    i = l.listIterator();
    i.next();
    i.add(new Integer(1));
    i.next();
    i.next();
    i.previous();
    i.add(new Integer(3));
    i.next();
    i.add(new Integer(5));
    i.add(new Integer(6));
    for (int n = 0; n < 6; n++) {
        assertEquals(new Integer(n), l.get(n));
    }
}

From source file:com.galenframework.speclang2.pagespec.PageSectionProcessor.java

private Pair<PageRule, Map<String, String>> findAndProcessRule(String ruleText, StructNode ruleNode) {
    ListIterator<Pair<Rule, PageRule>> iterator = pageSpecHandler.getPageRules()
            .listIterator(pageSpecHandler.getPageRules().size());
    /*/*ww w . j  a va 2  s .c  o  m*/
    It is important to make a reversed iteration over all rules so that
    it is possible for the end user to override previously defined rules
     */

    while (iterator.hasPrevious()) {
        Pair<Rule, PageRule> rulePair = iterator.previous();
        Matcher matcher = rulePair.getKey().getPattern().matcher(ruleText);
        if (matcher.matches()) {
            int index = 1;

            Map<String, String> parameters = new HashMap<>();

            for (String parameterName : rulePair.getKey().getParameters()) {
                String value = matcher.group(index);
                pageSpecHandler.setGlobalVariable(parameterName, value, ruleNode);

                parameters.put(parameterName, value);
                index += 1;
            }

            return new ImmutablePair<>(rulePair.getValue(), parameters);
        }
    }
    throw new SyntaxException(ruleNode, "Couldn't find rule matching: " + ruleText);
}

From source file:com.bwc.ora.models.Lrp.java

public List<XYSeries> getFWHMForLRPPeaks(XYSeries lrpPeaks, XYSeries lrpSeries) {
    LinkedList<XYSeries> seriesList = new LinkedList<>();
    List<XYDataItem> pointList = (List<XYDataItem>) lrpSeries.getItems();
    List<XYDataItem> peakList = (List<XYDataItem>) lrpPeaks.getItems();
    //iterate through the peaks, process FWHM for each peak
    for (XYDataItem peak : peakList) {
        //grab index of the closest point to the peak
        int peakIndex = -1;
        for (XYDataItem pnt : pointList) {
            peakIndex++;//w  w  w.j  a va2s  . co  m
            if (Math.abs(pnt.getXValue() - peak.getXValue()) < 0.6D) {
                break;
            }
        }
        //calculate point with Y value of valley to the left of peak
        XYDataItem leftValleyPoint = null;
        ListIterator<XYDataItem> it = pointList.listIterator(peakIndex);
        double prevY = peak.getYValue();
        while (it.hasPrevious()) {
            XYDataItem leftPoint = it.previous();
            if (leftPoint.getYValue() <= prevY) {
                prevY = leftPoint.getYValue();
                leftValleyPoint = leftPoint;
            } else {
                break;
            }
        }
        //calculate point with Y value of valley to the right of peak
        XYDataItem rightValleyPoint = null;
        it = pointList.listIterator(peakIndex);
        prevY = peak.getYValue();
        while (it.hasNext()) {
            XYDataItem rightPoint = it.next();
            if (rightPoint.getYValue() <= prevY) {
                prevY = rightPoint.getYValue();
                rightValleyPoint = rightPoint;
            } else {
                break;
            }
        }
        //determine half max Y value
        double halfMaxYValue;
        if (rightValleyPoint.getYValue() == leftValleyPoint.getYValue()) {
            halfMaxYValue = peak.getYValue() - ((peak.getYValue() - leftValleyPoint.getYValue()) / 2D);
        } else if (rightValleyPoint.getYValue() > leftValleyPoint.getYValue()) {
            halfMaxYValue = peak.getYValue() - ((peak.getYValue() - rightValleyPoint.getYValue()) / 2D);
        } else {
            halfMaxYValue = peak.getYValue() - ((peak.getYValue() - leftValleyPoint.getYValue()) / 2D);
        }
        //determine the X value on both sides of the peak that corresponds to the half max Y value
        double leftX = pointList.get(0).getXValue(), rightX = pointList.get(pointList.size() - 1).getXValue();
        XYDataItem prevPoint = pointList.get(peakIndex);
        it = pointList.listIterator(peakIndex);
        while (it.hasPrevious()) {
            XYDataItem leftPoint = it.previous();
            if (leftPoint.getYValue() == halfMaxYValue) {
                leftX = leftPoint.getXValue();
                break;
            } else {
                if (leftPoint.getYValue() < halfMaxYValue) {
                    //                        System.out.println("Left X for peak (" + peak.getXValue() + "," + peak.getYValue() + "): ");
                    leftX = calculateXFromYForLineWithTwoPoints(leftPoint, prevPoint, halfMaxYValue);
                    //                        System.out.println("    Left X: (" + leftX + "," + halfMaxYValue + "): ");
                    break;
                } else {
                    prevPoint = leftPoint;
                }
            }
        }
        prevPoint = pointList.get(peakIndex);
        it = pointList.listIterator(peakIndex);
        while (it.hasNext()) {
            XYDataItem rightPoint = it.next();
            if (rightPoint.getYValue() == halfMaxYValue) {
                rightX = rightPoint.getXValue();
                break;
            } else {
                if (rightPoint.getYValue() < halfMaxYValue) {
                    //                        System.out.println("Right X for peak (" + peak.getXValue() + "," + peak.getYValue() + "): ");
                    rightX = calculateXFromYForLineWithTwoPoints(rightPoint, prevPoint, halfMaxYValue);
                    //                        System.out.println("    Right X: (" + leftX + "," + halfMaxYValue + "): ");
                    break;
                } else {
                    prevPoint = rightPoint;
                }
            }
        }
        //store the two points for the half max full width line for this peak
        XYSeries peakSeries = new XYSeries("(" + peak.getXValue() + "," + peak.getYValue() + ")FWHM");
        peakSeries.add(leftX, halfMaxYValue);
        peakSeries.add(rightX, halfMaxYValue);
        seriesList.add(peakSeries);
    }
    return seriesList;
}

From source file:org.echocat.jomon.maven.boot.ArtifactFactory.java

@Nullable
protected String selectLatestMatchingVersion(@Nonnull ArtifactRepositoryMetadata repositoryMetadata,
        @Nonnull Artifact artifact) {//from  ww w . j ava2  s  . c o m
    final Metadata metadata = repositoryMetadata.getMetadata();
    String latestMatchingVersion = null;
    final Versioning versioning = metadata.getVersioning();
    if (versioning != null) {
        final List<String> versions = versioning.getVersions();
        final ListIterator<String> i = versions.listIterator(versions.size());
        final VersionRange versionRange = artifact.getVersionRange();
        while (i.hasPrevious() && isEmpty(latestMatchingVersion)) {
            final String current = i.previous();
            if (versionRange.containsVersion(new DefaultArtifactVersion(current))) {
                latestMatchingVersion = current;
            }
        }
    }
    return latestMatchingVersion;
}

From source file:org.eclipse.jubula.client.core.businessprocess.CompNamesBP.java

/**
 * @param treePath/* ww  w  . j a  v  a2s.c om*/
 *            The tree path
 * @param compNameCache
 *            The cache to use in order to resolve Component Name 
 *            references.
 * @param originalName
 *            The GUID of the component name.
 * @param originalCompNameDefiner
 *            The node that is using the component name
 * @return The result containing the component name and the responsible node
 */
private CompNameResult findCompName(List<INodePO> treePath, IComponentNameCache compNameCache,
        String originalName, INodePO originalCompNameDefiner) {

    String currentName = originalName;
    INodePO compNameDefiner = originalCompNameDefiner;
    IComponentNamePO currentNamePo;
    ListIterator<INodePO> it = treePath.listIterator(treePath.size());
    while (it.hasPrevious()) {
        INodePO node = it.previous();
        if (node instanceof IExecTestCasePO) {
            IExecTestCasePO execNode = (IExecTestCasePO) node;
            ICompNamesPairPO pair = null;
            if (!StringUtils.isEmpty(currentName)) {
                pair = execNode.getCompNamesPair(currentName);
            }
            if (pair != null) {
                currentName = pair.getSecondName();
                currentNamePo = compNameCache.getCompNamePo(currentName);
                if (currentNamePo != null) {
                    currentName = currentNamePo.getGuid();
                }
                if (pair.isPropagated()) {
                    int index = it.previousIndex();
                    if (index > -1) {
                        compNameDefiner = treePath.get(index);
                    }
                } else {
                    compNameDefiner = execNode;
                    break;
                }
            }
        }
    }

    return new CompNameResult(currentName, compNameDefiner);
}

From source file:com.projity.script.object.TimeIntervals.java

public TimeIntervals translate(int winCount) { //TODO case winCount<0

    //      for (TimeWindow w : history) System.out.println("history0: "+w);
    //      for (TimeWindow w : win) System.out.println("win0: "+w);

    //for (TimeWindow w : history) System.out.println("id="+w.getId());
    TimeIntervals t = new TimeIntervals();
    t.setScale(scale);/*from   w  w w  .j  a v a 2 s . co m*/
    LinkedList<TimeWindow> twin = t.getWin();
    if (winCount == 0 || win.size() == 0)
        return t; //or null
    if (winCount > 0) {
        t.winId = winId + win.size();
        int lastId = t.winId - 1 + winCount;
        int maxHistoryId = Math.min(history.getLast().getId(), lastId);
        int i = t.winId;
        if (i <= maxHistoryId) {
            ListIterator<TimeWindow> it = history.listIterator();
            TimeWindow w;
            while (it.hasNext()) {
                w = it.next();
                if (w.getId() == t.winId) {
                    it.previous();
                    break;
                }
            }
            for (; i <= maxHistoryId && it.hasNext(); i++) {
                w = it.next();
                twin.add(w);
                //               System.out.println("Found in history: "+w);
            }
        }
        LinkedList<TimeWindow> newWin = new LinkedList<TimeWindow>();
        generateWindows(scale, (twin.size() > 0 ? twin : win).getLast().getE(), start, end, lastId - i + 1,
                newWin);
        t.indexWindows(t.winId + t.getWin().size(), newWin);
        //         for (TimeWindow w : newWin) System.out.println("New window: "+w);
        t.getWin().addAll(newWin);
        history.addAll(newWin);
    } else {
        t.winId = winId - 1;
        int lastId = t.winId + 1 + winCount;
        int minHistoryId = Math.max(history.getFirst().getId(), lastId);
        int i = t.winId;
        if (i >= minHistoryId) {
            ListIterator<TimeWindow> it = history.listIterator(history.size() - 1);
            TimeWindow w;
            while (it.hasPrevious()) {
                w = it.previous();
                if (w.getId() == t.winId) {
                    it.next();
                    break;
                }
            }
            for (; i >= minHistoryId; i--) {
                w = it.previous();
                twin.addFirst(w);
                //               System.out.println("Found in history: "+w);
            }
        }
        //         System.out.println("winId="+winId+", t.winId="+t.winId+", lastId="+lastId+", i="+i+" minHistoryId="+minHistoryId);
        LinkedList<TimeWindow> newWin = new LinkedList<TimeWindow>();
        generateWindows(scale, (twin.size() > 0 ? twin : win).getFirst().getS(), start, end, lastId - i - 1,
                newWin);
        t.indexWindows(lastId, newWin);
        //         for (TimeWindow w : newWin) System.out.println("New window: "+w);
        t.getWin().addAll(0, newWin);
        history.addAll(0, newWin);
    }

    int translation = 0;
    for (TimeWindow w : t.getWin()) {
        if (winCount > 0) {
            win.removeFirst();
            win.addLast(w);
            translation++;
        } else {
            win.removeLast();
            win.addFirst(w);
            translation--;
        }
    }
    winId = winId + translation;
    t.setTranslation(translation);

    //      for (TimeWindow w : history) System.out.println("history1: "+w);
    //      for (TimeWindow w : win) System.out.println("win1: "+w);
    //      for (TimeWindow w : twin) System.out.println("t.win1: "+w);

    return t;
}

From source file:org.apache.fop.layoutmgr.table.TableContentLayoutManager.java

/**
 * Creates Knuth elements by iterating over a TableRowIterator.
 * @param iter TableRowIterator instance to fetch rows from
 * @param context Active LayoutContext//from  w  w  w.j a  v  a 2 s .  com
 * @param alignment alignment indicator
 * @param bodyType Indicates what kind of body is being processed
 *                  (BODY, HEADER or FOOTER)
 * @return An element list
 */
private LinkedList getKnuthElementsForRowIterator(TableRowIterator iter, LayoutContext context, int alignment,
        int bodyType) {
    LinkedList returnList = new LinkedList();
    EffRow[] rowGroup = iter.getNextRowGroup();
    // TODO homogenize the handling of keeps and breaks
    context.clearKeepsPending();
    context.setBreakBefore(Constants.EN_AUTO);
    context.setBreakAfter(Constants.EN_AUTO);
    Keep keepWithPrevious = Keep.KEEP_AUTO;
    int breakBefore = Constants.EN_AUTO;
    if (rowGroup != null) {
        RowGroupLayoutManager rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup, stepper);
        List nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType);
        keepWithPrevious = keepWithPrevious.compare(context.getKeepWithPreviousPending());
        breakBefore = context.getBreakBefore();
        int breakBetween = context.getBreakAfter();
        returnList.addAll(nextRowGroupElems);
        while ((rowGroup = iter.getNextRowGroup()) != null) {
            rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup, stepper);

            //Note previous pending keep-with-next and clear the strength
            //(as the layout context is reused)
            Keep keepWithNextPending = context.getKeepWithNextPending();
            context.clearKeepWithNextPending();

            //Get elements for next row group
            nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType);
            /*
             * The last break element produced by TableStepper (for the previous row
             * group) may be used to represent the break between the two row groups.
             * Its penalty value and break class must just be overridden by the
             * characteristics of the keep or break between the two.
             *
             * However, we mustn't forget that if the after border of the last row of
             * the row group is thicker in the normal case than in the trailing case,
             * an additional glue will be appended to the element list. So we may have
             * to go two steps backwards in the list.
             */

            //Determine keep constraints
            Keep keep = keepWithNextPending.compare(context.getKeepWithPreviousPending());
            context.clearKeepWithPreviousPending();
            keep = keep.compare(getTableLM().getKeepTogether());
            int penaltyValue = keep.getPenalty();
            int breakClass = keep.getContext();

            breakBetween = BreakUtil.compareBreakClasses(breakBetween, context.getBreakBefore());
            if (breakBetween != Constants.EN_AUTO) {
                penaltyValue = -KnuthElement.INFINITE;
                breakClass = breakBetween;
            }
            BreakElement breakElement;
            ListIterator elemIter = returnList.listIterator(returnList.size());
            ListElement elem = (ListElement) elemIter.previous();
            if (elem instanceof KnuthGlue) {
                breakElement = (BreakElement) elemIter.previous();
            } else {
                breakElement = (BreakElement) elem;
            }
            breakElement.setPenaltyValue(penaltyValue);
            breakElement.setBreakClass(breakClass);
            returnList.addAll(nextRowGroupElems);
            breakBetween = context.getBreakAfter();
        }
    }
    /*
     * The last break produced for the last row-group of this table part must be
     * removed, because the breaking after the table will be handled by TableLM.
     * Unless the element list ends with a glue, which must be kept to accurately
     * represent the content. In such a case the break is simply disabled by setting
     * its penalty to infinite.
     */
    ListIterator elemIter = returnList.listIterator(returnList.size());
    ListElement elem = (ListElement) elemIter.previous();
    if (elem instanceof KnuthGlue) {
        BreakElement breakElement = (BreakElement) elemIter.previous();
        breakElement.setPenaltyValue(KnuthElement.INFINITE);
    } else {
        elemIter.remove();
    }
    context.updateKeepWithPreviousPending(keepWithPrevious);
    context.setBreakBefore(breakBefore);

    //fox:widow-content-limit
    int widowContentLimit = getTableLM().getTable().getWidowContentLimit().getValue();
    if (widowContentLimit != 0 && bodyType == TableRowIterator.BODY) {
        ElementListUtils.removeLegalBreaks(returnList, widowContentLimit);
    }
    //fox:orphan-content-limit
    int orphanContentLimit = getTableLM().getTable().getOrphanContentLimit().getValue();
    if (orphanContentLimit != 0 && bodyType == TableRowIterator.BODY) {
        ElementListUtils.removeLegalBreaksFromEnd(returnList, orphanContentLimit);
    }

    return returnList;
}

From source file:com.projity.grouping.core.hierarchy.AbstractMutableNodeHierarchy.java

private Node getPrevious(Node current, boolean doChildren) {
    if (current == null) // null parent has no parent
        return null;
    List children;//from   w  ww . j  a v  a  2 s .  c  o  m

    Node parent = getParent(current);
    children = getChildren(parent);
    if (doChildren) { // if haven't visited children yet
        ListIterator i = children.listIterator(children.size()); // reverse iterator
        while (i.hasPrevious()) { // get next element after this one.  If it is the last then try its parent
            if (i.previous() == current) {
                if (i.hasPrevious())
                    return getPrevious((Node) i.previous(), false);
                else
                    return parent;
            }
        }
    }

    children = getChildren(current);
    if (children != null && children.size() > 0) // if parent, previous is last child
        return getPrevious((Node) children.get(children.size() - 1), doChildren);

    return current;
}

From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java

/**
 * Gets a set of boxes which covers all and only the pixels covered by
 * <code>A</code> and <code>B</code>.
 * /*from   www  .  j  a v  a2 s.  c o m*/
 * @param A
 *            a set of boxes to union with
 * @param B
 *            a set of boxes to union with
 * @return a set of boxes corresponding to the region shared by A and B
 */
public static BoundingBox union(BoundingBox A, BoundingBox B) {
    BoundingBox temp = new BoundingBox();
    LinkedList aList;
    temp.composed = true;
    int x = Math.min(A.rect.x, B.rect.x);
    int y = Math.min(A.rect.y, B.rect.y);
    int x2 = Math.max(A.rect.x + A.rect.width, B.rect.x + B.rect.width);
    int y2 = Math.max(A.rect.y + A.rect.height, B.rect.y + B.rect.height);

    temp.rect = new Rectangle(x, y, x2, y2);

    if (A.composed)
        aList = (LinkedList) A.pieces.clone();
    else {
        aList = new LinkedList();
        aList.add(A);
    }

    if (B.composed)
        temp = B.copy();
    else {
        temp.pieces = new LinkedList();
        temp.pieces.add(B.copy());
        temp.composed = true;
    }

    ListIterator iter = aList.listIterator(0);
    while (iter.hasNext()) {
        BoundingBox child = (BoundingBox) iter.next();
        Iterator ti = temp.pieces.iterator();
        LinkedList childRemains = null;

        /* remove an offending piece of the child */
        while (ti.hasNext() && (null == (childRemains = ((BoundingBox) ti.next()).subtractFrom(child))))
            ;

        /*
         * Add the broken pieces into the list and break back to top loop
         * remove the offending rectangle and replace it with its shards,
         * then clean up those.
         */
        if (childRemains != null) {
            ti = childRemains.iterator();
            iter.remove();
            while (ti.hasNext()) {
                iter.add(ti.next());
                iter.previous();
            }
        }
    }
    temp.pieces.addAll(aList);
    temp.simplify();
    return (temp);
}