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:com.mindquarry.desktop.workspace.ConflictHelper.java

/**
 * Finds all Add/Add conflicts, including file/file, file/dir, dir/file and
 * dir/dir conflicts./*ww  w.ja  va  2 s .  c o  m*/
 */
public static List<Conflict> findAddConflicts(List<Status> remoteAndLocalChanges) {
    List<Conflict> conflicts = new ArrayList<Conflict>();

    Iterator<Status> iter = remoteAndLocalChanges.iterator();
    while (iter.hasNext()) {
        Status status = iter.next();

        // local ADD / UNVERSIONED / IGNORED /EXTERNAL
        // (as we added everything, unversioned shouldn't happen)
        // and remote ADD
        if ((status.getTextStatus() == StatusKind.added || status.getTextStatus() == StatusKind.unversioned
                || status.getTextStatus() == StatusKind.ignored
                || status.getTextStatus() == StatusKind.external)
                && status.getRepositoryTextStatus() == StatusKind.added) {

            Status conflictParent = status;
            // we remove all files/stati connected to this conflict
            iter.remove();

            List<Status> localAdded = new ArrayList<Status>();
            List<Status> remoteAdded = new ArrayList<Status>();

            // find all children (locally and remotely)
            while (iter.hasNext()) {
                status = iter.next();
                if (FileHelper.isParent(conflictParent.getPath(), status.getPath())) {
                    if (status.getTextStatus() == StatusKind.added
                            || status.getTextStatus() == StatusKind.unversioned
                            || status.getTextStatus() == StatusKind.ignored
                            || status.getTextStatus() == StatusKind.external) {
                        localAdded.add(status);
                    } else if (status.getRepositoryTextStatus() == StatusKind.added) {
                        remoteAdded.add(status);
                    }
                    iter.remove();
                } else {
                    // no more children found, this conflict is done
                    // reset global iterator for next conflict search
                    iter = remoteAndLocalChanges.iterator();
                    break;
                }
            }
            conflicts.add(new AddConflict(conflictParent, localAdded, remoteAdded));
        }
    }
    return conflicts;
}

From source file:eu.europa.ec.fisheries.uvms.plugins.ais.service.AisService.java

@Schedule(minute = "*/1", hour = "*", persistent = false)
public void connectAndRetrive() {
    if (!startUp.isEnabled()) {
        return;//from  www  .  ja va  2 s. co m
    }
    if (connection != null && !connection.isOpen()) {
        String host = startUp.getSetting("HOST");
        int port = Integer.parseInt(startUp.getSetting("PORT"));
        String username = startUp.getSetting("USERNAME");
        String password = startUp.getSetting("PASSWORD");

        connection.open(host, port, username, password);
    }

    if (connection != null && connection.isOpen()) {
        Iterator<Future<Long>> processIterator = processes.iterator();
        while (processIterator.hasNext()) {
            Future<Long> process = processIterator.next();
            if (process.isDone() || process.isCancelled()) {
                processIterator.remove();
            }
        }
        List<String> sentences = connection.getSentences();
        Future<Long> process = processService.processMessages(sentences);
        processes.add(process);
        LOG.info("Got {} sentences from AIS RA. Currently running {} parallel threads", sentences.size(),
                processes.size());
    }
}

From source file:de.unirostock.sems.cbarchive.web.dataholder.WorkspaceHistory.java

/**
 * Removes all not existing workspaces from the history
 *//*from  ww  w.  j a  v  a2  s. co  m*/
@JsonIgnore
public void cleanUpHistory() {
    WorkspaceManager workspaceManager = WorkspaceManager.getInstance();

    Iterator<Workspace> iter = recentWorkspaces.iterator();
    while (iter.hasNext()) {
        Workspace elem = iter.next();
        if (workspaceManager.hasWorkspace(elem.getWorkspaceId()) == false)
            iter.remove();
    }

}

From source file:org.jboss.as.test.integration.logging.formatters.XmlFormatterTestCase.java

