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:eu.scidipes.toolkits.pawebapp.web.ItemsController.java

public String editItemHelper(final List<Form> formSubset, final Form form, final Model model,
        final RedirectAttributes redirectAttrs) {
    final ListIterator<Form> formIterator = formSubset.listIterator();

    while (formIterator.hasNext()) {
        final Form theForm = formIterator.next();
        if (theForm.equals(form)) {
            /* Jump back: */
            formIterator.previous();/*  w  w  w.  j  a  va2  s . c o  m*/
            if (formIterator.hasPrevious()) {
                model.addAttribute("previous",
                        Integer.valueOf(formSubset.get(formIterator.previousIndex()).getFormID().intValue()));
            }
            /* Jump forward: */
            formIterator.next();
            if (formIterator.hasNext()) {
                model.addAttribute("next",
                        Integer.valueOf(formSubset.get(formIterator.nextIndex()).getFormID().intValue()));
            }
        }
    }
    model.addAttribute("saveAction", EDIT);

    final CurationPersistentIdentifier manifestCPID = form.getManifestCPID();
    final Map<DatasetRIL, Set<CoreRIType>> rilMembership = new HashMap<>();

    /* Fetch the current RIL membership for this form instance: */
    for (final DatasetRIL dsRIL : form.getParentBundle().getRils()) {

        final RepresentationInformation[] repInfo = dsRIL.getRil().getRepresentationInformationChildren();

        for (final RepresentationInformation coreRI : repInfo) {

            if (coreRI.getRepresentationInformation() instanceof RepInfoGroup) {
                final RepInfoGroup repInfoGroup = (RepInfoGroup) coreRI.getRepresentationInformation();

                for (final RepresentationInformation ri : repInfoGroup.getRepresentationInformationChildren()) {

                    if (ri.getCpid().equals(manifestCPID)) {

                        if (!rilMembership.containsKey(dsRIL)) {
                            rilMembership.put(dsRIL, new HashSet<CoreRIType>());
                        }
                        rilMembership.get(dsRIL).add(CoreRIType.fromClass(coreRI.getClass()));
                    }

                }

            }
        }
    }
    model.addAttribute("rilMembership", rilMembership);

    model.addAttribute("form", form);
    return "datasets/items/edit";
}

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

/** {@inheritDoc} */
@Override/*  ww w.ja v  a2  s .  c o  m*/
public List<KnuthElement> getChangedKnuthElements(List oldList, int alignment) {
    ListIterator<KnuthElement> oldListIterator = oldList.listIterator();
    KnuthElement returnedElement;
    List<KnuthElement> returnedList = new LinkedList<KnuthElement>();
    List<KnuthElement> returnList = new LinkedList<KnuthElement>();
    KnuthElement prevElement = null;
    KnuthElement currElement = null;
    int fromIndex = 0;

    // "unwrap" the Positions stored in the elements
    KnuthElement oldElement;
    while (oldListIterator.hasNext()) {
        oldElement = oldListIterator.next();
        if (oldElement.getPosition() instanceof NonLeafPosition) {
            // oldElement was created by a descendant of this FlowLM
            oldElement.setPosition((oldElement.getPosition()).getPosition());
        } else {
            // thisElement was created by this FlowLM, remove it
            oldListIterator.remove();
        }
    }
    // reset the iterator
    oldListIterator = oldList.listIterator();

    while (oldListIterator.hasNext()) {
        currElement = oldListIterator.next();
        if (prevElement != null && prevElement.getLayoutManager() != currElement.getLayoutManager()) {
            // prevElement is the last element generated by the same LM
            BlockLevelLayoutManager prevLM = (BlockLevelLayoutManager) prevElement.getLayoutManager();
            BlockLevelLayoutManager currLM = (BlockLevelLayoutManager) currElement.getLayoutManager();
            returnedList.addAll(prevLM.getChangedKnuthElements(
                    oldList.subList(fromIndex, oldListIterator.previousIndex()), alignment));
            fromIndex = oldListIterator.previousIndex();

            // there is another block after this one
            if (prevLM.mustKeepWithNext() || currLM.mustKeepWithPrevious()) {
                // add an infinite penalty to forbid a break between blocks
                returnedList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, new Position(this), false));
            } else if (!ListUtil.getLast(returnedList).isGlue()) {
                // add a null penalty to allow a break between blocks
                returnedList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
            }
        }
        prevElement = currElement;
    }
    if (currElement != null) {
        BlockLevelLayoutManager currLM = (BlockLevelLayoutManager) currElement.getLayoutManager();
        returnedList
                .addAll(currLM.getChangedKnuthElements(oldList.subList(fromIndex, oldList.size()), alignment));
    }

    // "wrap" the Position stored in each element of returnedList
    // and add elements to returnList
    ListIterator<KnuthElement> listIter = returnedList.listIterator();
    while (listIter.hasNext()) {
        returnedElement = listIter.next();
        if (returnedElement.getLayoutManager() != this) {
            returnedElement.setPosition(new NonLeafPosition(this, returnedElement.getPosition()));
        }
        returnList.add(returnedElement);
    }

    return returnList;
}

