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.xtivia.training.BookPortlet.java

@ProcessAction(name = "ajaxDelete")
public void ajaxDelete(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    response.setContentType("text/html");
    String isbn = request.getParameter("isbn");
    ListIterator iterator = books.listIterator();
    while (iterator.hasNext()) {
        Book book = (Book) iterator.next();
        String isbns = book.getIsbnNumber() + "";
        if (isbn.equals(isbns)) {
            iterator.remove();/*w  w w  .ja v  a2s  . c o  m*/
        }
    }
    request.setAttribute("books", books);
    System.out.println("I am in ajax delete");
    /*request.setAttribute("books", books);
    System.out.println("I am here whats up");
    include(templateJSP, request, response, PortletRequest.RESOURCE_PHASE);*/
}

From source file:com.xtivia.training.BookPortlet.java

public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    response.setContentType("text/html");
    String message = request.getParameter("message");
    String isbn = message;// www.j  ava 2s. c  om
    ListIterator iterator = books.listIterator();
    while (iterator.hasNext()) {
        Book book = (Book) iterator.next();
        String isbns = book.getIsbnNumber() + "";
        if (isbn.equals(isbns)) {
            iterator.remove();
        }
    }
    request.setAttribute("books", books);
    System.out.println("I am in ajax delete");

    // this seems to be the page that was calling...?
    String resourceID = request.getResourceID();
    System.out.println("resourceId was : " + resourceID);
    System.out.println("message was : " + message);
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupDaoJena.java

public int removeUnpopulatedGroups(List<VClassGroup> groups) {
    if (groups == null || groups.size() == 0)
        return 0;
    int removedGroupsCount = 0;
    ListIterator<VClassGroup> it = groups.listIterator();
    while (it.hasNext()) {
        VClassGroup group = it.next();//  ww  w. j  ava2  s  . c o  m
        List<VClass> classes = group.getVitroClassList();
        if (classes == null || classes.size() < 1) {
            removedGroupsCount++;
            it.remove();
        }
    }
    return removedGroupsCount;
}

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParser.java

public void parse(String[] args) throws CmdLineParseException {
    LinkedList<String> arglist = new LinkedList<String>();
    arglist.addAll(Arrays.asList(args));

    // Quick Help
    if (arglist.contains("--" + OPT_HELP)) {
        usage();//  w  w  w. j a  va2s .c o  m
        return;
    }

    // Configuration File Option
    int idx = arglist.indexOf("--" + OPT_CONFIG);
    if (idx >= 0) {
        if (idx + 1 > arglist.size()) {
            throw new CmdLineParseException("Expected <File> parameter for option: --" + OPT_CONFIG);
        }
        String value = arglist.get(idx + 1);
        File file = (File) ConvertUtils.convert(value, File.class);

        this.configer.setPersistFile(file);

        arglist.remove(idx + 1);
        arglist.remove(idx);
    }

    // Save Options Option
    boolean saveOptions = false;

    idx = arglist.indexOf("--" + OPT_SAVE);
    if (idx >= 0) {
        saveOptions = true;
        arglist.remove(idx);
    }

    // Restore from persist first.
    try {
        configer.restore();
    } catch (IOException e) {
        throw new CmdLineParseException("Unable to load configuration: " + e.getMessage(), e);
    }

    // Set values from command line now.
    String value;
    ListIterator<String> iter = arglist.listIterator();
    while (iter.hasNext()) {
        String arg = iter.next();
        if (arg.startsWith("--")) {
            // Its an option.
            String optname = arg.substring(2);

            Configurable cfgrbl = configer.getConfigurable(optname);

            if (cfgrbl == null) {
                throw new CmdLineParseException("Invalid Option: " + arg);
            }

            if (!iter.hasNext()) {
                throw new CmdLineParseException(
                        "Expected <" + cfgrbl.getType() + "> parameter for option: " + arg);
            }
            value = iter.next();
            configer.setValue(optname, value);
            continue; // process next arg
        }

        // All others are considered args.
        addToRawArgs(arg);
    }

    // Save options (if specified)
    if (saveOptions) {
        try {
            configer.persist();
        } catch (IOException e) {
            throw new CmdLineParseException("Unable to save configuration: " + e.getMessage(), e);
        }
    }
}

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  a va2  s.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:com.mirth.connect.server.util.DatabaseConnection.java

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

    try {/*from   www  .ja  v  a  2 s .  co m*/
        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();
        CachedRowSetImpl crs = new CachedRowSetImpl();
        crs.populate(statement.getGeneratedKeys());
        return crs;
    } catch (SQLException e) {
        throw e;
    } finally {
        DbUtils.closeQuietly(statement);
    }
}