private static void validateDefault(final Document doc, final Collection<String> expectedKeys,
        final String expectedMessage) {
    final Set<String> remainingKeys = new HashSet<>(expectedKeys);

    String loggerClassName = null;
    String loggerName = null;/*www . jav a  2  s. com*/
    String level = null;
    String message = null;

    // Check all the expected keys
    final Iterator<String> iterator = remainingKeys.iterator();
    while (iterator.hasNext()) {
        final String key = iterator.next();
        final NodeList children = doc.getElementsByTagName(key);
        Assert.assertTrue(String.format("Key %s was not found in the document: %s", key, doc),
                children.getLength() > 0);
        final Node child = children.item(0);
        if ("loggerClassName".equals(child.getNodeName())) {
            loggerClassName = child.getTextContent();
        } else if ("loggerName".equals(child.getNodeName())) {
            loggerName = child.getTextContent();
        } else if ("level".equals(child.getNodeName())) {
            level = child.getTextContent();
        } else if ("message".equals(child.getNodeName())) {
            message = child.getTextContent();
        }
        iterator.remove();
    }

    // Should have no more remaining keys
    Assert.assertTrue("There are remaining keys that were not validated: " + remainingKeys,
            remainingKeys.isEmpty());

    Assert.assertEquals("org.jboss.logging.Logger", loggerClassName);
    Assert.assertEquals(LoggingServiceActivator.LOGGER.getName(), loggerName);
    Assert.assertTrue("Invalid level found in " + level, isValidLevel(level));
    Assert.assertEquals(expectedMessage, message);
}

From source file:edu.bellevue.hubspot.Leads.LeadsAPI.java

public void update_lead(String leadGuid, HashMap data) {
    String endpoint = "lead/" + leadGuid;

    // clear any values not able to be updated
    String[] badValues = new String[] { "id", "leadId", "isCustomer", "lastConvertedAt", "lastModifiedAt",
            "leadJsonLink", "leadLink", "LeadNurturingActive", "numConversionEvents", "portalId",
            "publicLeadLink", "sourceValueModifiedAt", "analyticsDetails", "crmDetails",
            "leadConversionEvents" };
    List badList = Arrays.asList(badValues);
    Iterator keys = data.keySet().iterator();
    while (keys.hasNext()) {
        if (badList.contains((String) keys.next())) {
            keys.remove();
        }//from  www .  ja va  2  s. c o  m
    }
    JSONObject a = new JSONObject(data);

    execute_put_request(get_request_url(endpoint, null), a.toString());
}

From source file:gov.nih.nci.caarray.upgrade.SingleConnectionHibernateHelper.java

/**
 * @param connection/*from w w w .j a  v a 2  s  .c o m*/
 */
public void initialize(Connection connection) {
    HibernateSingleConnectionProvider.setConnection(connection);

    InputStream configurationStream = FixIlluminaGenotypingCsvDesignProbeNamesMigrator.class
            .getResourceAsStream("/hibernate.cfg.xml");
    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new org.hibernate.util.DTDEntityResolver());
    Document configurationDocument = null;
    try {
        configurationDocument = reader.read(configurationStream);
    } catch (DocumentException e) {
        throw new UnhandledException(e);
    }
    Node sessionFactoryNode = configurationDocument
            .selectSingleNode("/hibernate-configuration/session-factory");

    Iterator<?> iter = ((Branch) sessionFactoryNode).nodeIterator();
    while (iter.hasNext()) {
        Node currentNode = (Node) iter.next();
        if (currentNode.getNodeType() == Node.ELEMENT_NODE && !currentNode.getName().equals("mapping")) {
            iter.remove();
        }
    }

    DOMWriter domWriter = new DOMWriter();
    org.w3c.dom.Document document = null;
    try {
        document = domWriter.write(configurationDocument);
    } catch (DocumentException e) {
        throw new UnhandledException(e);
    }

    configuration = new AnnotationConfiguration();
    configuration.setProperty(Environment.CONNECTION_PROVIDER,
            "gov.nih.nci.caarray.upgrade.HibernateSingleConnectionProvider");

    configuration.configure(document);

    configuration.setProperty(Environment.TRANSACTION_STRATEGY,
            "org.hibernate.transaction.JDBCTransactionFactory");
    configuration.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
    configuration.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
    configuration.getProperties().remove(Environment.TRANSACTION_MANAGER_STRATEGY);
    configuration.setNamingStrategy(new NamingStrategy());

    sessionFactory = configuration.buildSessionFactory();
}

