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:org.cloudfoundry.identity.uaa.login.feature.CreateAccountIT.java

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

    webDriver.get(baseUrl + "/");
    webDriver.findElement(By.xpath("//*[text()='Create account']")).click();

    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("Create your account", webDriver.findElement(By.tagName("h1")).getText());
    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));/*from w  w  w. j  a v  a2 s  . com*/

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

    webDriver.findElement(By.xpath("//*[text()='" + userEmail + "']")).click();
    webDriver.findElement(By.linkText("Sign Out")).click();

    webDriver.findElement(By.name("username")).sendKeys(userEmail);
    webDriver.findElement(By.name("password")).sendKeys("secret");
    webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();

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

From source file:net.cristcost.study.gwt.server.TagServiceImpl.java

@Override
@PreAuthorize("isAuthenticated() and principal.username == #tagUser")
public void deleteTag(String tagUser, String tag) {
    Iterator<Tag> iter = database.iterator();
    while (iter.hasNext()) {
        Tag persistedTag = iter.next();//www. j av  a  2s.c o m
        if (persistedTag.getUsername().equals(tagUser) && persistedTag.getTag().equals(tag)) {
            iter.remove();
        }
    }
}

From source file:com.replaymod.replaystudio.studio.StudioReplayPart.java

@Override
public Collection<PacketData> remove(long from, long to) {
    List<PacketData> removed = new LinkedList<>();
    Iterator<PacketData> iter = iterator();
    while (iter.hasNext()) {
        PacketData data = iter.next();//from   w ww.java 2  s  . co m
        if (data.getTime() >= from) {
            iter.remove();
            removed.add(data);
        }
        if (data.getTime() > to) {
            // Packets are ordered by time therefore we can stop here
            break;
        }
    }
    return removed;
}

From source file:com.avanza.ymer.FakeDocumentCollection.java

private void removeByTemplate(BasicDBObject dbObject) {
    Iterator<DBObject> it = collection.iterator();
    while (it.hasNext()) {
        DBObject next = it.next();// ww  w. ja  v a 2 s. c o  m
        if (next.equals(dbObject)) {
            it.remove();
            return;
        }
    }
}

From source file:it.crs4.most.ehrlib.parser.AdlParser.java

/**
 * Gets the paths array./*from  w ww . ja v  a2  s  . c  o  m*/
 *
 * @param path the path
 * @return the paths array
 */
private String[] getPathsArray(String path) {
    ArrayList<String> pathsA = new ArrayList<String>(Arrays.asList(path.split("[\\[\\]/]")));

    Iterator<String> iter = pathsA.iterator();
    while (iter.hasNext()) {
        if (iter.next().equalsIgnoreCase(""))
            iter.remove();
    }
    return pathsA.toArray(new String[0]);
}

From source file:CacheMap.java

private void evict() {
    Iterator<Object> it = accessList.iterator();
    for (int i = 0; i < evictSize; i++) {
        if (!it.hasNext())
            return;
        Object key = it.next();//from  www .j  a v a 2s .c om
        this.remove(key);
        it.remove();
    }
}

From source file:com.hortonworks.streamline.streams.common.StreamlineEventImplTest.java

@Test(expected = UnsupportedOperationException.class)
public void testRemoveIterator() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("foo", "bar");

    StreamlineEvent event = new StreamlineEventImpl(map, StringUtils.EMPTY);
    Iterator<Map.Entry<String, Object>> it = event.entrySet().iterator();
    while (it.hasNext()) {
        it.next();//from w  w w .ja v a 2  s.  c  om
        it.remove();
    }
}

From source file:eg.agrimarket.controller.ProductController.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String productName = request.getParameter("product_Name");
    List<Product> products = (List<Product>) request.getServletContext().getAttribute("products");
    if (products != null) {
        Iterator<Product> iterator = products.iterator();
        while (iterator.hasNext()) {
            if (iterator.next().getName().equals(productName)) {
                iterator.remove();
            }//from  w  w w .ja  va 2s.co m
        }

        request.getServletContext().setAttribute("products", products);

    }
    ProductDao dao = new ProductDaoImp();
    dao.removeProduct(productName);
    response.sendRedirect("http://" + request.getServerName() + ":" + request.getServerPort()
            + "/AgriMarket/admin/getProducts?#product-div");

}

From source file:cc.kune.core.server.manager.impl.SocialNetworkCache.java

/**
 * Gets the SN of some user/group from the cache if available.
 * /*from  w  w w.j  av a2 s . c o m*/
 * @param user
 *          the user
 * @param group
 *          the group
 * @return the social network data
 */
public SocialNetworkData get(final User user, final Group group) {
    final Pair<User, Group> pair = Pair.create(user, group);
    if (expiredGroups.contains(group)) {
        // TODO Do this in a cron job
        final Iterator<Pair<User, Group>> iterator = super.keySet().iterator();
        while (iterator.hasNext()) {
            if (iterator.next().right.equals(group)) {
                iterator.remove();
            }
        }
        expiredGroups.remove(group);
        LOG.debug("Not returning expired SN info");
        return null;
    }
    return super.get(pair);
}

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

@Override
public void clearTasks(Integer siteId) {
    Assert.notNull(siteId, "Site id is null");
    Iterator<Taskable> iterator = tasks.iterator();
    for (Taskable t = iterator.next(); iterator.hasNext(); t = iterator.next()) {
        if (siteId.intValue() == t.getSite().getId().intValue()) {
            iterator.remove();
        }/*from  www  . ja v a2  s.c o m*/
    }
}