Example usage for java.util ListIterator remove

List of usage examples for java.util ListIterator remove

Introduction

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

Prototype

void remove();

Source Link

Document

Removes from the list the last element that was returned by #next or #previous (optional operation).

Usage

From source file:org.photovault.swingui.PhotoViewController.java

/**
 Remove photos from current model if they belong to it
 @param removePhotos Collection of photos that will be removed. Potentially 
 detached instances./*from   ww  w .  j  a v a 2s  . c  om*/
 */
private void removePhotos(Collection<PhotoInfo> removePhotos) {
    Set<UUID> removeIds = new TreeSet<UUID>();
    for (PhotoInfo p : removePhotos) {
        removeIds.add(p.getUuid());
    }

    ListIterator<PhotoInfo> iter = photos.listIterator();
    while (iter.hasNext()) {
        if (removeIds.contains(iter.next().getUuid())) {
            iter.remove();
        }
    }
}

From source file:org.squashtest.tm.domain.campaign.IterationTestPlanItem.java

public void removeExecution(Execution execution) {
    boolean wasLastExecution = false;
    if (this.getLatestExecution().equals(execution)) {
        wasLastExecution = true;//from   w w w .  ja v a 2s. c o  m
    }
    ListIterator<Execution> iterator = executions.listIterator();

    while (iterator.hasNext()) {
        Execution exec = iterator.next();
        if (exec.getId().equals(execution.getId())) {
            iterator.remove();
            break;
        }
    }
    if (wasLastExecution) {
        updateExecutionStatus();
        if (this.getLatestExecution() != null) {
            this.lastExecutedOn = this.getLatestExecution().getLastExecutedOn();
            this.lastExecutedBy = this.getLatestExecution().getLastExecutedBy();
        } else {
            this.lastExecutedOn = null;
            this.lastExecutedBy = null;
        }
        Iteration iter = this.getIteration();

        if (iter != null) {
            iter.updateAutoDatesAfterExecutionDetach(this);
        }
    }

}

From source file:org.mozilla.gecko.ui.SimpleScaleGestureDetector.java

private void onTouchEnd(MotionEvent event) {
    mLastEventTime = event.getEventTime();

    int id = event.getPointerId(getActionIndex(event));
    ListIterator<PointerInfo> iterator = mPointerInfo.listIterator();
    while (iterator.hasNext()) {
        PointerInfo pointerInfo = iterator.next();
        if (pointerInfo.getId() != id) {
            continue;
        }//w  w w  . j a v a  2s  .  c  o m

        // One of the pointers we were tracking was lifted. Remove its info object from the
        // list, recycle it to avoid GC pauses, and send an onScaleEnd() notification if this
        // ended the gesture.
        iterator.remove();
        pointerInfo.recycle();
        if (getPointersDown() == 1) {
            sendScaleGesture(EventType.END);
        }
    }
}

From source file:com.adobe.acs.commons.httpcache.engine.impl.HttpCacheEngineImpl.java

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

    // PIDs of global cache handling rules.
    globalCacheHandlingRulesPid = new ArrayList<String>(Arrays.asList(
            PropertiesUtil.toStringArray(configs.get(PROP_GLOBAL_CACHE_HANDLING_RULES_PID), new String[] {})));
    ListIterator<String> listIterator = globalCacheHandlingRulesPid.listIterator();
    while (listIterator.hasNext()) {
        String value = listIterator.next();
        if (StringUtils.isBlank(value)) {
            listIterator.remove();
        }/*from w ww .jav  a  2  s  .c o  m*/
    }
    log.info("HttpCacheEngineImpl activated.");
}

From source file:storm.mesos.schedulers.DefaultScheduler.java

/**
 * Schedule function looks in the "mesosWorkerSlotMap" to determine which topology owns the particular
 * WorkerSlot and assigns the executors accordingly.
 *///from w  w w.  j av  a  2  s .  c  om