From source file:com.edgenius.wiki.render.macro.BaseMacro.java

/**
 * Move Iterator cursor backward or forward to given node. You must ensure then direction is correct! 
 * This location will only following "forward inertia". <br>
 * "Inertia" means, if iterator goes previous, then next, the same cursor will return, likewise in next->previous.
 * (see {@link com.edgenius.wiki.gwt.client.html.TestHTMLNodeContainer#testIteratorAdd()}) <br>
 * //from w  w w .j ava 2  s.com
 * This method will if call next(), it already return next HTMNode from current cursor. But if call previous(), 
 * it returns current cursor at first time. 
 *  
 * @param node
 * @param iter
 * @param forward
 */
protected void moveIteratorCursorTo(HTMLNode node, ListIterator<HTMLNode> iter, boolean forward) {
    if (forward) {
        if (iter.hasNext()) {
            HTMLNode cursor = iter.next();
            if (cursor.previous() != node) { //this is just ensure, iter current position is not equals with given node 
                while (cursor != node && iter.hasNext()) {
                    cursor = iter.next();
                }
            }
        }
    } else {
        //backward
        if (iter.hasPrevious()) {
            HTMLNode cursor = iter.previous();
            if (cursor.next() != node) { //this is just ensure, iter current position is not equals with given node 
                while (cursor != node && iter.hasPrevious()) {
                    cursor = iter.previous();
                }
            }
            //delete inertia
            iter.next();
        }
    }
}

From source file:com.amazonaws.hbase.connector.HBaseEmitter.java

