Example usage for java.util ListIterator next

List of usage examples for java.util ListIterator next

Introduction

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

Prototype

E next();

Source Link

Document

Returns the next element in the list and advances the cursor position.

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();/*from  w w w.j  a va  2s  .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:com.adobe.acs.commons.httpcache.config.impl.HttpCacheConfigImpl.java

@Activate
protected void activate(Map<String, Object> configs) {

    // Request URIs - Whitelisted.
    requestUriPatterns = Arrays//from   w ww . j a  va 2  s.  c o m
            .asList(PropertiesUtil.toStringArray(configs.get(PROP_REQUEST_URI_PATTERNS), new String[] {}));
    requestUriPatternsAsRegEx = compileToPatterns(requestUriPatterns);

    // Request URIs - Blacklisted.
    blacklistedRequestUriPatterns = Arrays.asList(
            PropertiesUtil.toStringArray(configs.get(PROP_BLACKLISTED_REQUEST_URI_PATTERNS), new String[] {}));
    blacklistedRequestUriPatternsAsRegEx = compileToPatterns(blacklistedRequestUriPatterns);

    // Authentication requirement.
    authenticationRequirement = PropertiesUtil.toString(configs.get(PROP_AUTHENTICATION_REQUIREMENT),
            DEFAULT_AUTHENTICATION_REQUIREMENT);

    // Cache store
    cacheStore = PropertiesUtil.toString(configs.get(PROP_CACHE_STORE), DEFAULT_CACHE_STORE);

    // Cache invalidation paths.
    cacheInvalidationPathPatterns = Arrays.asList(
            PropertiesUtil.toStringArray(configs.get(PROP_CACHE_INVALIDATION_PATH_PATTERNS), new String[] {}));
    cacheInvalidationPathPatternsAsRegEx = compileToPatterns(cacheInvalidationPathPatterns);

    order = PropertiesUtil.toInteger(configs.get(PROP_ORDER), DEFAULT_ORDER);

    filterScope = FilterScope.valueOf(
            PropertiesUtil.toString(configs.get(PROP_FILTER_SCOPE), DEFAULT_FILTER_SCOPE).toUpperCase());

    // PIDs of cache handling rules.
    cacheHandlingRulesPid = new ArrayList<String>(Arrays
            .asList(PropertiesUtil.toStringArray(configs.get(PROP_CACHE_HANDLING_RULES_PID), new String[] {})));
    ListIterator<String> listIterator = cacheHandlingRulesPid.listIterator();
    while (listIterator.hasNext()) {
        String value = listIterator.next();
        if (StringUtils.isBlank(value)) {
            listIterator.remove();
        }
    }

    log.info("HttpCacheConfigImpl activated.");
}

From source file:au.edu.ausstage.networks.SearchManager.java

/**
 * A method to take a group of collaborators and output JSON encoded text
 * Unchecked warnings are suppressed due to internal issues with the org.json.simple package
 *
 * @param collaborators the list of collaborators
 * @return              the JSON encoded string
 *///from ww w  . jav a 2  s .  com
@SuppressWarnings("unchecked")
private String createJSONOutput(LinkedList<Collaborator> collaborators) {

    // assume that all sorting and ordering has already been carried out
    // loop through the list of collaborators and add them to the new JSON objects
    ListIterator iterator = collaborators.listIterator(0);

    // declare helper variables
    JSONArray list = new JSONArray();
    Collaborator collaborator = null;

    while (iterator.hasNext()) {

        // get the collaborator
        collaborator = (Collaborator) iterator.next();

        // add the Json object to the array
        list.add(collaborator.toJsonObject());
    }

    // return the JSON encoded string
    return list.toString();

}

From source file:bzstats.chart.KillRatioHistoryChart.java

private void fillDataset(DefaultTableXYDataset dataset) {

    ListIterator i = period.listIterator();

    GameEvent event;/*from  w  ww.  ja  va2  s .c  o  m*/
    XYSeries playerseries;
    PeriodStats stats = new PeriodStats();
    int x;
    float y;
    Iterator statiter;
    Map.Entry entry;
    PlayerStats playerstats;
    while (i.hasNext()) {
        x = i.nextIndex();
        event = (GameEvent) i.next();
        event.collectStats(stats);

        statiter = stats.getPlayerStats().entrySet().iterator();
        while (statiter.hasNext()) {
            entry = (Map.Entry) statiter.next();
            playerstats = (PlayerStats) entry.getValue();
            y = playerstats.getKillRatio();
            playerseries = getSeries(playerstats.getName());

            if (playerseries != null) {
                playerseries.add(x, y);
            }
        }
    }

    // add the series to the dataset
    Iterator serieiter = series.entrySet().iterator();
    while (serieiter.hasNext()) {
        entry = (Map.Entry) serieiter.next();
        dataset.addSeries((XYSeries) entry.getValue());
    }

}

From source file:com.danga.camli.UploadThread.java

private void filterOutBlobRef(String blobRef) {
    // TODO: kinda lame, iterating over whole list.
    ListIterator<QueuedFile> iter = mQueue.listIterator();
    while (iter.hasNext()) {
        QueuedFile qf = iter.next();
        if (qf.getContentName().equals(blobRef)) {
            iter.remove();//from w  w w. j a v  a2s . co m
            mService.onUploadComplete(qf, false /* not uploaded */);
        }
    }
}

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

/**
 * Executes a prepared INSERT/UPDATE statement on the database and returns the row count.
 * /*  w  ww.  j ava2 s . c  o m*/
 * @param expression
 *            The prepared statement to be executed.
 * @param parameters
 *            The parameters for the prepared statement.
 * @return A count of the number of updated rows.
 * @throws SQLException
 */
