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:mase.app.foraging.LandRobot.java

@Override
public void action(double[] output) {
    super.action(output);

    ForagingTask ft = (ForagingTask) super.sim;
    Iterator<Item> iter = ft.items.iterator();
    while (iter.hasNext()) {
        Item i = iter.next();/*from www  .  ja  v a2 s  . co m*/
        if (this.distanceTo(i) <= 0) {
            ft.field.remove(i);
            iter.remove();
        }
    }
    if (ft.items.isEmpty()) {
        ft.kill();
    }
}

From source file:com.untangle.uvm.EventManagerImpl.java

/**
 * Make json formatted event more suitable for users:
 * * Remove unncessessary fields./*  ww  w  .ja v  a 2 s .com*/
 * * Recursively clean.
 * @param jsonObject JSONObject to process.
 */
private static void cleanupJsonObject(JSONObject jsonObject) {
    if (jsonObject == null)
        return;

    @SuppressWarnings("unchecked")
    java.util.Iterator<String> keys = (java.util.Iterator<String>) jsonObject.keys();
    while (keys.hasNext()) {
        String key = keys.next();

        if ("class".equals(key)) {
            keys.remove();
            continue;
        }
        if ("tag".equals(key)) {
            keys.remove();
            continue;
        }
        if ("partitionTablePostfix".equals(key)) {
            keys.remove();
            continue;
        }

        /**
         * Recursively clean json objects
         */
        try {
            JSONObject subObject = jsonObject.getJSONObject(key);
            if (subObject != null) {
                cleanupJsonObject(subObject);
            }
        } catch (Exception e) {
            /* ignore */
        }

        /**
         * If the object implements JSONString, then its probably a jsonObject
         * Convert to JSON Object, recursively clean that, then replace it
         */
        try {
            if (jsonObject.get(key) != null) {
                Object o = jsonObject.get(key);
                if (o instanceof org.json.JSONString) {
                    JSONObject newObj = new JSONObject(o);
                    cleanupJsonObject(newObj);
                    jsonObject.put(key, newObj);
                }
            }
        } catch (Exception e) {
            /* ignore */
        }
    }
}

From source file:framework.retrieval.engine.pool.impl.IndexWriterPool.java

public synchronized void clean() {
    log.debug("IndexWriterPool Clean indexWriterProxy.............");
    Iterator<String> it = indexPathTypes.iterator();
    while (it.hasNext()) {
        String indexPathType = it.next();
        interRemove(indexPathType);//from w w w. j  a  v a  2s .  com
        it.remove();
    }
    log.debug("IndexWriterPool Clean complete.............");
}

From source file:com.ewcms.publication.task.MemoryTaskQueue.java

@Override
public void remove(String id) {
    Assert.notNull(id, "task id is null");
    Iterator<Taskable> iterator = tasks.iterator();
    for (Taskable t = iterator.next(); iterator.hasNext(); t = iterator.next()) {
        if (t.getId().equals(id)) {
            iterator.remove();
        }/*from w w  w  .  j a v a2s .c o m*/
    }
}

From source file:org.cloudfoundry.identity.uaa.login.feature.CreateAccountIT.java

@Test
public void testClientInitiatedSignup() throws Exception {
    String userEmail = "user" + new SecureRandom().nextInt() + "@example.com";

    webDriver.get(baseUrl + "/create_account?client_id=app");

    Assert.assertEquals("Create your account", webDriver.findElement(By.tagName("h1")).getText());

    int receivedEmailSize = simpleSmtpServer.getReceivedEmailSize();

    webDriver.findElement(By.name("email")).sendKeys(userEmail);
    webDriver.findElement(By.name("password")).sendKeys("secret");
    webDriver.findElement(By.name("password_confirmation")).sendKeys("secret");
    webDriver.findElement(By.xpath("//input[@value='Send activation link']")).click();

    Assert.assertEquals(receivedEmailSize + 1, simpleSmtpServer.getReceivedEmailSize());
    Iterator receivedEmail = simpleSmtpServer.getReceivedEmail();
    SmtpMessage message = (SmtpMessage) receivedEmail.next();
    receivedEmail.remove();
    Assert.assertEquals(userEmail, message.getHeaderValue("To"));
    Assert.assertThat(message.getBody(), containsString("Activate your account"));

    Assert.assertEquals("Please check email for an activation link.",
            webDriver.findElement(By.cssSelector(".instructions-sent")).getText());

    String link = testClient.extractLink(message.getBody());
    assertFalse(isEmpty(link));/* ww w . java2 s  .c om*/

    webDriver.get(link);
    Assert.assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), not(containsString("Where to?")));
}

