Example usage for java.util HashMap putAll

List of usage examples for java.util HashMap putAll

Introduction

In this page you can find the example usage for java.util HashMap putAll.

Prototype

public void putAll(Map<? extends K, ? extends V> m) 

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:org.apache.myfaces.webapp.filter.MultipartRequestWrapper.java

public Map getParameterMap() {
    if (parametersMap == null)
        parseRequest();//from www .j a v  a2 s  .c om

    //return parametersMap;
    HashMap mergedMap = new HashMap(request.getParameterMap());
    mergedMap.putAll(parametersMap);
    return mergedMap;
}

From source file:org.opentestsystem.shared.monitoringalerting.service.AlertServiceTest.java

@Test
public void testPagingFeatures() {
    HashMap<String, Alert> page1Map = new HashMap<String, Alert>();
    HashMap<String, Alert> page2Map = new HashMap<String, Alert>();
    HashMap<String, Alert> page3Map = new HashMap<String, Alert>();
    HashMap<String, Alert> page4Map = new HashMap<String, Alert>();

    createAlerts(10, ALERT_TYPE, COOL);/*from  w ww .  ja va 2  s .c  om*/
    createAlerts(10, ALERT_TYPE, "uncool");

    Map<String, String[]> requestMap = new HashMap<String, String[]>();
    requestMap.put(PAGE_SIZE, new String[] { "3" });
    requestMap.put(CURRENT_PAGE, new String[] { "0" });
    requestMap.put(SORT_DIR, new String[] { ASC });
    requestMap.put(SORT_KEY, new String[] { SERVER });

    requestMap.put(ALERT_TYPE, new String[] { COOL });

    AlertSearchRequest searchRequest = new AlertSearchRequest(requestMap);

    SearchResponse<Alert> response = alertService.searchAlerts(searchRequest);

    assertEquals(WRONG_RESP_COUNT, 3, response.getReturnCount());
    assertEquals(WRONG_RESULTS_COUNT, 3, response.getSearchResults().size());

    for (Alert result : response.getSearchResults()) {
        page1Map.put(result.getId(), result);
    }

    requestMap.put(CURRENT_PAGE, new String[] { "1" });
    searchRequest = new AlertSearchRequest(requestMap);
    response = alertService.searchAlerts(searchRequest);
    assertEquals(WRONG_RESP_COUNT, 3, response.getReturnCount());
    assertEquals(WRONG_RESULTS_COUNT, 3, response.getSearchResults().size());

    for (Alert result : response.getSearchResults()) {
        page2Map.put(result.getId(), result);
    }

    requestMap.put(CURRENT_PAGE, new String[] { "2" });
    searchRequest = new AlertSearchRequest(requestMap);
    response = alertService.searchAlerts(searchRequest);
    assertEquals(WRONG_RESP_COUNT, 3, response.getReturnCount());
    assertEquals(WRONG_RESULTS_COUNT, 3, response.getSearchResults().size());

    for (Alert result : response.getSearchResults()) {
        page3Map.put(result.getId(), result);
    }

    requestMap.put(CURRENT_PAGE, new String[] { "3" });
    searchRequest = new AlertSearchRequest(requestMap);
    response = alertService.searchAlerts(searchRequest);
    assertEquals(WRONG_RESP_COUNT, 1, response.getReturnCount());
    assertEquals(WRONG_RESULTS_COUNT, 1, response.getSearchResults().size());

    for (Alert result : response.getSearchResults()) {
        page4Map.put(result.getId(), result);
    }

    requestMap.put(CURRENT_PAGE, new String[] { "4" });
    searchRequest = new AlertSearchRequest(requestMap);
    response = alertService.searchAlerts(searchRequest);
    assertEquals(WRONG_RESP_COUNT, 0, response.getReturnCount());
    assertEquals(WRONG_RESULTS_COUNT, 0, response.getSearchResults().size());

    requestMap.put(CURRENT_PAGE, new String[] { "90000" });
    searchRequest = new AlertSearchRequest(requestMap);
    response = alertService.searchAlerts(searchRequest);
    assertEquals(WRONG_RESP_COUNT, 0, response.getReturnCount());
    assertEquals(WRONG_RESULTS_COUNT, 0, response.getSearchResults().size());

    HashMap<String, Alert> allAlerts = new HashMap<String, Alert>();
    allAlerts.putAll(page1Map);
    allAlerts.putAll(page2Map);
    allAlerts.putAll(page3Map);
    allAlerts.putAll(page4Map);
    assertEquals("should be 10 unique items", 10, allAlerts.size());
}

From source file:org.apache.geode.geospatial.utils.CachingPutAllMap.java

@Override
public Collection values() {
    readLock.lock();/* w  ww  .jav a2s  .c o m*/
    try {
        HashMap map = new HashMap(wrappedMap);
        map.putAll(bulkMap);
        return map.values();
    } finally {
        readLock.unlock();
    }
}

