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:org.elasticsoftware.elasticactors.geoevents.actors.Region.java

private void handle(DeRegisterInterest message) {
    State state = getState(State.class);
    ListIterator<RegisterInterest> itr = state.getListeners().listIterator();
    while (itr.hasNext()) {
        RegisterInterest registeredInterest = itr.next();
        if (registeredInterest.getActorRef().equals(message.getActorRef())
                && registeredInterest.getLocation().equals(message.getLocation())) {
            itr.remove();//  w w  w .j  av  a  2s.co  m
            if (message.isPropagate()) {
                // remove without propagating
                removeFromOtherRegions(state.getId(), registeredInterest,
                        new DeRegisterInterest(message.getActorRef(), message.getLocation(), false));
            }
        }
    }
}

From source file:org.wikimedia.analytics.kraken.pageview.PageviewCanonical.java

/**
 * Enter one or more keys to search for, this list of keys is
 * interpreted as key1 or key2; this function is not intended
 * to retrieve the values of multiple keys. In that case,
 * call this function multiple times./*from  ww  w.j  a  va  2s . c o  m*/
 * @param keys
 * @return
 */
private String searchQueryAction(final String[] keys) {
    try {
        URL pURL = fixApacheHttpComponentBug(url);

        List<NameValuePair> qparams = URLEncodedUtils.parse(pURL.toURI(), "utf-8");
        ListIterator<NameValuePair> it = qparams.listIterator();
        while (it.hasNext()) {
            NameValuePair nvp = it.next();
            for (String key : keys) {
                if (nvp.getName().equals(key)) {
                    return nvp.getValue();
                }
            }
        }
    } catch (URISyntaxException e) {
        return "key.not.found";
    } catch (MalformedURLException e) {
        return "malformed.url";
    }
    return "key.not.found";
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.MoveFreeVariableOperatorOutOfSubplanRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    /*//from  w w w .  j  a v  a  2 s  . co  m
     * This rule looks for an assign within a subplan that uses only 
     * variables from outside of the subplan
     * 
     * It moves this assign outside of the subplan
     * 
     */
    AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue();
    if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
        return false;
    }
    SubplanOperator subplan = (SubplanOperator) op0;

    Mutable<ILogicalOperator> leftRef = subplan.getInputs().get(0);
    if (((AbstractLogicalOperator) leftRef.getValue())
            .getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
        return false;
    }

    ListIterator<ILogicalPlan> plansIter = subplan.getNestedPlans().listIterator();
    ILogicalPlan p = null;
    while (plansIter.hasNext()) {
        p = plansIter.next();
    }
    if (p == null) {
        return false;
    }
    if (p.getRoots().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> opRef1 = p.getRoots().get(0);

    //The root operator will not be movable. Start with the second op
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef1.getValue();
    if (op1.getInputs().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);

    //Get all variables that come from outside of the loop
    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op1, free);

    while (op2Ref != null) {
        //Get the operator that we want to look at
        AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();

        //Make sure we are looking at subplan with a scan/join
        if (op2.getInputs().size() != 1 || !descOrSelfIsScanOrJoin(op2)) {
            return false;
        }
        boolean notApplicable = false;

        //Get its used variables
        Set<LogicalVariable> used = new HashSet<LogicalVariable>();
        VariableUtilities.getUsedVariables(op2, used);

        //not movable if the operator is not an assign
        //Might be helpful in the future for other operations in the future
        if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
            notApplicable = true;
        }

        //Make sure that all of its used variables come from outside
        for (LogicalVariable var : used) {
            if (!free.contains(var)) {
                notApplicable = true;
            }
        }

        if (notApplicable) {
            op2Ref = op2.getInputs().get(0);
        } else {
            //Make the input of op2 be the input of op1
            op2Ref.setValue(op2.getInputs().get(0).getValue());

            //Make the outside of the subplan the input of op2
            Mutable<ILogicalOperator> outsideRef = op2.getInputs().get(0);
            outsideRef.setValue(op0.getInputs().get(0).getValue());

            //Make op2 the input of the subplan
            Mutable<ILogicalOperator> op2OutsideRef = op0.getInputs().get(0);
            op2OutsideRef.setValue(op2);

            return true;
        }

    }
    return false;
}

From source file:com.bluelotussoftware.apache.commons.fileupload.example.MultiContentServlet.java

