List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:ch.puzzle.itc.mobiliar.business.server.boundary.ServerView.java
private HashMap<String, ServerTuple> merge(List<ServerTuple> servers) { HashMap<String, ServerTuple> releaseFilteredServer = new HashMap<String, ServerTuple>(); for (ServerTuple server : servers) { String code = server.getHost() + server.getAppServer() + server.getEnvironment() + server.getNode(); if (releaseFilteredServer.containsKey(code)) { ServerTuple oldServer = releaseFilteredServer.get(code); if (oldServer.getAppServerRelease() != server.getAppServerRelease()) { server.setAppServerRelease(MULTI_MARKER); }// w w w . jav a2 s .co m if (oldServer.getNodeRelease() != server.getNodeRelease()) { server.setNodeRelease(MULTI_MARKER); } if (oldServer.getRuntime() != server.getRuntime()) { server.setRuntime(MULTI_MARKER); } } releaseFilteredServer.put(code, server); } return releaseFilteredServer; }
From source file:com.opengamma.integration.copier.snapshot.reader.FileSnapshotReader.java
private void buildYieldCurves( HashMap<String, Pair<YieldCurveKey, ManageableYieldCurveSnapshot>> yieldCurveBuilder, Map<String, String> currentRow) { String name = currentRow.get(SnapshotColumns.NAME.get()); if (!yieldCurveBuilder.containsKey(name)) { ManageableYieldCurveSnapshot curve = new ManageableYieldCurveSnapshot(); ManageableUnstructuredMarketDataSnapshot snapshot = new ManageableUnstructuredMarketDataSnapshot(); YieldCurveKey key = new YieldCurveKey( Currency.of(currentRow.get(SnapshotColumns.YIELD_CURVE_CURRENCY.get())), currentRow.get(SnapshotColumns.NAME.get())); curve.setValuationTime(Instant.parse(currentRow.get(SnapshotColumns.INSTANT.get()))); snapshot.putValue(createExternalIdBundle(currentRow), currentRow.get(SnapshotColumns.VALUE_NAME.get()), createValueSnapshot(currentRow)); curve.setValues(snapshot);/*ww w.j a v a2s. c om*/ yieldCurveBuilder.put(name, Pair.of(key, curve)); } else { yieldCurveBuilder.get(name).getSecond().getValues().putValue(createExternalIdBundle(currentRow), currentRow.get(SnapshotColumns.VALUE_NAME.get()), createValueSnapshot(currentRow)); } }
From source file:com.zavakid.mushroom.impl.MetricsConfig.java
/** * Return sub configs for instance specified in the config. Assuming format specified as follows: * // w w w . jav a2 s. co m * <pre> * [type].[instance].[option] = [value] * </pre> * * Note, '*' is a special default instance, which is excluded in the result. * * @param type of the instance * @return a map with [instance] as key and config object as value */ Map<String, MetricsConfig> getInstanceConfigs(String type) { HashMap<String, MetricsConfig> map = new HashMap<String, MetricsConfig>(); MetricsConfig sub = subset(type); for (String key : sub.keys()) { Matcher matcher = INSTANCE_REGEX.matcher(key); if (matcher.matches()) { String instance = matcher.group(1); if (!map.containsKey(instance)) { map.put(instance, sub.subset(instance)); } } } return map; }
From source file:org.dataconservancy.ui.services.EZIDServiceIT.java
/** * Tests that an id is created without exception, and the id returned is not empty. * @throws EZIDServiceException/*from w ww . j ava 2 s . c o m*/ * @throws IOException * @throws ClientProtocolException */ @Test public void testCreateId() throws EZIDServiceException, ClientProtocolException, IOException { String id = ezidService.createID(ezidMetadata); assertFalse(id.isEmpty()); HttpGet getID = new HttpGet(id); HttpResponse resp = httpClient.execute(getID); assertEquals(200, resp.getStatusLine().getStatusCode()); HttpEntity respEntity = resp.getEntity(); StringWriter writer = new StringWriter(); IOUtils.copy(respEntity.getContent(), writer); String response = writer.toString(); HashMap<String, String> metadata = parseResponse(response); assertTrue(metadata.containsKey("_status")); assertEquals("reserved", metadata.get("_status")); }
From source file:org.ala.spatial.services.web.DashboardController.java
@RequestMapping(value = { DASHBOARD_HOME + "/types/{type}", "app/types/{type}" }) public ModelAndView displayFullTypeList(@PathVariable String type, HttpServletRequest req) { if (type.equals("")) { return index(req); }//from www . ja v a2 s. c o m String useremail = null; if (Utilities.isAppAuth(req)) { try { useremail = URLDecoder.decode(req.getParameter("email"), "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("User: " + req.getParameter("email")); return new ModelAndView("message", "msg", "Please authenticate yourself with the ALA system"); } } else if (!Utilities.isLoggedIn(req)) { //ModelAndView mv = new ModelAndView("dashboard/types"); //mv.addAttribute("error", "authentication"); //mv.addAttribute("message", "Please authenticate yourself with the ALA system"); //return mv; return new ModelAndView("message", "msg", "Please authenticate yourself with the ALA system"); } else { useremail = Utilities.getUserEmail(req); } List<Action> abe = actionDao.getActionsByEmailAndCategory1(useremail, type); FastDateFormat df = FastDateFormat.getInstance("yyyy-MM-dd hh:mm"); HashMap<String, String> types = new HashMap<String, String>(); for (Action a : abe) { if (a.getService() == null) { continue; } if (a.getCategory1() != null && !a.getCategory1().equalsIgnoreCase(type)) { continue; } String val = ""; if (types.containsKey(a.getCategory1())) { val = types.get(a.getCategory1()) + "|"; } val += a.getService().getName() + "-" + a.getId() + "-" + df.format(a.getTime()).replaceAll("-", "_"); types.put(a.getCategory1(), val); } String key = type.substring(0, 1).toUpperCase() + type.substring(1).toLowerCase(); ModelAndView mv = new ModelAndView("dashboard/types"); mv.addObject("abe", abe); mv.addObject("types", types); mv.addObject("key", key); mv.addObject("useremail", useremail); mv.addObject("isAdmin", Utilities.isUserAdmin(req)); return mv; }
From source file:org.opendaylight.infrautils.diagstatus.shell.HttpClient.java
public HttpResponse sendRequest(HttpRequest request) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); if (httpclient == null) { throw new ClientProtocolException("Couldn't create an HTTP client"); }//from w ww . j av a 2s .c o m RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(request.getTimeout()) .setConnectTimeout(request.getTimeout()).build(); HttpRequestBase httprequest; String method = request.getMethod(); if (method.equalsIgnoreCase("GET")) { httprequest = new HttpGet(request.getUri()); } else if (method.equalsIgnoreCase("POST")) { httprequest = new HttpPost(request.getUri()); if (request.getEntity() != null) { StringEntity sentEntity = new StringEntity(request.getEntity()); sentEntity.setContentType(request.getContentType()); ((HttpEntityEnclosingRequestBase) httprequest).setEntity(sentEntity); } } else if (method.equalsIgnoreCase("PUT")) { httprequest = new HttpPut(request.getUri()); if (request.getEntity() != null) { StringEntity sentEntity = new StringEntity(request.getEntity()); sentEntity.setContentType(request.getContentType()); ((HttpEntityEnclosingRequestBase) httprequest).setEntity(sentEntity); } } else if (method.equalsIgnoreCase("DELETE")) { httprequest = new HttpDelete(request.getUri()); } else { httpclient.close(); throw new IllegalArgumentException( "This profile class only supports GET, POST, PUT, and DELETE methods"); } httprequest.setConfig(requestConfig); // add request headers Iterator<String> headerIterator = request.getHeaders().keySet().iterator(); while (headerIterator.hasNext()) { String header = headerIterator.next(); Iterator<String> valueIterator = request.getHeaders().get(header).iterator(); while (valueIterator.hasNext()) { httprequest.addHeader(header, valueIterator.next()); } } CloseableHttpResponse response = httpclient.execute(httprequest); try { int httpResponseCode = response.getStatusLine().getStatusCode(); HashMap<String, List<String>> headerMap = new HashMap<>(); // copy response headers HeaderIterator it = response.headerIterator(); while (it.hasNext()) { Header nextHeader = it.nextHeader(); String name = nextHeader.getName(); String value = nextHeader.getValue(); if (headerMap.containsKey(name)) { headerMap.get(name).add(value); } else { List<String> list = new ArrayList<>(); list.add(value); headerMap.put(name, list); } } if (httpResponseCode > 299) { return new HttpResponse(httpResponseCode, response.getStatusLine().getReasonPhrase(), headerMap); } Optional<HttpEntity> receivedEntity = Optional.ofNullable(response.getEntity()); String httpBody = receivedEntity.isPresent() ? EntityUtils.toString(receivedEntity.get()) : null; return new HttpResponse(response.getStatusLine().getStatusCode(), httpBody, headerMap); } finally { response.close(); } }
From source file:com.ibm.bi.dml.hops.OptimizerUtils.java
/** * //from ww w. j a va 2 s.c om * @param root * @param valMemo * @param vars * @return * @throws HopsException */ protected static double rEvalSimpleUnaryDoubleExpression(Hop root, HashMap<Long, Double> valMemo, LocalVariableMap vars) throws HopsException { //memoization (prevent redundant computation of common subexpr) if (valMemo.containsKey(root.getHopID())) return valMemo.get(root.getHopID()); double ret = Double.MAX_VALUE; UnaryOp uroot = (UnaryOp) root; Hop input = uroot.getInput().get(0); if (uroot.getOp() == Hop.OpOp1.NROW) ret = (input.getDim1() > 0) ? input.getDim1() : Double.MAX_VALUE; else if (uroot.getOp() == Hop.OpOp1.NCOL) ret = (input.getDim2() > 0) ? input.getDim2() : Double.MAX_VALUE; else { double lval = rEvalSimpleDoubleExpression(uroot.getInput().get(0), valMemo, vars); if (lval != Double.MAX_VALUE) { switch (uroot.getOp()) { case SQRT: ret = Math.sqrt(lval); break; case ROUND: ret = Math.round(lval); break; case CAST_AS_BOOLEAN: ret = (lval != 0) ? 1 : 0; break; case CAST_AS_INT: ret = UtilFunctions.toLong(lval); break; case CAST_AS_DOUBLE: ret = lval; break; default: ret = Double.MAX_VALUE; } } } valMemo.put(root.getHopID(), ret); return ret; }
From source file:com.ibm.bi.dml.hops.OptimizerUtils.java
/** * //from w ww . ja va2 s. c om * @param root * @param valMemo * @param vars * @return * @throws HopsException */ protected static double rEvalSimpleBinaryDoubleExpression(Hop root, HashMap<Long, Double> valMemo, LocalVariableMap vars) throws HopsException { //memoization (prevent redundant computation of common subexpr) if (valMemo.containsKey(root.getHopID())) return valMemo.get(root.getHopID()); double ret = Double.MAX_VALUE; BinaryOp broot = (BinaryOp) root; double lret = rEvalSimpleDoubleExpression(broot.getInput().get(0), valMemo, vars); double rret = rEvalSimpleDoubleExpression(broot.getInput().get(1), valMemo, vars); //note: positive and negative values might be valid subexpressions if (lret != Double.MAX_VALUE && rret != Double.MAX_VALUE) //if known { switch (broot.getOp()) { case PLUS: ret = lret + rret; break; case MINUS: ret = lret - rret; break; case MULT: ret = lret * rret; break; case DIV: ret = lret / rret; break; case MIN: ret = Math.min(lret, rret); break; case MAX: ret = Math.max(lret, rret); break; case POW: ret = Math.pow(lret, rret); break; default: ret = Double.MAX_VALUE; } } valMemo.put(root.getHopID(), ret); return ret; }
From source file:biomine.bmvis2.pipeline.DeleteElementsOperation.java
public void doOperation(VisualGraph graph) throws GraphOperationException { HashMap<String, VisualNode> allNodes = new HashMap<String, VisualNode>(); for (VisualNode node : graph.getAllNodes()) allNodes.put(node.getId(), node); HashMap<String, VisualEdge> allEdges = new HashMap<String, VisualEdge>(); for (VisualEdge edge : graph.getAllEdges()) allEdges.put(edge.toString(), edge); for (String nodeId : this.deletedNodes) { if (allNodes.containsKey(nodeId)) graph.deleteNode(allNodes.get(nodeId)); else// ww w . j a va 2s. c o m Logging.warning("graph_operation", "Node " + nodeId + " not in graph; couldn't be deleted."); } for (String edgeId : this.deletedEdges) { if (allEdges.containsKey(edgeId)) graph.deleteEdge(allEdges.get(edgeId)); else Logging.warning("graph_operation", "Edge " + edgeId + " not in graph; couldn't be deleted."); } }
From source file:com.opengamma.integration.copier.snapshot.reader.FileSnapshotReader.java
private void buildSurface( HashMap<String, Pair<VolatilitySurfaceKey, ManageableVolatilitySurfaceSnapshot>> surfaceBuilder, Map<String, String> currentRow) { String name = currentRow.get(SnapshotColumns.NAME.get()); if (!surfaceBuilder.containsKey(name)) { ManageableVolatilitySurfaceSnapshot surface = new ManageableVolatilitySurfaceSnapshot(); VolatilitySurfaceKey key = new VolatilitySurfaceKey( UniqueId.parse(currentRow.get(SnapshotColumns.SURFACE_TARGET.get())), currentRow.get(SnapshotColumns.NAME.get()), currentRow.get(SnapshotColumns.SURFACE_INSTRUMENT_TYPE.get()), currentRow.get(SnapshotColumns.SURFACE_QUOTE_TYPE.get()), currentRow.get(SnapshotColumns.SURFACE_QUOTE_UNITS.get())); HashMap values = new HashMap<Pair<Object, Object>, ValueSnapshot>(); values.put(Pair.of(currentRow.get(SnapshotColumns.SURFACE_X.get()), currentRow.get(SnapshotColumns.SURFACE_Y.get())), createValueSnapshot(currentRow)); surface.setValues(values);//from w ww .ja va 2 s. c om surfaceBuilder.put(name, Pair.of(key, surface)); } else { surfaceBuilder.get(name).getSecond().getValues().put(createOrdinatePair(currentRow), createValueSnapshot(currentRow)); } }