From source file:com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration.java

/**
 * Sets the list of endpoints./*w  ww.  j a  va2  s.  c om*/
 *
 * @param endpoints the list of endpoints.
 */
public synchronized void setEndpoints(@CheckForNull List<? extends AbstractBitbucketEndpoint> endpoints) {
    Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
    List<AbstractBitbucketEndpoint> eps = new ArrayList<>(Util.fixNull(endpoints));
    // remove duplicates and empty urls
    Set<String> serverUrls = new HashSet<>();
    for (ListIterator<AbstractBitbucketEndpoint> iterator = eps.listIterator(); iterator.hasNext();) {
        AbstractBitbucketEndpoint endpoint = iterator.next();
        String serverUrl = endpoint.getServerUrl();
        if (StringUtils.isBlank(serverUrl) || serverUrls.contains(serverUrl)) {
            iterator.remove();
            continue;
        } else if (!(endpoint instanceof BitbucketCloudEndpoint)
                && BitbucketCloudEndpoint.SERVER_URL.equals(serverUrl)) {
            // fix type for the special case
            iterator.set(new BitbucketCloudEndpoint(endpoint.isManageHooks(), endpoint.getCredentialsId(),
                    endpoint.getBitbucketJenkinsRootUrl()));
        }
        serverUrls.add(serverUrl);
    }
    if (eps.isEmpty()) {
        eps.add(new BitbucketCloudEndpoint(false, null));
    }
    this.endpoints = eps;
    save();
}

From source file:br.com.ingenieux.mojo.beanstalk.version.CleanPreviousVersionsMojo.java

void filterAppVersionListByVersionLabelPattern(List<ApplicationVersionDescription> appVersionList,
        String patternString) {/* w  w w.  j  a  va  2 s  .  co  m*/
    if (patternString == null) {
        return;
    }

    getLog().info("Filtering versions with pattern : " + patternString);

    Pattern p = Pattern.compile(patternString);
    for (ListIterator<ApplicationVersionDescription> appVersionIterator = appVersionList
            .listIterator(); appVersionIterator.hasNext();) {

        if (!p.matcher(appVersionIterator.next().getVersionLabel()).matches()) {
            appVersionIterator.remove();
        }
    }
}

From source file:com.quigley.filesystem.FilesystemPath.java

public FilesystemPath simplify() {
    List<String> elementsCopy = new ArrayList<String>(elements);
    ListIterator<String> i = elementsCopy.listIterator();
    boolean saw = false;
    while (i.hasNext()) {
        String value = i.next();//from w  ww  .  ja v  a2  s  .  co  m
        if (value.equals(".")) {
            i.remove();
        } else if (value.equals("..")) {
            if (saw) {
                if (i.hasPrevious()) {
                    i.remove();
                    i.previous();
                    i.remove();
                }
            }
        } else {
            saw = true;
        }
    }
    FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
    pathCopy.isAbsolute = isAbsolute;

    return pathCopy;
}

From source file:com.opengamma.web.WebAbout.java

