Example usage for java.util List clear

List of usage examples for java.util List clear

Introduction

In this page you can find the example usage for java.util List clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this list (optional operation).

Usage

From source file:com.gargoylesoftware.htmlunit.CacheTest.java

/**
 *@throws Exception if the test fails/*from   ww w.ja v a 2  s .c o m*/
 */
@Test
public void usage() throws Exception {
    final String content = "<html><head><title>page 1</title>\n" + "<script src='foo1.js'></script>\n"
            + "<script src='foo2.js'></script>\n" + "</head><body>\n" + "<a href='page2.html'>to page 2</a>\n"
            + "</body></html>";

    final String content2 = "<html><head><title>page 2</title>\n" + "<script src='foo2.js'></script>\n"
            + "</head><body>\n" + "<a href='page1.html'>to page 1</a>\n" + "</body></html>";

    final String script1 = "alert('in foo1');";
    final String script2 = "alert('in foo2');";

    final WebClient webClient = getWebClient();
    final MockWebConnection connection = new MockWebConnection();
    webClient.setWebConnection(connection);

    final URL urlPage1 = new URL(URL_FIRST, "page1.html");
    connection.setResponse(urlPage1, content);
    final URL urlPage2 = new URL(URL_FIRST, "page2.html");
    connection.setResponse(urlPage2, content2);

    final List<NameValuePair> headers = new ArrayList<>();
    headers.add(new NameValuePair("Last-Modified", "Sun, 15 Jul 2007 20:46:27 GMT"));
    connection.setResponse(new URL(URL_FIRST, "foo1.js"), script1, 200, "ok", JAVASCRIPT_MIME_TYPE, headers);
    connection.setResponse(new URL(URL_FIRST, "foo2.js"), script2, 200, "ok", JAVASCRIPT_MIME_TYPE, headers);

    final List<String> collectedAlerts = new ArrayList<>();
    webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts));

    final HtmlPage page1 = webClient.getPage(urlPage1);
    final String[] expectedAlerts = { "in foo1", "in foo2" };
    assertEquals(expectedAlerts, collectedAlerts);

    collectedAlerts.clear();
    page1.getAnchors().get(0).click();

    assertEquals(new String[] { "in foo2" }, collectedAlerts);
    assertEquals("no request for scripts should have been performed", urlPage2,
            connection.getLastWebRequest().getUrl());
}

From source file:com.gargoylesoftware.htmlunit.CacheTest.java

/**
 *@throws Exception if the test fails/*w  w w  .j av a  2 s. c om*/
 */
@Test
public void jsUrlEncoded() throws Exception {
    final String content = "<html>\n" + "<head>\n" + "  <title>page 1</title>\n"
            + "  <script src='foo1.js'></script>\n" + "  <script src='foo2.js?foo[1]=bar/baz'></script>\n"
            + "</head>\n" + "<body>\n" + "  <a href='page2.html'>to page 2</a>\n" + "</body>\n" + "</html>";

    final String content2 = "<html>\n" + "<head>\n" + "  <title>page 2</title>\n"
            + "  <script src='foo2.js?foo[1]=bar/baz'></script>\n" + "</head>\n" + "<body>\n"
            + "  <a href='page1.html'>to page 1</a>\n" + "</body>\n" + "</html>";

    final String script1 = "alert('in foo1');";
    final String script2 = "alert('in foo2');";

    final URL urlPage1 = new URL(URL_FIRST, "page1.html");
    getMockWebConnection().setResponse(urlPage1, content);
    final URL urlPage2 = new URL(URL_FIRST, "page2.html");
    getMockWebConnection().setResponse(urlPage2, content2);

    final List<NameValuePair> headers = new ArrayList<>();
    headers.add(new NameValuePair("Last-Modified", "Sun, 15 Jul 2007 20:46:27 GMT"));
    getMockWebConnection().setResponse(new URL(URL_FIRST, "foo1.js"), script1, 200, "ok", JAVASCRIPT_MIME_TYPE,
            headers);
    getMockWebConnection().setDefaultResponse(script2, 200, "ok", JAVASCRIPT_MIME_TYPE, headers);

    final WebClient webClient = getWebClientWithMockWebConnection();

    final List<String> collectedAlerts = new ArrayList<>();
    webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts));

    final HtmlPage page1 = webClient.getPage(urlPage1);
    final String[] expectedAlerts = { "in foo1", "in foo2" };
    assertEquals(expectedAlerts, collectedAlerts);

    collectedAlerts.clear();
    page1.getAnchors().get(0).click();

    assertEquals(new String[] { "in foo2" }, collectedAlerts);
    assertEquals("no request for scripts should have been performed", urlPage2,
            getMockWebConnection().getLastWebRequest().getUrl());
}

From source file:com.saasovation.common.port.adapter.persistence.eventsourcing.mysql.MySQLJDBCEventStoreTest.java

