Example usage for java.util Collections synchronizedList

List of usage examples for java.util Collections synchronizedList

Introduction

In this page you can find the example usage for java.util Collections synchronizedList.

Prototype

public static <T> List<T> synchronizedList(List<T> list) 

Source Link

Document

Returns a synchronized (thread-safe) list backed by the specified list.

Usage

From source file:org.syncope.core.persistence.dao.impl.UserSearchDAOImpl.java

@Override
public int count(final Set<Long> adminRoles, final NodeCond searchCondition) {

    List<Object> parameters = Collections.synchronizedList(new ArrayList<Object>());

    // 1. get the query string from the search condition
    StringBuilder queryString = getQuery(searchCondition, parameters);

    // 2. take into account administrative roles
    queryString.insert(0, "SELECT u.user_id FROM (");
    queryString.append(") u WHERE user_id NOT IN (");
    queryString.append(getAdminRolesFilter(adminRoles)).append(")");

    // 3. prepare the COUNT query
    queryString.insert(0, "SELECT COUNT(user_id) FROM (");
    queryString.append(") count_user_id");

    Query countQuery = entityManager.createNativeQuery(queryString.toString());
    fillWithParameters(countQuery, parameters);

    LOG.debug("Native count query\n{}\nwith parameters\n{}", queryString.toString(), parameters);

    int result = ((Number) countQuery.getSingleResult()).intValue();
    LOG.debug("Native count query result: {}", result);

    return result;
}

From source file:org.opennms.sms.monitor.internal.config.SequenceSessionVariable.java

/**
 * <p>addParameter</p>// www .  j  a  va2s.  c o m
 *
 * @param key a {@link java.lang.String} object.
 * @param value a {@link java.lang.String} object.
 */
public void addParameter(String key, String value) {
    if (m_parameters == null) {
        m_parameters = Collections.synchronizedList(new ArrayList<SequenceParameter>());
    }
    m_parameters.add(new SequenceParameter(key, value));
}

From source file:mitm.application.djigzo.james.smtpserver.CheckRepositoriesBlockingRcptCmdHandler.java

@Override
public void configure(Configuration handlerConfiguration) throws ConfigurationException {
    logger.info("Configuring CommandHandler");

    Configuration[] repositoryConfigs = handlerConfiguration.getChild("repositories").getChildren("repository");

    repositories = Collections.synchronizedList(new ArrayList<String>(repositoryConfigs.length));

    for (Configuration repositoryConfig : repositoryConfigs) {
        repositories.add(repositoryConfig.getValue());
    }// ww w  .ja v  a2 s  . c  o  m

    Configuration config = handlerConfiguration.getChild("rejectCode", false);

    if (config != null) {
        rejectCode = config.getValue("452");
    }

    config = handlerConfiguration.getChild("repositoryUpperLimit", false);

    if (config != null) {
        repositoryUpperLimit = config.getValueAsInteger(1000);
    }

    config = handlerConfiguration.getChild("repositoryLowerLimit", false);

    if (config != null) {
        repositoryLowerLimit = config.getValueAsInteger(500);
    }

    config = handlerConfiguration.getChild("checkInterval", false);

    if (config != null) {
        checkInterval = config.getValueAsLong(60000);
    }

    StrBuilder sb = new StrBuilder();

    sb.append("Repositories: ");
    sb.appendWithSeparators(repositories, ", ");
    sb.appendSeparator("; ");
    sb.append("rejectCode: ");
    sb.append(rejectCode);
    sb.appendSeparator("; ");
    sb.append("repositoryUpperLimit: ");
    sb.append(repositoryUpperLimit);
    sb.appendSeparator("; ");
    sb.append("repositoryLowerLimit: ");
    sb.append(repositoryLowerLimit);
    sb.appendSeparator("; ");
    sb.append("checkInterval: ");
    sb.append(checkInterval);

    logger.info(sb.toString());
}

From source file:org.lightjason.agentspeak.beliefbase.TestCViewMap.java

/**
 * initialize//from   w w  w.  j ava 2 s  .  co  m
 *
 * @throws IOException is thrown on parsing error
 */
@Before
@SuppressWarnings("unchecked")
public final void initialize() throws IOException {
    m_testlog = Collections.synchronizedList(new ArrayList<>());
    m_data = new ObjectMapper().readValue(
            "{ \"val\" : 123, \"str\" : \"text value\", \"logic\" : true, \"obj\" : { \"name\" : \"abcdef\", \"val\" : 357 }, \"ar\" : [1, 3, 5] }",
            Map.class);
}

From source file:HttpDownloadManager.java

public HttpDownloadManager(Logger log) throws IOException {
    if (log == null)
        log = Logger.getLogger(this.getClass().getName());
    this.log = log;
    selector = Selector.open(); // create Selector
    buffer = ByteBuffer.allocateDirect(64 * 1024); // allocate buffer
    pendingDownloads = Collections.synchronizedList(new ArrayList());
    this.start(); // start thread
}

From source file:org.inwiss.platform.common.util.ConvertUtil.java

/**
 * Converts string to list. The string is assumed to be a sequence of some
  * elements separated with delimiter.//w  ww . j  av a 2 s .  c o  m
 *
 * @param string    String to convert to list
 * @param delimiter Delimiter of list elements
 * @param trim      Whether or not to trim tokens befor putting them in list
 * @return List
 */
