List of usage examples for java.util HashMap putAll
public void putAll(Map<? extends K, ? extends V> m)
From source file:org.eclipse.smila.connectivity.framework.impl.AgentControllerImpl.java
/** * {@inheritDoc}//from w ww . j a v a2 s . c o m * * @see org.eclipse.smila.connectivity.framework.AgentController#getAgentTasksState() */ @Override public Map<String, AgentState> getAgentTasksState() { final HashMap<String, AgentState> states = new HashMap<String, AgentState>(); states.putAll(_agentStates); return states; }
From source file:com.github.haixing_hu.bean.DefaultProperty.java
@Override public final void setMappedValue(final HashMap<String, Object> map) { checkKind(PropertyKind.MAPPED);//from w w w. j a v a 2 s . co m requireNonNull("map", map); for (final Object obj : map.values()) { checkType(obj); } @SuppressWarnings("unchecked") final HashMap<String, Object> valueMap = (HashMap<String, Object>) value; valueMap.clear(); valueMap.putAll(map); }
From source file:de.huberlin.wbi.cfjava.data.Amap.java
public Amap<K, V> put(K key, V value) { HashMap<K, V> newContent; if (key == null) throw new IllegalArgumentException("Key term must not be null."); if (value == null) throw new IllegalArgumentException("Value term must not be null."); newContent = new HashMap<>(); newContent.putAll(content); newContent.put(key, value);/*from ww w . j a v a2 s . c o m*/ return new Amap<>(newContent); }
From source file:com.cloudbees.api.BeesClientBase.java
protected String executeUpload(String uploadURL, Map<String, String> params, Map<String, File> files, UploadProgress writeListener) throws Exception { HashMap<String, String> clientParams = getDefaultParameters(); clientParams.putAll(params); PostMethod filePost = new PostMethod(uploadURL); try {/*from w w w .j ava2 s .co m*/ ArrayList<Part> parts = new ArrayList<Part>(); int fileUploadSize = 0; for (Map.Entry<String, File> fileEntry : files.entrySet()) { FilePart filePart = new FilePart(fileEntry.getKey(), fileEntry.getValue()); parts.add(filePart); fileUploadSize += filePart.length(); //TODO: file params are not currently included in the signature, // we should hash the file contents so we can verify them } for (Map.Entry<String, String> entry : clientParams.entrySet()) { parts.add(new StringPart(entry.getKey(), entry.getValue())); } // add the signature String signature = calculateSignature(clientParams); parts.add(new StringPart("sig", signature)); ProgressUploadEntity uploadEntity = new ProgressUploadEntity(parts.toArray(new Part[parts.size()]), filePost.getParams(), writeListener, fileUploadSize); filePost.setRequestEntity(uploadEntity); HttpClient client = HttpClientHelper.createClient(this.beesClientConfiguration); client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); int status = client.executeMethod(filePost); String response = getResponseString(filePost.getResponseBodyAsStream()); if (status == HttpStatus.SC_OK) { trace("upload complete, response=" + response); } else { trace("upload failed, response=" + HttpStatus.getStatusText(status)); } return response; } finally { filePost.releaseConnection(); } }
From source file:org.trustedanalytics.atk.event.EventTest.java
@Test public void events_inherit_context_data_across_threads() throws InterruptedException { EventContext context1 = new EventContext("ctx1"); context1.put("hello", "world"); EventContext context2 = new EventContext("ctx2"); context2.put("hello", "galaxy"); //Just to prove that contexts aren't sharing context data assertThat(context1.get("hello"), is(not(equalTo(context2.get("hello"))))); final HashMap<String, String> data = new HashMap<>(); Thread thread = new Thread(new Runnable() { @Override/*w w w. j ava2 s. c om*/ public void run() { Event event = EventContext.event(EventTestMessages.SOMETHING_HAPPENED).build(); data.putAll(event.getData()); } }); thread.start(); thread.join(); assertThat(data.get("hello"), is(equalTo("galaxy"))); }
From source file:org.pentaho.reporting.platform.plugin.cache.FileSystemCacheBackend.java
@Override public boolean write(final List<String> key, final Serializable value, final Map<String, Serializable> metaData) { final List<String> cleanKey = sanitizeKeySegments(key); final List<Lock> locks = lockForWrite(cleanKey); try {//from w ww.j a v a 2 s . co m final String filePath = cachePath + StringUtils.join(cleanKey, File.separator); if (writeFile(value, filePath + DATA)) { return false; } final HashMap<String, Serializable> writeableMetaData = new HashMap<>(); if (metaData != null) { writeableMetaData.putAll(metaData); } if (writeFile(writeableMetaData, filePath + METADATA)) { return false; } return true; } finally { unlock(locks); } }
From source file:com.android.volley.toolbox.http.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError, IOException { HashMap<String, String> map = new HashMap<String, String>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders);/*ww w.j a v a2 s .c om*/ String url = request.getUrl(); if (mUrlRewriter != null) { url = mUrlRewriter.rewriteUrl(url); if (url == null) { throw new IOException("URL blocked by rewriter: " + url); } } URL parsedUrl = new URL(url); System.err.println(url); HttpURLConnection connection = openConnection(parsedUrl, request); if (!TextUtils.isEmpty(mUserAgent)) { connection.setRequestProperty(HEADER_USER_AGENT, mUserAgent); } 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()); 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:com.tongbanjie.tarzan.server.client.ClientManager.java
public HashMap<String, HashMap<Channel, ClientChannelInfo>> getGroupChannelTable() { HashMap<String, HashMap<Channel, ClientChannelInfo>> newGroupChannelTable = new HashMap<String, HashMap<Channel, ClientChannelInfo>>(); try {//from w w w . j a va 2 s . c o m if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { newGroupChannelTable.putAll(groupChannelTable); } finally { groupChannelLock.unlock(); } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOGGER.error("", e); } return newGroupChannelTable; }
From source file:org.apache.hcatalog.templeton.ExecServiceImpl.java
/** * Build the environment used for all exec calls. * * @return The environment variables.//w w w . j a v a 2 s.com */ public Map<String, String> execEnv(Map<String, String> env) { HashMap<String, String> res = new HashMap<String, String>(); for (String key : appConf.getStrings(AppConfig.EXEC_ENVS_NAME)) { String val = System.getenv(key); if (val != null) { res.put(key, val); } } if (env != null) res.putAll(env); for (Map.Entry<String, String> envs : res.entrySet()) { LOG.info("Env " + envs.getKey() + "=" + envs.getValue()); } return res; }
From source file:org.opentestsystem.shared.monitoringalerting.service.MetricServiceTest.java
@Test public void testPagingFeatures() { HashMap<String, Metric> page1Map = new HashMap<String, Metric>(); HashMap<String, Metric> page2Map = new HashMap<String, Metric>(); HashMap<String, Metric> page3Map = new HashMap<String, Metric>(); HashMap<String, Metric> page4Map = new HashMap<String, Metric>(); createMetrics(10, ALT_KEY_NODE, COOL); createMetrics(10, ALT_KEY_NODE, "uncool"); Map<String, String[]> requestMap = getTestPagingParams("3"); requestMap.put(ALT_KEY_NODE, new String[] { COOL }); MetricSearchRequest searchRequest = new MetricSearchRequest(requestMap); SearchResponse<Metric> response = metricService.searchMetrics(searchRequest); assertEquals(WRONG_RESP_COUNT, 3, response.getReturnCount()); assertEquals(WRONG_RES_COUNT, 3, response.getSearchResults().size()); for (Metric result : response.getSearchResults()) { page1Map.put(result.getId(), result); }//from www . jav a 2 s . c om requestMap.put(CURRENT_PAGE, new String[] { "1" }); searchRequest = new MetricSearchRequest(requestMap); response = metricService.searchMetrics(searchRequest); assertEquals(WRONG_RESP_COUNT, 3, response.getReturnCount()); assertEquals(WRONG_RES_COUNT, 3, response.getSearchResults().size()); for (Metric result : response.getSearchResults()) { page2Map.put(result.getId(), result); } requestMap.put(CURRENT_PAGE, new String[] { "2" }); searchRequest = new MetricSearchRequest(requestMap); response = metricService.searchMetrics(searchRequest); assertEquals(WRONG_RESP_COUNT, 3, response.getReturnCount()); assertEquals(WRONG_RES_COUNT, 3, response.getSearchResults().size()); for (Metric result : response.getSearchResults()) { page3Map.put(result.getId(), result); } requestMap.put(CURRENT_PAGE, new String[] { "3" }); searchRequest = new MetricSearchRequest(requestMap); response = metricService.searchMetrics(searchRequest); assertEquals(WRONG_RESP_COUNT, 1, response.getReturnCount()); assertEquals(WRONG_RES_COUNT, 1, response.getSearchResults().size()); for (Metric result : response.getSearchResults()) { page4Map.put(result.getId(), result); } requestMap.put(CURRENT_PAGE, new String[] { "4" }); searchRequest = new MetricSearchRequest(requestMap); response = metricService.searchMetrics(searchRequest); assertEquals(WRONG_RESP_COUNT, 0, response.getReturnCount()); assertEquals(WRONG_RES_COUNT, 0, response.getSearchResults().size()); requestMap.put(CURRENT_PAGE, new String[] { "90000" }); searchRequest = new MetricSearchRequest(requestMap); response = metricService.searchMetrics(searchRequest); assertEquals(WRONG_RESP_COUNT, 0, response.getReturnCount()); assertEquals(WRONG_RES_COUNT, 0, response.getSearchResults().size()); HashMap<String, Metric> allMetrics = new HashMap<String, Metric>(); allMetrics.putAll(page1Map); allMetrics.putAll(page2Map); allMetrics.putAll(page3Map); allMetrics.putAll(page4Map); assertEquals("should be 10 unique items", 10, allMetrics.size()); }