Example usage for java.util ListIterator hasNext

List of usage examples for java.util ListIterator hasNext

Introduction

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

Prototype

boolean hasNext();

Source Link

Document

Returns true if this list iterator has more elements when traversing the list in the forward direction.

Usage

From source file:com.manydesigns.elements.options.DefaultSelectionProvider.java

public void ensureActive(Object... values) {
    Row row = null;//from  ww w  .  j a  v  a 2s  .c  o  m
    ListIterator<Row> iterator = rows.listIterator();
    while (iterator.hasNext()) {
        Row current = iterator.next();
        boolean found = true;
        for (int i = 0; i < fieldCount; i++) {
            if (!ObjectUtils.equals(values[i], current.getValues()[i])) {
                found = false;
                break;
            }
        }
        if (found) {
            row = new Row(values, current.getLabels(), true);
            iterator.set(row);
            break;
        }
    }
    if (row == null) {
        String[] labels = new String[fieldCount];
        for (int i = 0; i < fieldCount; i++) {
            labels[i] = ObjectUtils.toString(values[i]);
        }
        row = new Row(values, labels, true);
        rows.add(row);
    }
}

From source file:com.platum.restflow.RestflowModel.java

/**
 * //w w w .ja  va2 s . c o  m
 * @param datasource
 * @return
 */
public RestflowModel updateFileSystem(FileSystemDetails fs) {
    Validate.notNull(fs, "Cannot update a null filesystem.");
    Validate.notEmpty(fs.getName(), "Filesystem name cannot be null or empty.");
    if (resources != null) {
        ListIterator<FileSystemDetails> iterator = fileSystems.listIterator();
        while (iterator.hasNext()) {
            if (iterator.next().getName().equals(fs.getName())) {
                iterator.set(fs);
                return this;
            }
        }
    }
    throw new RestflowNotExistsException("Datasource does not exists.");
}

From source file:com.platum.restflow.RestflowModel.java

/**
 * //from   ww  w .  j a  v a  2  s.  co m
 * @param datasource
 * @return
 */
public RestflowModel updateDatasource(DatasourceDetails datasource) {
    Validate.notNull(datasource, "Cannot update a null datasource.");
    Validate.notEmpty(datasource.getName(), "Datasource name cannot be null or empty.");
    if (resources != null) {
        ListIterator<DatasourceDetails> iterator = datasources.listIterator();
        while (iterator.hasNext()) {
            if (iterator.next().getName().equals(datasource.getName())) {
                iterator.set(datasource);
                return this;
            }
        }
    }
    throw new RestflowNotExistsException("Datasource does not exists.");
}

From source file:com.card.loop.xyz.dao.LearningElementDAO.java

public ArrayList<String> getKeywords(String md5, String collection) throws UnknownHostException {
    Mongo mongo = new Mongo(AppConfig.mongodb_host, AppConfig.mongodb_port);
    DB db = mongo.getDB(AppConfig.DATABASE_LOOP);
    ArrayList<String> list = new ArrayList<>();
    GridFS le_gfs = new GridFS(db, collection);
    GridFSDBFile le_output = le_gfs.findOne(new BasicDBObject("md5", md5));
    ListIterator<Object> trustedList = ((BasicDBList) le_output.get("keywords")).listIterator();

    while (trustedList.hasNext()) {
        Object nextItem = trustedList.next();
        list.add(nextItem.toString());/*from w w w. j av a 2 s  .  co m*/
    }
    return list;
}

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 a  va2s . 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.
 * //w ww . j a  va  2s  .  c  om
 * @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.//  ww  w. ja  v  a 2  s  .  com
 * 
 * @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:io.github.swagger2markup.markup.builder.internal.confluenceMarkup.ConfluenceMarkupBuilder.java

@Override
public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) {
    Validate.notEmpty(cells, "cells must not be null");
    documentBuilder.append(newLine);/*w w  w .  j a  v  a2  s .co m*/
    if (columnSpecs != null && !columnSpecs.isEmpty()) {
        documentBuilder.append("||");
        for (MarkupTableColumn column : columnSpecs) {
            documentBuilder.append(formatCellContent(defaultString(column.header))).append("||");
        }
        documentBuilder.append(newLine);
    }
    for (List<String> row : cells) {
        documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);
        ListIterator<String> cellIterator = row.listIterator();
        while (cellIterator.hasNext()) {
            int cellIndex = cellIterator.nextIndex();
            if (columnSpecs != null && columnSpecs.size() > cellIndex
                    && columnSpecs.get(cellIndex).headerColumn)
                documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);

            documentBuilder.append(formatCellContent(cellIterator.next()))
                    .append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);
        }
        documentBuilder.append(newLine);
    }
    documentBuilder.append(newLine);
    return this;
}

From source file:com.github.vanroy.springdata.jest.CriteriaQueryProcessor.java

QueryBuilder createQueryFromCriteria(Criteria criteria) {
    if (criteria == null)
        return null;

    List<QueryBuilder> shouldQueryBuilderList = new LinkedList<QueryBuilder>();
    List<QueryBuilder> mustNotQueryBuilderList = new LinkedList<QueryBuilder>();
    List<QueryBuilder> mustQueryBuilderList = new LinkedList<QueryBuilder>();

    ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();

    QueryBuilder firstQuery = null;/*from  w ww  .  jav a 2 s .c o  m*/
    boolean negateFirstQuery = false;

    while (chainIterator.hasNext()) {
        Criteria chainedCriteria = chainIterator.next();
        QueryBuilder queryFragmentForCriteria = createQueryFragmentForCriteria(chainedCriteria);
        if (queryFragmentForCriteria != null) {
            if (firstQuery == null) {
                firstQuery = queryFragmentForCriteria;
                negateFirstQuery = chainedCriteria.isNegating();
                continue;
            }
            if (chainedCriteria.isOr()) {
                shouldQueryBuilderList.add(queryFragmentForCriteria);
            } else if (chainedCriteria.isNegating()) {
                mustNotQueryBuilderList.add(queryFragmentForCriteria);
            } else {
                mustQueryBuilderList.add(queryFragmentForCriteria);
            }
        }
    }

    if (firstQuery != null) {
        if (!shouldQueryBuilderList.isEmpty() && mustNotQueryBuilderList.isEmpty()
                && mustQueryBuilderList.isEmpty()) {
            shouldQueryBuilderList.add(0, firstQuery);
        } else {
            if (negateFirstQuery) {
                mustNotQueryBuilderList.add(0, firstQuery);
            } else {
                mustQueryBuilderList.add(0, firstQuery);
            }
        }
    }

    BoolQueryBuilder query = null;

    if (!shouldQueryBuilderList.isEmpty() || !mustNotQueryBuilderList.isEmpty()
            || !mustQueryBuilderList.isEmpty()) {

        query = boolQuery();

        for (QueryBuilder qb : shouldQueryBuilderList) {
            query.should(qb);
        }
        for (QueryBuilder qb : mustNotQueryBuilderList) {
            query.mustNot(qb);
        }
        for (QueryBuilder qb : mustQueryBuilderList) {
            query.must(qb);
        }
    }

    return query;
}

From source file:bzstats.chart.KillRatioHistoryChart.java

private void fillDataset(DefaultTableXYDataset dataset) {

    ListIterator i = period.listIterator();

    GameEvent event;/*w  ww.  j a  v a2  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());
    }

}