/**
 * Gets the JVM input arguments./*from   w w  w  .  ja va  2s .  c  o  m*/
 * @return the JVM input arguments
 */
public List<String> getJvmArguments() {
    List<String> args = new ArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments());
    for (ListIterator<String> it = args.listIterator(); it.hasNext();) {
        String arg = it.next();
        if (arg.contains("secret") || arg.contains("password")) {
            int index = arg.indexOf("secret") + 6;
            if (index < 0) {
                index = arg.indexOf("password") + 8;
            }
            it.set(arg.substring(0, index) + "*************");
        }
    }
    return args;
}

From source file:org.generationcp.breeding.manager.crossingmanager.MakeCrossesTableComponent.java

/**
 * Crosses each item on first list with its counterpart (same index or position) 
 * on second list. Assumes that checking if list sizes are equal was done beforehand.
 * The generated crossings are then added to Crossings Table.
 * //from   w w w . ja va  2 s.  com
 * @param parents1 - list of GermplasmList entries as first parents
 * @param parents2 - list of GermplasmList entries as second parents
 * @param listnameMaleParent 
 * @param listnameFemaleParent 
 */
public void makeTopToBottomCrosses(List<GermplasmListEntry> parents1, List<GermplasmListEntry> parents2,
        Label listnameFemaleParent, Label listnameMaleParent) {

    ListIterator<GermplasmListEntry> iterator1 = parents1.listIterator();
    ListIterator<GermplasmListEntry> iterator2 = parents2.listIterator();

    tableCrossesMade
            .setVisibleColumns(new Object[] { PARENTAGE, FEMALE_PARENT_COLUMN, MALE_PARENT_COLUMN, SOURCE });

    while (iterator1.hasNext()) {
        GermplasmListEntry parent1 = iterator1.next();
        GermplasmListEntry parent2 = iterator2.next();
        String caption1 = parent1.getDesignation();
        String caption2 = parent2.getDesignation();
        String caption3 = listnameFemaleParent.getValue().toString() + ":" + parent1.getEntryId() + "/"
                + listnameMaleParent.getValue().toString() + ":" + parent2.getEntryId();

        CrossParents parents = new CrossParents(parent1, parent2);

        if (!crossAlreadyExists(parents)) {
            tableCrossesMade.addItem(
                    new Object[] { CrossingManagerUtil.generateFemaleandMaleCrossName(caption1, caption2),
                            caption1, caption2, caption3 },
                    parents);
        }
    }
    this.crossesMadeCountContainer.setCaption("Total Crosses: " + tableCrossesMade.size());

    tableCrossesMade.setVisibleColumns(new Object[] { PARENTAGE, FEMALE_PARENT_COLUMN, MALE_PARENT_COLUMN });
    tableCrossesMade.setPageLength(0);
    tableCrossesMade.requestRepaint();
}

From source file:com.mirth.connect.server.util.DatabaseConnection.java

public CachedRowSet executeCachedQuery(String expression, List<Object> parameters) throws SQLException {
    PreparedStatement statement = null;

    try {/* w w  w . j  ava  2s . co m*/
        statement = connection.prepareStatement(expression);
        logger.debug("executing prepared statement:\n" + expression);

        ListIterator<Object> iterator = parameters.listIterator();

        while (iterator.hasNext()) {
            int index = iterator.nextIndex() + 1;
            Object value = iterator.next();
            logger.debug("adding parameter: index=" + index + ", value=" + value);
            statement.setObject(index, value);
        }

        ResultSet result = statement.executeQuery();
        CachedRowSetImpl crs = new CachedRowSetImpl();
        crs.populate(result);
        DbUtils.closeQuietly(result);
        return crs;
    } catch (SQLException e) {
        throw e;
    } finally {
        DbUtils.closeQuietly(statement);
    }
}

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

/** {@inheritDoc} */
public void addChildLMs(List newLMs) {
    if (newLMs == null || newLMs.size() == 0) {
        return;/*from   ww w  .  j  ava 2  s.  c  o m*/
    }
    ListIterator<LayoutManager> iter = newLMs.listIterator();
    while (iter.hasNext()) {
        addChildLM(iter.next());
    }
}