@Override
public void schedule(Topologies topologies, Cluster cluster) {
    List<WorkerSlot> workerSlots = cluster.getAvailableSlots();
    String info = "Scheduling the following worker slots from cluster.getAvailableSlots: ";
    if (workerSlots.isEmpty()) {
        info += "[]";
    } else {
        List<String> workerSlotsStrings = new ArrayList<String>();
        for (WorkerSlot ws : workerSlots) {
            workerSlotsStrings.add(ws.toString());
        }
        info += String.format("[%s]", StringUtils.join(workerSlotsStrings, ", "));
    }
    log.info(info);

    Map<String, List<MesosWorkerSlot>> perTopologySlotList = getMesosWorkerSlotPerTopology(workerSlots);
    info = "Schedule the per-topology slots:";
    for (String topo : perTopologySlotList.keySet()) {
        List<String> mwsAssignments = new ArrayList<>();
        for (MesosWorkerSlot mws : perTopologySlotList.get(topo)) {
            mwsAssignments.add(mws.getNodeId() + ":" + mws.getPort());
        }
        info += String.format(" {%s, [%s]}", topo, StringUtils.join(mwsAssignments, ", "));
    }
    log.info(info);

    // So far we know how many MesosSlots each of the topologies have got. Let's assign executors for each of them
    for (String topologyId : perTopologySlotList.keySet()) {
        TopologyDetails topologyDetails = topologies.getById(topologyId);
        List<MesosWorkerSlot> mesosWorkerSlots = perTopologySlotList.get(topologyId);

        int slotsRequested = topologyDetails.getNumWorkers();
        int slotsAssigned = cluster.getAssignedNumWorkers(topologyDetails);
        int slotsAvailable = mesosWorkerSlots.size();

        if (slotsAvailable == 0) {
            log.warn("No slots found for topology {} while scheduling", topologyId);
            continue;
        }

        log.info("topologyId: {}, slotsRequested: {}, slotsAssigned: {}, slotsAvailable: {}", topologyId,
                slotsRequested, slotsAssigned, slotsAvailable);

        List<List<ExecutorDetails>> executorsPerWorkerList = executorsPerWorkerList(cluster, topologyDetails,
                slotsRequested, slotsAssigned, slotsAvailable);
        if (executorsPerWorkerList == null || executorsPerWorkerList.isEmpty()) {
            continue;
        }

        info = "schedule: Cluster assignment for " + topologyId + "." + " Requesting " + slotsRequested
                + " slots, with " + slotsAvailable + " slots available, and " + slotsAssigned
                + " currently assigned." + " Setting new assignment (node:port, executorsPerWorkerList) as: ";
        List<String> slotAssignmentStrings = new ArrayList<String>();
        ListIterator<List<ExecutorDetails>> iterator = executorsPerWorkerList.listIterator();
        while (iterator.hasNext()) {
            List<ExecutorDetails> executorsPerWorker = iterator.next();
            slotAssignmentStrings.add("(" + mesosWorkerSlots.get(0).getNodeId() + ":"
                    + mesosWorkerSlots.get(0).getPort() + ", " + executorsPerWorker.toString() + ")");
            iterator.remove();
            cluster.assign(mesosWorkerSlots.remove(0), topologyId, executorsPerWorker);
        }
        if (slotsAvailable == 0) {
            info += "[]";
        } else {
            info += StringUtils.join(slotAssignmentStrings, ", ");
        }
        log.info(info);
    }
    mesosWorkerSlotMap.clear();
}

From source file:org.springframework.security.ldap.userdetails.LdapUserDetailsManager.java

public void updateUser(UserDetails user) {
    DistinguishedName dn = usernameMapper.buildDn(user.getUsername());

    logger.debug("Updating user '" + user.getUsername() + "' with DN '" + dn + "'");

    List<GrantedAuthority> authorities = getUserAuthorities(dn, user.getUsername());

    DirContextAdapter ctx = loadUserAsContext(dn, user.getUsername());
    ctx.setUpdateMode(true);/* w ww . j a  v  a  2s  .co  m*/
    copyToContext(user, ctx);

    // Remove the objectclass attribute from the list of mods (if present).
    List<ModificationItem> mods = new LinkedList<>(Arrays.asList(ctx.getModificationItems()));
    ListIterator<ModificationItem> modIt = mods.listIterator();

    while (modIt.hasNext()) {
        ModificationItem mod = (ModificationItem) modIt.next();
        Attribute a = mod.getAttribute();
        if ("objectclass".equalsIgnoreCase(a.getID())) {
            modIt.remove();
        }
    }

    template.modifyAttributes(dn, mods.toArray(new ModificationItem[mods.size()]));

    // template.rebind(dn, ctx, null);
    // Remove the old authorities and replace them with the new one
    removeAuthorities(dn, authorities);
    addAuthorities(dn, user.getAuthorities());
}

From source file:org.eredlab.g4.ccl.net.ftp.parser.VMSVersioningFTPEntryParser.java

