Example usage for java.util Iterator remove

List of usage examples for java.util Iterator remove

Introduction

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

Prototype

default void remove() 

Source Link

Document

Removes from the underlying collection the last element returned by this iterator (optional operation).

Usage

From source file:de.doering.dwca.flickr.OccurrenceExport.java

private void searchYear(int year) {
    if (threads.size() < THREADS) {
        threads.add(startThread(year));/*from w ww  .  j  av  a  2 s  .  c  om*/
    } else {
        // wait until one thread is finished
        log.debug("Waiting for a thread to finish");
        do {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            Iterator<Thread> iter = threads.iterator();
            while (iter.hasNext()) {
                Thread t = iter.next();
                if (!t.isAlive()) {
                    log.debug("Thread " + t.getName() + " finished");
                    iter.remove();
                }
            }
        } while (threads.size() == THREADS);

        threads.add(startThread(year));
    }
}

From source file:eu.esdihumboldt.hale.ui.service.project.internal.RecentProjectsServiceImpl.java

/**
 * @see RecentProjectsService#add(String, String)
 *//*from www  . ja va 2 s . co  m*/
@Override
public void add(String file, String projectName) {
    if (file != null) {
        CircularFifoBuffer buffer = restoreState();

        if (projectName == null)
            projectName = "";
        Entry entry = new EntryImpl(file, projectName);
        Iterator<?> i = buffer.iterator();
        while (i.hasNext()) {
            Entry rfe = (Entry) i.next();
            if (entry.equals(rfe)) {
                i.remove();
                break;
            }
        }
        buffer.add(entry);

        saveState(buffer);
    }
}

From source file:edu.oregonstate.eecs.mcplan.domains.voyager.LaunchAction.java

@Override
public void undoAction(final VoyagerState s) {
    assert (done_);
    log.debug("undo {}", toString());
    final Iterator<Spaceship> sitr = s.spaceships.iterator();
    while (sitr.hasNext()) {
        final Spaceship sp = sitr.next();
        if (sp.id == spaceship_.id) {
            sitr.remove();
            break;
        }/*from   ww  w  . j a v a2  s. c om*/
    }
    for (int i = 0; i < population.length; ++i) {
        src.incrementPopulation(player, Unit.values()[i], population[i]);
    }
    src.setOwner(old_owner_);
    for (final Player y : Player.competitors) {
        src.setCarryDamage(y, old_carry_damage_[y.id]);
    }
    src.setProduction(old_production_);
    src.setStoredProduction(old_stored_production_);
    done_ = false;
}

From source file:net.socket.nio.TimeClientHandle.java