public int executeUpdate(String expression, List<Object> parameters) throws SQLException {
    PreparedStatement statement = null;

    try {
        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);
        }

        if (statement.execute()) {
            return -1;
        } else {
            return statement.getUpdateCount();
        }
    } catch (SQLException e) {
        throw e;
    } finally {
        DbUtils.closeQuietly(statement);
    }
}

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

/**
 * Executes a prepared query on the database and returns a CachedRowSet.
 * //from  w  w w  . j a  va  2s.com
 * @param expression
 *            The prepared statement to be executed.
 * @param parameters
 *            The parameters for the prepared statement.
 * @return The result of the query, as a CachedRowSet.
 * @throws SQLException
 */
public CachedRowSet executeCachedQuery(String expression, List<Object> parameters) throws SQLException {
    PreparedStatement statement = null;

    try {
        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();
        CachedRowSet crs = new MirthCachedRowSet();
        crs.populate(result);
        DbUtils.closeQuietly(result);
        return crs;
    } catch (SQLException e) {
        throw e;
    } finally {
        DbUtils.closeQuietly(statement);
    }
}

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

/**
 * Executes a prepared INSERT/UPDATE statement on the database and returns a CachedRowSet
 * containing any generated keys.//from  w w  w  .j  a va2  s  .c  o m
 * 
 * @param expression
 *            The prepared statement to be executed.
 * @param parameters
 *            The parameters for the prepared statement.
 * @return A CachedRowSet containing any generated keys.
 * @throws SQLException
 */
public CachedRowSet executeUpdateAndGetGeneratedKeys(String expression, List<Object> parameters)
        throws SQLException {
    PreparedStatement statement = null;

    try {
        statement = connection.prepareStatement(expression, Statement.RETURN_GENERATED_KEYS);
        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);
        }

        statement.executeUpdate();
        CachedRowSet crs = new MirthCachedRowSet();
        crs.populate(statement.getGeneratedKeys());
        return crs;
    } catch (SQLException e) {
        throw e;
    } finally {
        DbUtils.closeQuietly(statement);
    }
}

From source file:org.powertac.householdcustomer.persons.Person.java

/**
 * This function fills out the vector containing the days that the person is
 * going to be sick. When a person is sick he stays in the household.
 * /*from  w  w  w .jav  a  2 s. c o m*/
 * @param mean
 * @param dev
 * @param gen
 * @return
 */
Vector<Integer> createSicknessVector(double mean, double dev) {
    // Create auxiliary variables

    int days = (int) (dev * gen.nextGaussian() + mean);
    Vector<Integer> v = new Vector<Integer>(days);

    for (int i = 0; i < days; i++) {
        int x = gen.nextInt(VillageConstants.DAYS_OF_COMPETITION + VillageConstants.DAYS_OF_BOOTSTRAP) + 1;
        ListIterator<Integer> iter = v.listIterator();
        while (iter.hasNext()) {
            int temp = (int) iter.next();
            if (x == temp) {
                x = x + 1;
                iter = v.listIterator();
            }
        }
        v.add(x);
    }
    java.util.Collections.sort(v);
    return v;
}

From source file:msearch.filmlisten.MSFilmlisteSchreiben.java

private void xmlSchreibenFilmliste(ListeFilme listeFilme) throws XMLStreamException {
    //Filmliste Metadaten schreiben
    listeFilme.metaDaten[ListeFilme.FILMLISTE_VERSION_NR] = MSConst.VERSION_FILMLISTE;
    xmlSchreibenDaten(ListeFilme.FILMLISTE, ListeFilme.COLUMN_NAMES, listeFilme.metaDaten);
    // Feldinfo schreiben
    int xmlMax = DatenFilm.COLUMN_NAMES.length;
    try {// w w  w  .j  ava2  s.co m
        writer.writeStartElement(DatenFilm.FELD_INFO);
        writer.writeCharacters("\n");//neue Zeile
        for (int i = 0; i < xmlMax; ++i) {
            writer.writeStartElement(DatenFilm.COLUMN_NAMES_XML[i]);
            writer.writeCharacters(DatenFilm.COLUMN_NAMES[i]);
            writer.writeEndElement();
            writer.writeCharacters("\n");//neue Zeile
        }
        writer.writeEndElement();
        writer.writeCharacters("\n");//neue Zeile
    } catch (Exception ex) {
        MSLog.fehlerMeldung(638214005, MSLog.FEHLER_ART_PROG, "IoXmlSchreiben.xmlSchreibenFeldInfo", ex);
    }
    // Filme schreiben
    ListIterator<DatenFilm> iterator;
    DatenFilm datenFilm;
    String sender = "", thema = "";
    DatenFilm datenFilmSchreiben = new DatenFilm();
    iterator = listeFilme.listIterator();
    while (iterator.hasNext()) {
        datenFilm = iterator.next();
        System.arraycopy(datenFilm.arr, 0, datenFilmSchreiben.arr, 0, datenFilm.arr.length);
        if (sender.equals(datenFilm.arr[DatenFilm.FILM_SENDER_NR])) {
            datenFilmSchreiben.arr[DatenFilm.FILM_SENDER_NR] = "";
        } else {
            sender = datenFilm.arr[DatenFilm.FILM_SENDER_NR];
        }
        if (thema.equals(datenFilm.arr[DatenFilm.FILM_THEMA_NR])) {
            datenFilmSchreiben.arr[DatenFilm.FILM_THEMA_NR] = "";
        } else {
            thema = datenFilm.arr[DatenFilm.FILM_THEMA_NR];
        }
        datenFilmSchreiben.clean();
        xmlSchreibenDaten(DatenFilm.FILME_, DatenFilm.COLUMN_NAMES_XML, datenFilmSchreiben.arr);
    }
}