/**
 * Implement hook provided for those implementers (such as
 * VMSVersioningFTPEntryParser, and possibly others) which return
 * multiple files with the same name to remove the duplicates ..
 *
 * @param original Original list//from   ww w. j  a v  a 2 s  .  c om
 *
 * @return Original list purged of duplicates
 */
public List preParse(List original) {
    original = super.preParse(original);
    HashMap existingEntries = new HashMap();
    ListIterator iter = original.listIterator();
    while (iter.hasNext()) {
        String entry = ((String) iter.next()).trim();
        MatchResult result = null;
        if (_preparse_matcher_.matches(entry, _preparse_pattern_)) {
            result = _preparse_matcher_.getMatch();
            String name = result.group(1);
            String version = result.group(2);
            NameVersion nv = new NameVersion(name, version);
            NameVersion existing = (NameVersion) existingEntries.get(name);
            if (null != existing) {
                if (nv.versionNumber < existing.versionNumber) {
                    iter.remove(); // removal removes from original list.
                    continue;
                }
            }
            existingEntries.put(name, nv);
        }

    }
    // we've now removed all entries less than with less than the largest
    // version number for each name that were listed after the largest.
    // we now must remove those with smaller than the largest version number
    // for each name that were found before the largest
    while (iter.hasPrevious()) {
        String entry = ((String) iter.previous()).trim();
        MatchResult result = null;
        if (_preparse_matcher_.matches(entry, _preparse_pattern_)) {
            result = _preparse_matcher_.getMatch();
            String name = result.group(1);
            String version = result.group(2);
            NameVersion nv = new NameVersion(name, version);
            NameVersion existing = (NameVersion) existingEntries.get(name);
            if (null != existing) {
                if (nv.versionNumber < existing.versionNumber) {
                    iter.remove(); // removal removes from original list.
                }
            }
        }

    }
    return original;
}

From source file:org.kuali.kra.proposaldevelopment.service.impl.ProposalDevelopmentServiceImpl.java

/**
 * // ww  w.  jav a  2  s  . c  o  m
 * @see org.kuali.kra.proposaldevelopment.service.ProposalDevelopmentService#deleteProposal(org.kuali.kra.proposaldevelopment.document.ProposalDevelopmentDocument)
 */
public void deleteProposal(ProposalDevelopmentDocument proposalDocument) throws WorkflowException {
    ListIterator<BudgetDocumentVersion> iter = proposalDocument.getBudgetDocumentVersions().listIterator();
    while (iter.hasNext()) {
        BudgetDocumentVersion budgetVersion = iter.next();
        deleteProposalBudget(budgetVersion.getDocumentNumber(), proposalDocument);
        iter.remove();
    }
    //remove budget statuses as they are not referenced via ojb, but there is a
    //database constraint that requires removing these first
    Map<String, Object> keyValues = new HashMap<String, Object>();
    keyValues.put("proposalNumber", proposalDocument.getDevelopmentProposal().getProposalNumber());
    getBusinessObjectService().deleteMatching(ProposalBudgetStatus.class, keyValues);
    proposalDocument.getDevelopmentProposalList().clear();
    proposalDocument.getBudgetDocumentVersions().clear();
    proposalDocument.setProposalDeleted(true);

    //because the devproplist was cleared above the dev prop and associated BOs will be
    //deleted upon save
    getBusinessObjectService().save(proposalDocument);
    getDocumentService().cancelDocument(proposalDocument, "Delete Proposal");
}

From source file:org.libreplan.business.calendars.entities.AvailabilityTimeLine.java

private void removeAdjacent(int insertionPoint, Interval inserted) {
    ListIterator<Interval> listIterator = invalids.listIterator(insertionPoint + 1);
    while (listIterator.hasNext()) {
        Interval next = listIterator.next();
        if (!next.overlaps(inserted)) {
            break;
        }/*from  www .ja v a 2s  .  co m*/
        listIterator.remove();
    }
}

From source file:com.telestax.restcomm_olympus.CallActivity.java

private boolean havePermissions(ArrayList<String> permissions) {
    boolean allGranted = true;
    ListIterator<String> it = permissions.listIterator();
    while (it.hasNext()) {
        if (ActivityCompat.checkSelfPermission(this, it.next()) != PackageManager.PERMISSION_GRANTED) {
            allGranted = false;/*from  w w  w  .j av a 2s  .c  om*/
        } else {
            // permission granted, remove it from permissions
            it.remove();
        }
    }
    return allGranted;
}