From source file:org.apache.geode.geospatial.utils.CachingPutAllMap.java

@Override
public Set<Entry> entrySet() {
    readLock.lock();/*w  w w.ja  va2 s.c o  m*/
    try {
        HashMap map = new HashMap(wrappedMap);
        map.putAll(bulkMap);
        return map.entrySet();
    } finally {
        readLock.unlock();
    }
}

From source file:com.enonic.cms.domain.user.field.UserFieldTransformer.java

public Map<String, String> toStoreableMap(UserFieldMap fields) {
    HashMap<String, String> result = new HashMap<String, String>();
    for (UserField field : fields) {
        if (!field.isOfType(UserFieldType.ADDRESS) && !field.isOfType(UserFieldType.PHOTO)) {
            addSimpleField(result, field);
        }//  w  w w.j a  v  a  2 s. co  m
    }

    result.putAll(this.addressTransformer.toStoreableMap(fields));
    return result;
}

From source file:common.net.volley.toolbox.HurlStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();

    stethoManager = new StethoURLConnectionManager(url);

    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);/* w w  w .java 2s  . com*/
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    requestDecompression(connection);

    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }

    setConnectionParametersForRequest(connection, request);

    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());

    stethoManager.postConnect();

    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }

    return response;
}

From source file:org.craftercms.cstudio.publishing.processor.ShellProcessor.java

protected HashMap<String, String> buildArgumentsMap(List<String> files) {
    HashMap<String, String> result = new HashMap<String, String>();
    if (arguments != null) {
        result.putAll(arguments);
    }/*from  w w  w .  ja v a 2 s .  c  om*/
    String filter = result.get(INCLUDE_FILTER_PARAM);
    if (filter != null) {
        List<String> filterFiles = new ArrayList<String>();
        Pattern patter = Pattern.compile(filter);
        for (String file : files) {
            if (patter.matcher(file).matches()) {
                LOGGER.debug("File " + file + " Match " + filter);
                filterFiles.add(file);
            } else {
                LOGGER.debug("File Don't " + file + " don't match " + filter);
            }
        }
        result.put(INCLUDE_FILES_ARG, StringUtils.join(filterFiles, " "));
    }
    return result;
}

From source file:pl.otros.logview.exceptionshandler.ShowErrorDialogExceptionHandler.java

public Map<String, String> generateReportData(Thread thread, Throwable throwable,
        OtrosApplication otrosApplication) {
    ErrorReportCollectingContext ctx = new ErrorReportCollectingContext();
    ctx.setThread(thread);/*w  ww  . ja v  a 2s .  c o m*/
    ctx.setThrowable(throwable);
    ctx.setOtrosApplication(otrosApplication);
    ArrayList<ErrorReportDataCollector> collectors = new ArrayList<ErrorReportDataCollector>();
    collectors.add(new RuntimeInfoERDC());
    collectors.add(new SystemPropertiesERDC());
    collectors.add(new DesktopERDC());
    collectors.add(new ExceptionERDC());
    collectors.add(new OtrosAppERDC());
    collectors.add(new UuidERDC());

    HashMap<String, String> map = new HashMap<String, String>();
    for (ErrorReportDataCollector errorReportDataCollector : collectors) {
        try {
            map.putAll(errorReportDataCollector.collect(ctx));
        } catch (Throwable t) {
            LOGGER.log(Level.SEVERE, "Error during collecting diagnostic data", t);
        }
    }
    return map;
}

From source file:com.vincestyling.netroid.stack.HurlStack.java

@Override
public HttpResponse performRequest(Request<?> request) throws IOException, AuthFailureError {
    HashMap<String, String> map = new HashMap<String, String>();
    if (!TextUtils.isEmpty(mUserAgent)) {
        map.put(HTTP.USER_AGENT, mUserAgent);
    }//  www .  j  a  v a  2s .  co  m
    map.putAll(request.getHeaders());

    URL parsedUrl = new URL(request.getUrl());
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }

    setConnectionParametersForRequest(connection, request);

    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }

    StatusLine responseStatus = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1),
            connection.getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
        response.setEntity(entityFromConnection(connection));
    }

    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }

    return response;
}

From source file:com.predic8.membrane.core.interceptor.javascript.JavascriptInterceptor.java

private Outcome runScript(Exchange exc, Flow flow)
        throws InterruptedException, IOException, ClassNotFoundException {
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("exc", exc);
    parameters.put("flow", flow);
    parameters.put("spring", router.getBeanFactory());
    addOutcomeObjects(parameters);/* www  .  j ava  2s.c  o  m*/

    parameters.putAll(implicitClasses);
    Object res = script.apply(parameters);

    if (res instanceof Outcome) {
        return (Outcome) res;
    }

    if (res instanceof Response) {
        exc.setResponse((Response) res);
        return Outcome.RETURN;
    }

    if (res instanceof Request) {
        exc.setRequest((Request) res);
    }
    return Outcome.CONTINUE;

}