/**
 * Handles the HTTP// w  w  w  . j av  a2 s  . c  o m
 * <code>POST</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter writer = null;
    InputStream is = null;
    FileOutputStream fos = null;

    try {
        writer = response.getWriter();
    } catch (IOException ex) {
        log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
    }

    boolean isMultiPart = ServletFileUpload.isMultipartContent(request);

    if (isMultiPart) {
        log("Content-Type: " + request.getContentType());
        // Create a factory for disk-based file items
        DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();

        /*
         * Set the file size limit in bytes. This should be set as an
         * initialization parameter
         */
        diskFileItemFactory.setSizeThreshold(1024 * 1024 * 10); //10MB.

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(diskFileItemFactory);

        List items = null;

        try {
            items = upload.parseRequest(request);
        } catch (FileUploadException ex) {
            log("Could not parse request", ex);
        }

        ListIterator li = items.listIterator();

        while (li.hasNext()) {
            FileItem fileItem = (FileItem) li.next();
            if (fileItem.isFormField()) {
                if (debug) {
                    processFormField(fileItem);
                }
            } else {
                writer.print(processUploadedFile(fileItem));
            }
        }
    }

    if ("application/octet-stream".equals(request.getContentType())) {
        log("Content-Type: " + request.getContentType());
        String filename = request.getHeader("X-File-Name");

        try {
            is = request.getInputStream();
            fos = new FileOutputStream(new File(realPath + filename));
            IOUtils.copy(is, fos);
            response.setStatus(HttpServletResponse.SC_OK);
            writer.print("{success: true}");
        } catch (FileNotFoundException ex) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            writer.print("{success: false}");
            log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
        } catch (IOException ex) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            writer.print("{success: false}");
            log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
        } finally {
            try {
                fos.close();
                is.close();
            } catch (IOException ignored) {
            }
        }

        writer.flush();
        writer.close();
    }
}

From source file:com.offbynull.voip.kademlia.model.NodeMostRecentSet.java

public ActivityChangeSet touch(Instant time, Node node, boolean allowLinkMismatch) {
    Validate.notNull(time);//w  ww  .j  a v  a  2  s  .com
    Validate.notNull(node);

    Id nodeId = node.getId();

    InternalValidate.matchesLength(baseId.getBitLength(), nodeId);
    //        Validate.isTrue(!nodeId.equals(baseId)); // Don't reject adding self

    // TODO: You can make this way more efficient if you used something like MultiTreeSet (guava) and sorted based on entry time

    // Remove existing entry
    Activity oldEntry = null;
    ListIterator<Activity> it = entries.listIterator();
    while (it.hasNext()) {
        Activity entry = it.next();

        Id entryId = entry.getNode().getId();

        if (entryId.equals(nodeId)) {
            if (!allowLinkMismatch) {
                InternalValidate.matchesLink(entry.getNode(), node);
            }

            // remove
            it.remove();
            oldEntry = entry;
            break;
        }
    }

    // Add entry
    Activity newEntry = new Activity(node, time);
    it = entries.listIterator(entries.size());
    boolean added = false;
    while (it.hasPrevious()) {
        Activity entry = it.previous();

        if (entry.getTime().isBefore(time)) {
            it.next(); // move forward 1 space, we want to add to element just after entry
            it.add(newEntry);
            added = true;
            break;
        }
    }

    if (!added) { // special case where newEntry needs to be added at the end of entries, not handled by loop above
        entries.addFirst(newEntry);
    }

    // Set has become too large, remove the item with the earliest time
    Activity discardedEntry = null;
    if (entries.size() > maxSize) {
        // if the node removed with the earliest time is the one we just added, then report that node couldn't be added
        discardedEntry = entries.removeFirst();
        if (discardedEntry.equals(newEntry)) {
            return ActivityChangeSet.NO_CHANGE;
        }
    }

    // Add successful
    if (oldEntry != null) {
        Validate.validState(discardedEntry == null); // sanity check, must not have discarded anything

        // updated existing node
        return ActivityChangeSet.updated(newEntry);
    } else {
        // if block above ensures oldEntry is null if we're in this else block, so sanity check below isn't nessecary
        // Validate.validState(oldEntry == null); // sanity check, node being touched must not have already existed

        // added new node
        Collection<Activity> addedEntries = singletonList(newEntry);
        Collection<Activity> removedEntries = discardedEntry == null ? emptyList()
                : singletonList(discardedEntry);
        Collection<Activity> updatedEntries = emptyList();
        return new ActivityChangeSet(addedEntries, removedEntries, updatedEntries);
    }
}

From source file:gov.nih.nci.ncicb.cadsr.common.jsp.tag.handler.AvailableValidValue.java

public List getNotListedValidValues(List questionVVList, List availableVVList) {
    List nonListedVVs = new ArrayList();
    ListIterator availableVVListIterate = availableVVList.listIterator();

    FormValidValue currFormValidValue = null;
    while (availableVVListIterate.hasNext()) {
        currFormValidValue = (FormValidValue) availableVVListIterate.next();
        //Valid Values may not be mapped to VD
        if (!questionVVList.contains(currFormValidValue)) {
            nonListedVVs.add(currFormValidValue);
        }//w  w  w .j ava2 s  .  c om
    }
    return nonListedVVs;
}

From source file:com.activecq.experiments.pageimage.impl.PageImageServletImpl.java

/**
 * Retrieves the Width and Height from the Sling Selectors on the requested URI
 *
 * @param key//  w  w w  .  j  a  v a 2s . c om
 * @param request
 * @return
 */