@Override
public List<Map<String, String>> emit(final UnmodifiableBuffer<Map<String, String>> buffer) throws IOException {
    List<Map<String, String>> records = buffer.getRecords();
    ListIterator<Map<String, String>> iterator = records.listIterator();
    List<Put> batch = new ArrayList<Put>();
    HashMap<String, String> hashMap = (HashMap<String, String>) iterator.next();
    while (iterator.hasNext()) {
        //start with the row key followed by column family
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("user"),
                Bytes.toBytes("userid"), Bytes.toBytes(hashMap.get("userid"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("user"),
                Bytes.toBytes("firstname"), Bytes.toBytes(hashMap.get("firstname"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("user"),
                Bytes.toBytes("lastname"), Bytes.toBytes(hashMap.get("lastname"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("address"),
                Bytes.toBytes("city"), Bytes.toBytes(hashMap.get("city"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("address"),
                Bytes.toBytes("state"), Bytes.toBytes(hashMap.get("state"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("contact"),
                Bytes.toBytes("email"), Bytes.toBytes(hashMap.get("email"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("contact"),
                Bytes.toBytes("phone"), Bytes.toBytes(hashMap.get("phone"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likesports"), Bytes.toBytes(hashMap.get("likesports"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("liketheatre"), Bytes.toBytes(hashMap.get("liketheatre"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likeconcerts"), Bytes.toBytes(hashMap.get("likeconcerts"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likejazz"), Bytes.toBytes(hashMap.get("likejazz"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likeclassical"), Bytes.toBytes(hashMap.get("likeclassical"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likeopera"), Bytes.toBytes(hashMap.get("likeopera"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likerock"), Bytes.toBytes(hashMap.get("likerock"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likevegas"), Bytes.toBytes(hashMap.get("likevegas"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likebroadway"), Bytes.toBytes(hashMap.get("likebroadway"))));
        batch.add(new Put(Bytes.toBytes(hashMap.get("username"))).add(Bytes.toBytes("likes"),
                Bytes.toBytes("likemusicals"), Bytes.toBytes(hashMap.get("likemusicals"))));

        hashMap = (HashMap<String, String>) iterator.next();
    }/*  ww w .  j ava2 s  .  c  om*/
    LOG.info("EMIT: " + "records ....." + batch.size());
    HBaseUtils.addRecords(hbaseTableName, emrPublicDns, hbaseRestPort, batch);
    return Collections.emptyList();
    //return records;
}

From source file:org.socraticgrid.codeconversion.matchers.DescMatch.java

/**
 * Load the XML Document./*  w  w w  . j a  v  a2 s  .c o  m*/
 *
 * @param   is
 *
 * @throws  InitializationException
 */

protected void load(InputStream is) throws InitializationException {

    try {
        JAXBContext jaxbContext = JAXBContext
                .newInstance(org.socraticgrid.codeconversion.matchers.xml.ObjectFactory.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        org.socraticgrid.codeconversion.matchers.xml.DescMatch xmlMap = (org.socraticgrid.codeconversion.matchers.xml.DescMatch) jaxbUnmarshaller
                .unmarshal(is);

        Iterator<TargetSystem> itr = xmlMap.getTargetSystem().iterator();

        while (itr.hasNext()) {
            TargetSystem ts = itr.next();

            // Update
            contract.addTargetSystem(ts.getTargetSystemCode());

            TargetSystemCodeMap tsm = new TargetSystemCodeMap();
            tsMap.put(ts.getTargetSystemCode(), tsm);

            ListIterator<SourceCoding> sItr = ts.getSourceCoding().listIterator();

            while (sItr.hasNext()) {
                SourceCoding sc = sItr.next();
                HashMap<String, SourceCoding> map;

                if (tsm.SrchMap.containsKey(sc.getSourceName())) {
                    map = tsm.SrchMap.get(sc.getSourceName());
                } else {
                    map = new HashMap<>();
                    tsm.SrchMap.put(sc.getSourceName(), map);
                }

                map.put(sc.getSourceSystem(), sc);
            }
        }
    } catch (JAXBException exp) {
        throw new InitializationException("MapMap, Error parsing code map", exp);
    }
}

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

QueryBuilder createFilterFromCriteria(Criteria criteria) {
    List<QueryBuilder> fbList = new LinkedList<QueryBuilder>();
    QueryBuilder filter = null;//w w  w  . j  a  v  a2s .  com

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

    while (chainIterator.hasNext()) {
        QueryBuilder fb = null;
        Criteria chainedCriteria = chainIterator.next();
        if (chainedCriteria.isOr()) {
            fb = QueryBuilders.boolQuery();
            for (QueryBuilder f : createFilterFragmentForCriteria(chainedCriteria)) {
                ((BoolQueryBuilder) fb).should(f);
            }
            fbList.add(fb);
        } else if (chainedCriteria.isNegating()) {
            List<QueryBuilder> negationFilters = buildNegationFilter(criteria.getField().getName(),
                    criteria.getFilterCriteriaEntries().iterator());

            if (!negationFilters.isEmpty()) {
                fbList.addAll(negationFilters);
            }
        } else {
            fbList.addAll(createFilterFragmentForCriteria(chainedCriteria));
        }
    }

    if (!fbList.isEmpty()) {
        if (fbList.size() == 1) {
            filter = fbList.get(0);
        } else {
            filter = QueryBuilders.boolQuery();
            for (QueryBuilder f : fbList) {
                ((BoolQueryBuilder) filter).must(f);
            }
        }
    }
    return filter;
}