From source file:com.kotcrab.vis.editor.module.editor.RecentProjectModule.java

@Override
public void init() {
    FileHandle storage = fileAccess.getMetadataFolder();

    storageFile = storage.child("recentProjects.json");

    json = new Json();
    json.setIgnoreUnknownFields(true);/*  w w w  .j  a va 2  s.c o m*/
    json.addClassTag("RecentProjectEntry", RecentProjectEntry.class);

    try {

        if (storageFile.exists()) {
            recentProjects = json.fromJson(new Array<RecentProjectEntry>().getClass(), storageFile);

            Iterator<RecentProjectEntry> it = recentProjects.iterator();
            while (it.hasNext()) {
                RecentProjectEntry entry = it.next();

                if (Gdx.files.absolute(entry.projectPath).exists() == false)
                    it.remove();
            }
        } else
            recentProjects = new Array<>();

    } catch (SerializationException ignored) { //no big deal if cache can't be loaded
        recentProjects = new Array<>();
    }
}

From source file:de.dhke.projects.cutil.collections.aspect.AspectMultiMapValueCollection.java

@Override
public void clear() {
    if (!isEmpty()) {
        if (_key == null) {
            /* no key, delete the complete collection */
            CollectionEvent<Map.Entry<K, V>, MultiMap<K, V>> ev = _aspectMap
                    .notifyBeforeCollectionCleared(_aspectMap);
            getOriginalValueCollection().clear();
            _aspectMap.notifyAfterCollectionCleared(ev);
        } else {//from   w w w .  j  av  a 2  s .  c  om
            /* key, delete items one by one */
            Iterator<V> iter = iterator();
            while (iter.hasNext()) {
                iter.next();
                iter.remove();
            }
        }
    }
}

From source file:com.subgraph.vega.internal.model.requests.RequestLog.java

@Override
public void removeUpdateListener(IRequestLogUpdateListener callback) {
    synchronized (lock) {
        final Iterator<RequestLogListener> it = listenerList.iterator();
        while (it.hasNext()) {
            RequestLogListener listener = it.next();
            if (listener.getListenerCallback() == callback)
                it.remove();
        }// ww w .  j ava 2  s .  c o  m
    }
}

From source file:com.amalto.core.initdb.InitDBUtil.java

private static void updateDB(String resourcePath, Map<String, List<String>> initdb) {
    for (Entry<String, List<String>> entry : initdb.entrySet()) {
        String dataCluster = entry.getKey();
        try {/*from  w ww  .  j a v  a  2s.  com*/
            ConfigurationHelper.createCluster(dataCluster);// slow but more reliable
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not create cluster.", e); //$NON-NLS-1$
            }
        }
        List<String> list = entry.getValue();
        // create items
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String item = iterator.next();
            try {
                InputStream in = InitDBUtil.class.getResourceAsStream(resourcePath + "/" + item); //$NON-NLS-1$
                String xmlString = IOUtils.toString(in, "UTF-8"); //$NON-NLS-1$
                String uniqueID = item;
                int pos = item.lastIndexOf('/');
                if (pos != -1) {
                    uniqueID = item.substring(pos + 1);
                }
                uniqueID = uniqueID.replaceAll("\\+", " "); //$NON-NLS-1$ //$NON-NLS-2$
                if (Boolean.valueOf((String) MDMConfiguration.getConfiguration().get("cluster_override"))) { //$NON-NLS-1$
                    ConfigurationHelper.deleteDocument(dataCluster, uniqueID);
                }
                ConfigurationHelper.putDocument(dataCluster, xmlString, uniqueID);
            } catch (Exception e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not delete document.", e); //$NON-NLS-1$
                }
            } finally {
                iterator.remove();
            }
        }
    }
}