List of usage examples for java.util HashMap putAll
public void putAll(Map<? extends K, ? extends V> m)
From source file:org.opentestsystem.shared.monitoringalerting.service.LogServiceTest.java
@Test public void testPagingFeatures() { final HashMap<String, Log> page1Map = new HashMap<String, Log>(); final HashMap<String, Log> page2Map = new HashMap<String, Log>(); final HashMap<String, Log> page3Map = new HashMap<String, Log>(); final HashMap<String, Log> page4Map = new HashMap<String, Log>(); createLogs(10, ALTKEY_NODE, COOL);//from w ww . j av a 2 s . c om createLogs(10, ALTKEY_NODE, "uncool"); final Map<String, String[]> requestMap = new HashMap<String, String[]>(); requestMap.put(PAGE_SIZE, new String[] { "3" }); requestMap.put(CUR_PAGE, new String[] { "0" }); requestMap.put(SORT_DIR, new String[] { "desc", ASC }); requestMap.put(SORT_KEY, new String[] { "_id", SERVER }); requestMap.put("node", new String[] { COOL }); LogSearchRequest searchRequest = new LogSearchRequest(requestMap); String firstResultId = null, lastResultId = null; SearchResponse<Log> response = this.logService.searchLogs(searchRequest); assertThat(response.getReturnCount(), is(3)); assertThat(response.getSearchResults().size(), is(3)); for (final Log result : response.getSearchResults()) { page1Map.put(result.getId(), result); if (lastResultId == null) { lastResultId = result.getId(); } firstResultId = result.getId(); } requestMap.put(PREVIOUS_FIRST_ID, new String[] { firstResultId }); searchRequest = new LogSearchRequest(requestMap); response = this.logService.searchLogs(searchRequest); assertThat(response.getReturnCount(), is(3)); assertThat(response.getSearchResults().size(), is(3)); for (final Log result : response.getSearchResults()) { page2Map.put(result.getId(), result); if (lastResultId == null) { lastResultId = result.getId(); } firstResultId = result.getId(); } requestMap.put(PREVIOUS_FIRST_ID, new String[] { firstResultId }); searchRequest = new LogSearchRequest(requestMap); response = this.logService.searchLogs(searchRequest); assertThat(response.getReturnCount(), is(3)); assertThat(response.getSearchResults().size(), is(3)); for (final Log result : response.getSearchResults()) { page3Map.put(result.getId(), result); if (lastResultId == null) { lastResultId = result.getId(); } firstResultId = result.getId(); } requestMap.put(PREVIOUS_FIRST_ID, new String[] { firstResultId }); firstResultId = null; searchRequest = new LogSearchRequest(requestMap); response = this.logService.searchLogs(searchRequest); assertThat(response.getReturnCount(), is(1)); assertThat(response.getSearchResults().size(), is(1)); for (final Log result : response.getSearchResults()) { page4Map.put(result.getId(), result); if (lastResultId == null) { lastResultId = result.getId(); } firstResultId = result.getId(); } requestMap.put(PREVIOUS_FIRST_ID, new String[] { firstResultId }); firstResultId = null; searchRequest = new LogSearchRequest(requestMap); response = this.logService.searchLogs(searchRequest); assertThat(response.getReturnCount(), is(0)); assertThat(response.getSearchResults().size(), is(0)); requestMap.put(CUR_PAGE, new String[] { "90000" }); searchRequest = new LogSearchRequest(requestMap); response = this.logService.searchLogs(searchRequest); assertThat(response.getReturnCount(), is(0)); assertThat(response.getSearchResults().size(), is(0)); final HashMap<String, Log> allLogs = new HashMap<String, Log>(); allLogs.putAll(page1Map); allLogs.putAll(page2Map); allLogs.putAll(page3Map); allLogs.putAll(page4Map); assertThat(allLogs.size(), is(10)); }
From source file:com.handsome.frame.android.volley.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); }// ww w . j a v a 2s .c om 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)); } if (HandsomeApplication.getCookies() != null) { HDLog.d(TAG + "-Req-Cookie:", HandsomeApplication.getCookies().toString()); connection.addRequestProperty("Cookie", HandsomeApplication.getCookies()); } else { HDLog.d(TAG + "-Req-Cookie:", "null"); } 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); response.setEntity(entityFromConnection(connection)); for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { if (header.getKey() != null) { if (header.getKey().equalsIgnoreCase("Set-Cookie")) { List<String> cookies = header.getValue(); HashMap<String, HttpCookie> cookieMap = new HashMap<String, HttpCookie>(); for (String string : cookies) { List<HttpCookie> cookie = HttpCookie.parse(string); for (HttpCookie httpCookie : cookie) { cookieMap.put(httpCookie.getName(), httpCookie); } } HandsomeApplication.setCookies(cookieMap); HDLog.d(TAG + "-Rsp-Cookie:", HandsomeApplication.getCookies().toString()); } else { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } } return response; }
From source file:org.bpmscript.exec.js.JavascriptProcessExecutor.java
/** * Sends in the next message. The right continuation is looked up using the pid and then executed. * The result is then stored./*from ww w . jav a 2 s . c o m*/ * * @see IProcessExecutor#sendNext(String, String, String, String, String, IProcessDefinition, * Map, Object, String[]) */ public IExecutorResult sendNext(String definitionId, String definitionName, String pid, String branch, String version, String queueId, final Object message) throws BpmScriptException { final Context cx = new DynamicContextFactory().enterContext(); cx.setOptimizationLevel(-1); cx.setLanguageVersion(Context.VERSION_1_7); try { Map<String, Object> invocationContext = createInvocationContext(channel, definitionName); final Scriptable scope = scopeService.findScope(definitionId, invocationContext, cx); IDefinitionConfiguration definitionConfiguration = channel.getDefinitionConfiguration(definitionName); HashMap<String, Object> serialisationContext = new HashMap<String, Object>(); serialisationContext.putAll(definitionConfiguration.getProperties()); serialisationContext.putAll(invocationContext); Continuation continuation = continuationService.getContinuation(serialisationContext, scope, pid, branch); final Continuation unfrozen = continuation; final INextMessage nextMessage = new NextMessage(pid, branch, version, queueId, message); IExecutorResult result = javascriptExecutor.execute(definitionName, pid, branch, version, invocationContext, null, cx, scope, new Callable<Object>() { public Object call() throws Exception { Object call = unfrozen.call(cx, scope, scope, new Object[] { Context.javaToJS(nextMessage, scope) }); return call; } }); continuationService.storeResult(serialisationContext, excludedNames, result); return result; } catch (Throwable e) { log.warn(e, e); return new FailedResult(pid, branch, version, e, null); } finally { Context.exit(); } }
From source file:org.bpmscript.exec.js.JavascriptProcessExecutor.java
/** * Kills the process. Does this by restoring the continuation and passing it a "KILL" message. * This gives the instance a chance to run any code required to release resources. * /*from ww w .j a va 2 s.c o m*/ * @see org.bpmscript.IProcessExecutor#kill(java.lang.String, java.lang.String, * java.lang.String, org.bpmscript.IProcessDefinition, java.util.Map) */ public IKilledResult kill(String definitionId, String definitionName, String pid, String branch, String version, String message) throws BpmScriptException { final Context cx = new DynamicContextFactory().enterContext(); cx.setOptimizationLevel(-1); cx.setLanguageVersion(Context.VERSION_1_7); try { Map<String, Object> invocationContext = createInvocationContext(channel, definitionName); final Scriptable scope = scopeService.findScope(definitionId, invocationContext, cx); IDefinitionConfiguration definitionConfiguration = channel.getDefinitionConfiguration(definitionName); HashMap<String, Object> serialisationContext = new HashMap<String, Object>(); serialisationContext.putAll(definitionConfiguration.getProperties()); serialisationContext.putAll(invocationContext); Continuation continuation = continuationService.getContinuation(serialisationContext, scope, pid, branch); final Continuation unfrozen = continuation; final IKillMessage scriptMessage = new KillMessage(pid, branch, message); IExecutorResult result = javascriptExecutor.execute(definitionName, pid, branch, version, invocationContext, null, cx, scope, new Callable<Object>() { public Object call() throws Exception { Object call = unfrozen.call(cx, scope, scope, new Object[] { Context.javaToJS(scriptMessage, scope) }); return call; } }); continuationService.storeResult(serialisationContext, excludedNames, result); if (result instanceof IKilledResult) { IKilledResult killedResult = (IKilledResult) result; return killedResult; } else { throw new BpmScriptException("Process " + pid + " " + branch + " " + version + " not killed"); } } catch (Throwable e) { throw new BpmScriptException(e); } finally { Context.exit(); } }
From source file:ar.com.qbe.siniestros.model.utils.MimeMagic.MagicMatch.java
/** * DOCUMENT ME!/*from w w w. j a v a 2 s. c o m*/ * * @return DOCUMENT ME! * * @throws CloneNotSupportedException DOCUMENT ME! */ protected Object clone() throws CloneNotSupportedException { MagicMatch clone = new MagicMatch(); clone.setBitmask(Long.toString(bitmask, 8)); clone.setComparator("" + comparator); clone.setDescription(description); clone.setExtension(extension); clone.setLength(length); clone.setMimeType(mimeType); clone.setOffset(offset); // these properties should only be String types, so we shouldn't have to clone them if (properties != null) { HashMap m = new HashMap(); m.putAll(properties); clone.setProperties(m); } Iterator i = subMatches.iterator(); ArrayList a = new ArrayList(); while (i.hasNext()) { MagicMatch mm = (MagicMatch) i.next(); a.add(mm); } clone.setSubMatches(a); clone.setTest(test); clone.setType(type); // TODO Auto-generated method stub return clone; }
From source file:com.iflytek.android.framework.volley.toolbox.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { String url = request.getUrl(); HashMap<String, String> map = new HashMap<String, String>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders);/* w w w . jav a 2s . co m*/ 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); for (String headerName : map.keySet()) { VolleyLog.e("======4:" + headerName + ";" + map.get(headerName)); 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); 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:org.apache.storm.st.wrapper.TopoWrap.java
public void submit(ImmutableMap<String, Object> of) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException { final HashMap<String, Object> newConfig = new HashMap<>(submitConf); newConfig.putAll(of); StormSubmitter.submitTopologyWithProgressBar(name, newConfig, topology); }
From source file:org.bpmscript.exec.js.JavascriptProcessExecutor.java
/** * Sends the first message. This process executor checks the scope for a function that matches * the title case of the definitionName. It then hands that and all the request parameters to * a function called "process" (the processMethodName field). * /*from w w w. j a v a 2 s.c o m*/ * Once it has executed the definition, it stores the result * * @see IProcessExecutor#sendFirst(String, String, String, String, IProcessDefinition, Map, * Object, String[], String, String) */ public IExecutorResult sendFirst(String processId, final String pid, final String branch, final String version, final IProcessDefinition processDefinition, final Object message, final String operation, final String parentVersion) throws BpmScriptException { final Context cx = new DynamicContextFactory().enterContext(); cx.setOptimizationLevel(-1); cx.setLanguageVersion(Context.VERSION_1_7); try { Map<String, Object> invocationContext = createInvocationContext(channel, processDefinition.getName()); final Scriptable scope = scopeService.createScope(processId, processDefinition, invocationContext, cx); // get the main function and execute it String constructorName = constructorName(processDefinition.getName()); Object constructorObject = ScriptableObject.getProperty(scope, constructorName); Object processObject = ScriptableObject.getProperty(scope, processMethodName); if (constructorObject == null || !(constructorObject instanceof Function)) { throw new BpmScriptException("function name " + constructorName + " not found"); } if (processObject == null || !(processObject instanceof Function)) { throw new BpmScriptException("process operation " + processMethodName + " not found"); } final Function constructorFunction = (Function) constructorObject; final Function processFunction = (Function) processObject; IExecutorResult result = javascriptExecutor.execute(processDefinition.getName(), pid, branch, version, invocationContext, null, cx, scope, new Callable<Object>() { public Object call() throws Exception { Object call = processFunction.call(cx, scope, scope, new Object[] { constructorFunction, processDefinition.getName(), operation, parentVersion, pid, branch, version, Context.javaToJS(message, scope) }); return call; } }); IDefinitionConfiguration definitionConfiguration = channel .getDefinitionConfiguration(processDefinition.getName()); HashMap<String, Object> serialisationContext = new HashMap<String, Object>(); serialisationContext.putAll(definitionConfiguration.getProperties()); serialisationContext.putAll(invocationContext); continuationService.storeResult(serialisationContext, excludedNames, result); return result; } catch (Throwable e) { log.warn(e, e); return new FailedResult(pid, branch, version, e, null); } finally { Context.exit(); } }
From source file:org.jboss.dashboard.ui.panel.advancedHTML.HTMLDriver.java
/** * Write instance content to given OutputStream, which must not be closed. *//*from ww w . j a va 2 s . c o m*/ public void exportContent(PanelInstance instance, OutputStream os) throws Exception { HTMLText text = load(instance); if (text == null) { try { text = new HTMLText(); text.setPanelInstance(instance); text.save(); } catch (Exception e) { log.error("Error creating empty HTMLText object", e); } } ObjectOutputStream oos = new ObjectOutputStream(os); if (log.isDebugEnabled()) log.debug("Exporting content: " + text.getText()); HashMap<String, String> h = new HashMap<String, String>(); // Avoids serializing a hibernate map h.putAll(text.getText()); oos.writeObject(h); }
From source file:com.wms.studio.cache.lock.SyncLockMapCache.java
/** * ?/* w w w . ja va 2 s. c o m*/ * * @param cacheValues */ public void puts(Map<K, V> cacheValues) { // ?????? try { lock.lock(); HashMap<K, V> attributes = memcachedClient.get(name); boolean isInit = false; if (attributes == null) { isInit = true; attributes = new HashMap<K, V>(); } attributes.putAll(cacheValues); if (isInit) { memcachedClient.set(name, 0, attributes); } else { memcachedClient.replace(name, 0, attributes); } } catch (Exception e) { log.fatal("MemCache,.", e); } finally { lock.unlock(); } }