public static List convertStringToList(String string, String delimiter, boolean trim) {
    if (string == null || string.length() == 0) {
        return new LinkedList();
    }
    String[] members = string.split(delimiter);
    List list = Collections.synchronizedList(new LinkedList());
    for (int i = 0; i < members.length; i++) {
        String member = members[i];
        if (trim) {
            member = member.trim();
        }
        list.add(member);
    }
    return list;
}

From source file:org.springframework.ide.eclipse.boot.wizard.DefaultDependencies.java

/**
 * Finds check-box models from the selection model corresponding to stored default dependencies (ids)
 * /*from w ww .j a  v  a 2  s . com*/
 * @param model dependency selection model
 * @return check-box models of stored default dependencies
 */
public List<CheckBoxModel<Dependency>> getDependencies(HierarchicalMultiSelectionFieldModel<Dependency> model) {
    Set<String> ids = getDependciesIdSet();
    List<CheckBoxModel<Dependency>> dependencies = Collections.synchronizedList(new ArrayList<>(ids.size()));
    model.getCategories().parallelStream().forEach(category -> {
        model.getContents(category).getCheckBoxModels().stream().filter(checkboxModel -> {
            return ids.contains(checkboxModel.getValue().getId());
        }).forEach(dependencies::add);
    });
    return dependencies;
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest3Test.java

/**
 * Tests asynchronous use of XMLHttpRequest, using Mozilla style object creation.
 * @throws Exception if the test fails/*from   www. j  a va  2  s . com*/
 */
@Test
@Alerts(DEFAULT = { "0", "1", "1", "2", "3", "4" }, FF = { "0", "1", "2", "3", "4" })
@NotYetImplemented(CHROME)
public void asyncUse() throws Exception {
    final String html = "<html>\n" + "  <head>\n" + "    <title>XMLHttpRequest Test</title>\n"
            + "    <script>\n" + "      var request;\n" + "      function testAsync() {\n"
            + "        request = " + XMLHttpRequest2Test.XHRInstantiation_ + ";\n"
            + "        request.onreadystatechange = onReadyStateChange;\n"
            + "        alert(request.readyState);\n" + "        request.open('GET', '" + URL_SECOND
            + "', true);\n" + "        request.send('');\n" + "      }\n"
            + "      function onReadyStateChange() {\n" + "        alert(request.readyState);\n"
            + "        if (request.readyState == 4)\n" + "          alert(request.responseText);\n"
            + "      }\n" + "    </script>\n" + "  </head>\n" + "  <body onload='testAsync()'>\n"
            + "  </body>\n" + "</html>";

    final String xml = "<xml2>\n" + "<content2>sdgxsdgx</content2>\n" + "<content2>sdgxsdgx2</content2>\n"
            + "</xml2>";

    final WebClient client = getWebClient();
    final List<String> collectedAlerts = Collections.synchronizedList(new ArrayList<String>());
    client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
    final MockWebConnection conn = new MockWebConnection();
    conn.setResponse(URL_FIRST, html);
    conn.setResponse(URL_SECOND, xml, "text/xml");
    client.setWebConnection(conn);
    client.getPage(URL_FIRST);

    assertEquals(0, client.waitForBackgroundJavaScriptStartingBefore(1000));
    assertEquals(ArrayUtils.add(getExpectedAlerts(), xml), collectedAlerts);
}

From source file:org.alfresco.mobile.android.application.fragments.node.browser.NodeAdapter.java

public NodeAdapter(Fragment fr, int textViewResourceId, List<Node> listItems, List<Node> selectedItems,
        int mode) {
    super(fr.getActivity(), textViewResourceId, listItems);
    this.fragmentRef = new WeakReference<>(fr);
    originalNodes = Collections.synchronizedList(listItems);
    this.selectedItems = selectedItems;
    this.renditionManager = RenditionManagerImpl.getInstance(fr.getActivity());
    this.mode = mode;
    this.vhClassName = TwoLinesProgressViewHolder.class.getCanonicalName();
    this.activityRef = new WeakReference<>(fr.getActivity());
    this.gridFragment = (BaseGridFragment) fr;
}

From source file:com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerTest.java

/**
 * @throws Exception if the test fails/*from w  ww.j a va2s. c  om*/
 */
@Test
public void setClearIntervalUsesManager() throws Exception {
    final String content = "<html>\n" + "<head>\n" + "  <title>test</title>\n" + "  <script>\n"
            + "    var threadID;\n" + "    function test() {\n"
            + "      threadID = setInterval(doAlert, 100);\n" + "    }\n" + "    var iterationNumber=0;\n"
            + "    function doAlert() {\n" + "      alert('blah');\n" + "      if (++iterationNumber >= 3) {\n"
            + "        clearInterval(threadID);\n" + "      }\n" + "    }\n" + "  </script>\n" + "</head>\n"
            + "<body onload='test()'>\n" + "</body>\n" + "</html>";

    final List<String> collectedAlerts = Collections.synchronizedList(new ArrayList<String>());
    startTimedTest();
    final HtmlPage page = loadPage(content, collectedAlerts);
    final JavaScriptJobManager jobManager = page.getEnclosingWindow().getJobManager();
    assertNotNull(jobManager);
    assertEquals(1, jobManager.getJobCount());
    jobManager.waitForJobs(1000);
    assertEquals(0, jobManager.getJobCount());
    assertEquals(Collections.nCopies(3, "blah"), collectedAlerts);
    assertMaxTestRunTime(1000);
}