private String getDimension(final String key, final SlingHttpServletRequest request) {
    final RequestPathInfo rpi = request.getRequestPathInfo();
    final ListIterator<String> iterator = Arrays.asList(rpi.getSelectors()).listIterator();

    while (iterator.hasNext()) {
        final String selector = iterator.next();

        if (key.equals(selector)) {
            return iterator.next();
        }
    }

    return "0";
}

From source file:com.garyclayburg.persistence.repository.AccountMatcher.java

public User attachAccount(UserAccount scimAccount) {
    User matchedUser = matchAccount(scimAccount);
    User savedUser = null;/*from  w  ww. j  av  a 2 s . co m*/
    if (matchedUser != null) {
        List<UserAccount> userAccounts = matchedUser.getUserAccounts();

        if (userAccounts != null) {
            ListIterator<UserAccount> listIterator = userAccounts.listIterator();
            boolean updatedAccount = false;
            while (listIterator.hasNext()) {
                UserAccount userAccount = listIterator.next();
                String username = userAccount.getUsername();
                String accountType = userAccount.getAccountType();
                if (username != null && accountType != null) {
                    if (username.equals(scimAccount.getUsername())
                            && accountType.equals(scimAccount.getAccountType())) {
                        listIterator.set(scimAccount);
                        updatedAccount = true;
                    }
                }

            }
            if (!updatedAccount) { //add as new account for this matched user
                userAccounts.add(scimAccount);
            }
        } else { //user does not have any accounts yet.  This will be his first.
            List<UserAccount> newAccounts = new ArrayList<>();
            newAccounts.add(scimAccount);
            matchedUser.setUserAccounts(newAccounts);
        }
        savedUser = auditedUserRepo.save(matchedUser);
    }
    return savedUser;
}

From source file:com.offbynull.voip.kademlia.model.NodeLeastRecentSet.java

public ActivityChangeSet touch(Instant time, Node node, boolean allowLinkMismatch) {
    Validate.notNull(time);/* w  w  w .j a va2 s .c o m*/
    Validate.notNull(node);

    Id nodeId = node.getId();

    InternalValidate.matchesLength(baseId.getBitLength(), nodeId);
    //        Validate.isTrue(!nodeId.equals(baseId)); // Don't reject adding self

    // TODO: You can make this way more efficient if you used something like MultiTreeSet (guava) and sorted based on entry time

    // Remove existing entry
    Activity oldEntry = null;
    ListIterator<Activity> it = entries.listIterator();
    while (it.hasNext()) {
        Activity entry = it.next();

        Id entryId = entry.getNode().getId();

        if (entryId.equals(nodeId)) {
            if (!allowLinkMismatch) {
                InternalValidate.matchesLink(entry.getNode(), node);
            }

            // remove
            it.remove();
            oldEntry = entry;
            break;
        }
    }

    // Add entry
    Activity newEntry = new Activity(node, time);
    it = entries.listIterator();
    boolean added = false;
    while (it.hasNext()) {
        Activity entry = it.next();

        if (entry.getTime().isAfter(time)) {
            it.previous(); // move back 1 space, we want to add to element just before entry
            it.add(newEntry);
            added = true;
            break;
        }
    }

    if (!added) { // special case where newEntry needs to be added at the end of entries, not handled by loop above
        entries.addLast(newEntry);
    }

    // Set has become too large, remove the item with the latest time
    Activity discardedEntry = null;
    if (entries.size() > maxSize) {
        // if the node removed with the latest time is the one we just added, then report that node couldn't be added
        discardedEntry = entries.removeLast();
        if (discardedEntry.equals(newEntry)) {
            return ActivityChangeSet.NO_CHANGE;
        }
    }

    // Add successful
    if (oldEntry != null) {
        Validate.validState(discardedEntry == null); // sanity check, must not have discarded anything

        // updated existing node
        return ActivityChangeSet.updated(newEntry);
    } else {
        // if block above ensures oldEntry is null if we're in this else block, so sanity check below isn't nessecary
        // Validate.validState(oldEntry == null); // sanity check, node being touched must not have already existed

        // added new node
        Collection<Activity> addedEntries = singletonList(newEntry);
        Collection<Activity> removedEntries = discardedEntry == null ? emptyList()
                : singletonList(discardedEntry);
        Collection<Activity> updatedEntries = emptyList();
        return new ActivityChangeSet(addedEntries, removedEntries, updatedEntries);
    }
}

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

public int removeUnpopulatedGroups(List<PropertyGroup> groups) {
    if (groups == null || groups.size() == 0)
        return 0;
    int removedGroupsCount = 0;
    ListIterator<PropertyGroup> it = groups.listIterator();
    while (it.hasNext()) {
        PropertyGroup group = it.next();
        List properties = group.getPropertyList();
        if (properties == null || properties.size() < 1) {
            removedGroupsCount++;//from  w  ww.  j  a v  a 2  s .c  om
            it.remove();
        }
    }
    return removedGroupsCount;
}