From source file:com.skcraft.launcher.auth.AccountList.java

/**
 * Remove an account.//from  w ww. j  a v a  2  s  .  c  om
 *
 * @param account the account
 */
public synchronized void remove(@NonNull Account account) {
    Iterator<Account> it = accounts.iterator();
    while (it.hasNext()) {
        Account other = it.next();
        if (other.equals(account)) {
            it.remove();
            fireContentsChanged(this, 0, accounts.size() + 1);
            break;
        }
    }
}

From source file:com.gigaspaces.internal.utils.ClassLoaderCleaner.java

/**
 * Clear the {@link ResourceBundle} cache of any bundles loaded by this class loader or any
 * class loader where this loader is a parent class loader.
 *
 * The ResourceBundle is using WeakReferences so it shouldn't be pinning the class loader in
 * memory. However, it is. Therefore clear ou the references.
 *//*ww  w . j  av a 2s.c o  m*/
private static void clearReferencesResourceBundles(ClassLoader classLoader) {
    // Get a reference to the cache
    try {
        Field cacheListField = ResourceBundle.class.getDeclaredField("cacheList");
        cacheListField.setAccessible(true);

        // Java 6 uses ConcurrentMap
        // Java 5 uses SoftCache extends Abstract Map
        // So use Map and it *should* work with both
        Map<?, ?> cacheList = (Map<?, ?>) cacheListField.get(null);

        // Get the keys (loader references are in the key)
        Set<?> keys = cacheList.keySet();

        Field loaderRefField = null;

        // Iterate over the keys looking at the loader instances
        Iterator<?> keysIter = keys.iterator();

        int countRemoved = 0;

        while (keysIter.hasNext()) {
            Object key = keysIter.next();

            if (loaderRefField == null) {
                loaderRefField = key.getClass().getDeclaredField("loaderRef");
                loaderRefField.setAccessible(true);
            }
            WeakReference<?> loaderRef = (WeakReference<?>) loaderRefField.get(key);

            ClassLoader loader = (ClassLoader) loaderRef.get();

            while (loader != null && loader != classLoader) {
                loader = loader.getParent();
            }

            if (loader != null) {
                keysIter.remove();
                countRemoved++;
            }
        }

        if (countRemoved > 0 && logger.isLoggable(Level.FINE)) {
            logger.fine("Removed [" + countRemoved + "] ResourceBundle references from the cache");
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to clear ResourceBundle references", e);
    }
}

From source file:net.landora.video.mplayer.MPlayerParser.java

private Integer selectAndRemove(Collection<Integer> collection) {
    Iterator<Integer> i = collection.iterator();
    if (i.hasNext()) {
        Integer result = i.next();
        i.remove();
        return result;
    } else {//from w w  w  .  jav  a  2  s. c  om
        return null;
    }
}

From source file:org.freeeed.search.web.controller.TagAutoCompleteController.java

@Override
public ModelAndView execute() {
    SolrSessionObject solrSession = SessionContext.getSolrSession();
    if (solrSession != null) {
        Case c = solrSession.getSelectedCase();

        String term = (String) valueStack.get("term");
        if (c != null) {
            List<String> tags = c.getTags();
            Iterator<String> iter = tags.iterator();
            while (iter.hasNext()) {
                String tag = iter.next();
                if (!tag.matches(".*" + term + ".*")) {
                    iter.remove();
                }/* w  w w  .j ava  2  s .c om*/
            }

            StringBuffer result = new StringBuffer();
            result.append("[");

            for (int i = 0; i < tags.size(); i++) {
                String tag = tags.get(i);
                result.append("\"").append(tag).append("\"");
                if (i < tags.size() - 1) {
                    result.append(",");
                }
            }

            result.append("]");

            valueStack.put("data", result.toString());
        }
    }
    return new ModelAndView(WebConstants.TAG_AUTO);
}

From source file:com.mobius.software.mqtt.performance.controller.net.AbstractClient.java

public void shutdown() throws InterruptedException {
    Iterator<Entry<SocketAddress, Channel>> iterator = clientChannels.entrySet().iterator();
    while (iterator.hasNext()) {
        try {//from w  w  w. j a  va 2  s. c om
            iterator.next().getValue().close();
            iterator.remove();
        } catch (Exception e) {
            logger.error("An error occured while performing shutdown: client channel close failed - "
                    + e.getMessage());
        }
    }
}