@Override
public void run() {
    try {//from   w  ww.j  a  v  a2s.c  om
        doConnect();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    while (!stop) {
        try {
            selector.select(1000);
            Set<SelectionKey> selectedKeys = selector.selectedKeys();
            Iterator<SelectionKey> it = selectedKeys.iterator();
            SelectionKey key = null;
            while (it.hasNext()) {
                key = it.next();
                it.remove();
                try {
                    handleInput(key);
                } catch (Exception e) {
                    if (key != null) {
                        key.cancel();
                        if (key.channel() != null) {
                            key.channel().close();
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    // ???ChannelPipe??????
    IOUtils.closeQuietly(selector);

}

From source file:hydrograph.ui.graph.utility.DataViewerUtility.java

public void closeDataViewerWindows() {
    List<DebugDataViewer> dataViewerList = new ArrayList<>();
    dataViewerList.addAll(JobManager.INSTANCE.getDataViewerMap().values());

    JobManager.INSTANCE.getDataViewerMap().clear();
    Iterator<DebugDataViewer> iterator = dataViewerList.iterator();
    while (iterator.hasNext()) {
        DebugDataViewer daDebugDataViewer = (DebugDataViewer) iterator.next();
        daDebugDataViewer.close();/*from   ww w .  ja va  2 s.c om*/
        iterator.remove();
    }
}

From source file:com.predic8.membrane.core.interceptor.balancer.SessionCleanupThread.java

private int cleanupSessions(Cluster c) {
    Collection<Session> ss = c.getSessions().values();
    Iterator<Session> sIt = ss.iterator();
    int cleaned = 0;
    long now = System.currentTimeMillis();

    while (sIt.hasNext()) {
        Session s = sIt.next();//from   w  w w.j  a  v  a 2s .c  om
        if (now - s.getLastUsed() > sessionTimeout) {
            cleaned++;
            sIt.remove();
        }
    }
    return cleaned;
}

From source file:com.mycompany.crawlertest.GrabManager.java

private boolean checkPageGrabs() throws InterruptedException {
    Thread.sleep(PAUSE_TIME);/*  w ww . jav  a  2s.co  m*/
    Set<GrabPage> pageSet = new HashSet<>();
    Iterator<Future<GrabPage>> iterator = futures.iterator();

    while (iterator.hasNext()) {
        Future<GrabPage> future = iterator.next();
        if (future.isDone()) {
            iterator.remove();
            try {
                pageSet.add(future.get());
            } catch (InterruptedException e) { // skip pages that load too slow
            } catch (ExecutionException e) {
            }
        }
    }
    for (GrabPage grabPage : pageSet) {
        addNewURLs(grabPage);
    }

    return (futures.size() > 0);
}

From source file:com.taobao.diamond.client.impl.UnpublishTaskProcessor.java

private boolean processUnpublish(UnpublishTask unpublishTask) {
    int count = unpublishTask.getCount();
    int waitTime = getWaitTime(++count);
    log.info("" + count + "");
    unpublishTask.setCount(count);//from  w w w.j a  v  a2 s .  c om
    String dataId = unpublishTask.getDataId();
    String group = unpublishTask.getGroup();

    Iterator<String> it = unpublishTask.getContents().iterator();
    while (it.hasNext()) {
        String configInfo = it.next();
        if (innerUnpublish(unpublishTask, waitTime, dataId, group, configInfo)) {
            it.remove();
        } else {
            return false;
        }
    }
    return true;
}

From source file:com.twitter.hraven.etl.AssertHistoryListener.java

@Override
public void handle(JobHistoryCopy.RecordTypes recType, Map<JobHistoryKeys, String> values) throws IOException {
    if (JobHistoryCopy.RecordTypes.Job != recType) {
        log.warn(String.format("Not asserting record of type %s", recType));
        return;/*from   ww  w.jav  a2  s  .  c o m*/
    }
    String jobId = values.get(JobHistoryKeys.JOBID);
    log.info("Asserting record values for job " + jobId);

    if (values.get(JobHistoryKeys.JOB_STATUS) != null) {
        this.status = values.get(JobHistoryKeys.JOB_STATUS);
    }

    // assert first-class stats
    Iterator<Pair<JobHistoryKeys, String>> iterator = keysToAssert.iterator();
    while (iterator.hasNext()) {
        if (tryAssertKey(iterator.next(), values)) {
            iterator.remove();
        }
    }

    // assert counters
    if (values.get(JobHistoryKeys.COUNTERS) != null) {
        assertCounters(jobId, values.get(JobHistoryKeys.COUNTERS), jobDetails.getCounters());
        assertedCounters = true;
    }
    if (values.get(JobHistoryKeys.MAP_COUNTERS) != null) {
        assertCounters(jobId, values.get(JobHistoryKeys.MAP_COUNTERS), jobDetails.getMapCounters());
        assertedMapCounters = true;
    }
    if (values.get(JobHistoryKeys.REDUCE_COUNTERS) != null) {
        assertCounters(jobId, values.get(JobHistoryKeys.REDUCE_COUNTERS), jobDetails.getReduceCounters());
        assertedReduceCounters = true;
    }
}

From source file:com.datatorrent.stram.client.StramClientUtils.java

@SuppressWarnings("deprecation")
private static void convertDeprecatedProperties(Configuration conf) {
    Iterator<Map.Entry<String, String>> iterator = conf.iterator();
    Map<String, String> newEntries = new HashMap<String, String>();
    while (iterator.hasNext()) {
        Map.Entry<String, String> entry = iterator.next();
        if (entry.getKey().startsWith("stram.")) {
            String newKey = StreamingApplication.DT_PREFIX + entry.getKey().substring(6);
            LOG.warn("Configuration property {} is deprecated. Please use {} instead.", entry.getKey(), newKey);
            newEntries.put(newKey, entry.getValue());
            iterator.remove();
        }//from w w  w. j  a  va2s  . c  o  m
    }
    for (Map.Entry<String, String> entry : newEntries.entrySet()) {
        conf.set(entry.getKey(), entry.getValue());
    }
}