public void testFullEventStreamForStreamName() throws Exception {
    assertNotNull(this.eventStore);

    List<DomainEvent> events = new ArrayList<DomainEvent>();

    for (int idx = 1; idx <= 3; ++idx) {
        events.add(new TestableDomainEvent(idx, "Name: " + idx));
    }//from w  w w.  ja  v a  2s .c  om

    EventStreamId eventId = new EventStreamId(UUID.randomUUID().toString());

    this.eventStore.appendWith(eventId, events);

    EventStream eventStream = this.eventStore.fullEventStreamFor(eventId);

    assertEquals(3, eventStream.version());
    assertEquals(3, eventStream.events().size());

    events.clear();
    events.add(new TestableDomainEvent(4, "Name: " + 4));

    this.eventStore.appendWith(eventId.withStreamVersion(4), events);

    eventStream = this.eventStore.fullEventStreamFor(eventId);

    assertEquals(4, eventStream.version());
    assertEquals(4, eventStream.events().size());

    for (int idx = 1; idx <= 4; ++idx) {
        DomainEvent domainEvent = eventStream.events().get(idx - 1);

        assertEquals(idx, ((TestableDomainEvent) domainEvent).id());
    }
}

From source file:edu.duke.cabig.c3pr.infrastructure.interceptor.NotificationInterceptor.java

/**
* Removes the duplicate occurrences of any sites that may result in emails being sent out twice.
* 
* @param hcsList the hcs list/*from   ww  w.j ava 2 s  .com*/
*/
private void removeDuplicates(List<HealthcareSite> hcsList) {
    Set<HealthcareSite> set = new HashSet<HealthcareSite>();
    set.addAll(hcsList);
    hcsList.clear();
    hcsList.addAll(set);
}

From source file:com.saasovation.common.port.adapter.persistence.eventsourcing.mysql.MySQLJDBCEventStoreTest.java

public void testAppendWrongVersion() throws Exception {
    assertNotNull(this.eventStore);

    List<DomainEvent> events = new ArrayList<DomainEvent>();

    for (int idx = 1; idx <= 10; ++idx) {
        events.add(new TestableDomainEvent(idx, "Name: " + idx));
    }//from w ww  .  j a va  2 s  . c  om

    EventStreamId eventId = new EventStreamId(UUID.randomUUID().toString());

    this.eventStore.appendWith(eventId, events);

    EventStream eventStream = this.eventStore.fullEventStreamFor(eventId);

    assertEquals(10, eventStream.version());
    assertEquals(10, eventStream.events().size());

    events.clear();
    events.add(new TestableDomainEvent(11, "Name: " + 11));

    for (int idx = 0; idx < 3; ++idx) {
        try {
            this.eventStore.appendWith(eventId.withStreamVersion(8 + idx), events);

            fail("Should have thrown an exception.");

        } catch (EventStoreAppendException e) {
            // good
        }
    }

    // this should succeed

    this.eventStore.appendWith(eventId.withStreamVersion(11), events);
}

From source file:com.clustercontrol.jobmanagement.composite.WaitRuleComposite.java

/**
 * ??????????//from   w w w .j  a  v a  2  s  .  c  o m
 *
 * @return ??
 *
 * @see com.clustercontrol.jobmanagement.bean.JobWaitRuleInfo
 */
public ValidateResult createWaitRuleInfo() {
    m_log.debug("createWaitRuleInfo");
    ValidateResult result = null;

    //???
    ArrayList<JobObjectInfo> list = new ArrayList<JobObjectInfo>();
    ArrayList<?> tableData = (ArrayList<?>) m_viewer.getInput();
    HashMap<String, Integer> map = new HashMap<String, Integer>();

    for (int i = 0; i < tableData.size(); i++) {
        ArrayList<?> tableLineData = (ArrayList<?>) tableData.get(i);
        JobObjectInfo info = array2JobObjectInfo(tableLineData);
        // ????????
        if (info.getType() == JudgmentObjectConstant.TYPE_JOB_END_STATUS) {
            Integer checkValue = map.get(info.getJobId() + info.getType());
            if (checkValue == null || !checkValue.equals(info.getValue())) {
                list.add(info);
                map.put(info.getJobId() + info.getType(), info.getValue());
            }
        } else if (info.getType() == JudgmentObjectConstant.TYPE_JOB_END_VALUE) {
            Integer checkValue = map.get(info.getJobId() + info.getType());
            if (checkValue == null || checkValue.equals(info.getValue())) {
                list.add(info);
                map.put(info.getJobId() + info.getType(), info.getValue());
            }
        } else if (info.getType() == JudgmentObjectConstant.TYPE_TIME) {
            if (map.get("TIME") == null) {
                list.add(info);
                map.put("TIME", 1);
            }
        } else if (info.getType() == JudgmentObjectConstant.TYPE_START_MINUTE) {
            m_log.debug("info.getType=" + info.getType());
            m_log.debug("info.getStartMinute=" + info.getStartMinute());
            if (map.get(info.getType().toString()) == null) {
                list.add(info);
                map.put(info.getType().toString(), info.getValue());
            }
        } else if (info.getType() == JudgmentObjectConstant.TYPE_JOB_PARAMETER) {
            Integer checkValue = map.get(info.getType() + info.getDecisionValue01()
                    + info.getDecisionCondition() + info.getDecisionValue02());
            if (checkValue == null || !checkValue.equals(info.getValue())) {
                list.add(info);
                map.put(info.getType() + info.getDecisionValue01() + info.getDecisionCondition()
                        + info.getDecisionValue02(), info.getValue());
            }
        }
    }
    List<JobObjectInfo> jobObjectInfoList = m_waitRule.getObject();
    jobObjectInfoList.clear();
    jobObjectInfoList.addAll(list);

    //??
    if (m_andCondition.getSelection()) {
        m_waitRule.setCondition(ConditionTypeConstant.TYPE_AND);
    } else {
        m_waitRule.setCondition(ConditionTypeConstant.TYPE_OR);
    }

    //???????? 
    m_waitRule.setEndCondition(m_endCondition.getSelection());

    //?
    try {
        m_waitRule.setEndStatus(getSelectEndStatus(m_endStatus));
        m_waitRule.setEndValue(Integer.parseInt(m_endValue.getText()));
    } catch (NumberFormatException e) {
        if (m_waitRule.isEndCondition().booleanValue()) {
            result = new ValidateResult();
            result.setValid(false);
            result.setID(Messages.getString("message.hinemos.1"));
            result.setMessage(Messages.getString("message.job.21"));
            return result;
        }
    }

    return null;
}

From source file:cn.com.inhand.devicenetworks.ap.websocket.WSDNAccessPoint.java

/**
 * ?Inboxlogout//  w w w  . jav a 2 s. c  o  m
 *
 * @param logout
 */
private void onUnkownMsg(DNMessage msg, WebSocketSession session, WSDNSession wsdnsn)
        throws IOException, PacketException {
    List list = new ArrayList();
    list.add(new Parameter("result", "23009"));
    list.add(new Parameter("reason", "" + wsdnsn.getAssetid() + "@" + wsdnsn.getLast_msg()));
    DNMessage ack = new DNMessage(msg.getName(), "response", msg.getTxid(), list);
    session.sendMessage(new TextMessage(new String(parser.wrap(ack))));
    list.clear();
    wsdnsn.setSession(session);
    wsdnsn.setLast_msg(System.currentTimeMillis());
}

From source file:ar.com.zauber.commons.dao.closure.SwitchClosureTest.java

/** test */
@Test/*  ww w .  j a  v  a  2s  . co  m*/
public final void testname() throws Exception {
    final List<Entry<Predicate<String>, Closure<String>>> blocks = new LinkedList<Entry<Predicate<String>, Closure<String>>>();

    final Predicate<String> never = new FalsePredicate<String>();
    final Predicate<String> always = new TruePredicate<String>();

    final List<String> l = new LinkedList<String>();
    final Closure<String> putInList = new Closure<String>() {
        public void execute(final String t) {
            l.add(t);
        }
    };

    blocks.add(new PredicateClosureEntry<String>(never, new AssertFalseClosure<String>("no debe entrar aca")));
    blocks.add(new PredicateClosureEntry<String>(new EqualsPredicate("foo"), putInList));
    blocks.add(new PredicateClosureEntry<String>(always, new AssertFalseClosure<String>("default block")));

    final Closure<String> s = new SwitchClosure<String>(blocks);
    s.execute("foo");
    Assert.assertEquals("foo", l.get(0));
    l.clear();
    try {
        s.execute("bar");
        Assert.fail("shouldnt reach this point");
    } catch (final AssertionError e) {
        Assert.assertEquals("default block", e.getMessage());
    }

}

From source file:cn.com.inhand.devicenetworks.ap.websocket.WSDNAccessPoint.java

/**
 * ?Inbox/*  w ww .ja  v a 2 s  .  c  o  m*/
 *
 * @param heartBeat
 */
private void onHeartbeat(DNMessage heartbeat, WebSocketSession session, WSDNSession wsdnsn)
        throws IOException, PacketException {

    List list = new ArrayList();
    list.add(new Parameter("result", "0"));
    list.add(new Parameter("reason", "" + wsdnsn.getAssetid() + "@" + wsdnsn.getLast_msg()));
    DNMessage ack = new DNMessage("heartbeat", "response", heartbeat.getTxid(), list);
    session.sendMessage(new TextMessage(new String(parser.wrap(ack))));
    list.clear();
    wsdnsn.setSession(session);
    wsdnsn.setLast_msg(System.currentTimeMillis());
    wsdnsn.setAction(2);
    this.updateStatus(2, wsdnsn);
}

From source file:com.octanner.controllers.AbstractProductConfigController.java

protected void removeNullCsticsFromGroup(final List<CsticData> dirtyList) {
    if (dirtyList == null) {
        return;/*  w w w  . j  a  v a 2s  . c  om*/
    }

    final List<CsticData> cleanList = new ArrayList<>(dirtyList.size());

    for (final CsticData data : dirtyList) {
        if (data.getName() != null && data.getType() != UiType.READ_ONLY) {
            cleanList.add(data);
        }
    }

    dirtyList.clear();
    dirtyList.addAll(cleanList);

}