List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:com.chargebee.CSV.PhoneBook.PhoneBook2.PhoneBook.java
private void directory(CSVParser parser) { HashMap<String, ArrayList> map = new HashMap(); for (CSVRecord record : parser) { ArrayList<Person> person = new ArrayList(); Person p = new Person(record.get("Name"), record.get("Address"), new Phone(record.get("Mobile"), record.get("Home"), record.get("Work"))); if (!map.containsKey(record.get("Name"))) { person.add(p);// w w w .j ava2 s.c o m map.put(record.get("Name"), person); continue; } person = map.get(record.get("Name")); person.add(p); map.put(record.get("Name"), person); } display(map); }
From source file:com.esri.geoevent.solutions.adapter.geomessage.DefenseInboundAdapter.java
@SuppressWarnings("incomplete-switch") public void queueGeoEvent(HashMap<String, String> fields) { // in.mark(4 * 1024); if (fields.containsKey("_type")) { String geoEventTypeName = fields.get("_type"); GeoEvent geoEvent = findAndCreate(geoEventTypeName); if (geoEvent == null) { LOG.error("The incoming GeoEvent of type \"" + geoEventTypeName + "\" does not have a corresponding Event Definition in the ArcGIS GeoEvent server."); } else {//from ww w. j av a2s . c om GeoEventDefinition definition = geoEvent.getGeoEventDefinition(); for (String fieldName : fields.keySet()) { String fieldValue = fields.get(fieldName); try { FieldDefinition fieldDefinition = definition.getFieldDefinition(fieldName); if (fieldDefinition == null) { LOG.error("The incoming GeoEvent of type \"" + geoEventTypeName + "\" had an attribute called \"" + fieldName + "\"that does not exist in the corresponding Event Definition."); continue; } switch (fieldDefinition.getType()) { case Integer: geoEvent.setField(fieldName, Integer.parseInt(fieldValue)); break; case Long: geoEvent.setField(fieldName, Long.parseLong(fieldValue)); break; case Short: geoEvent.setField(fieldName, Short.parseShort(fieldValue)); break; case Double: geoEvent.setField(fieldName, Double.parseDouble(fieldValue)); break; case Float: geoEvent.setField(fieldName, Float.parseFloat(fieldValue)); break; case Boolean: geoEvent.setField(fieldName, Boolean.parseBoolean(fieldValue)); break; case Date: geoEvent.setField(fieldName, DateUtil.convert(fieldValue)); break; case String: geoEvent.setField(fieldName, fieldValue); break; case Geometry: String geometryString = fieldValue; if (geometryString.contains(";")) geometryString = geometryString.substring(0, geometryString.indexOf(';') - 1); String[] g = geometryString.split(","); double x = Double.parseDouble(g[0]); double y = Double.parseDouble(g[1]); double z = 0; if (g.length > 2) z = Double.parseDouble(g[2]); int wkid = Integer.parseInt(fields.get("_wkid")); //Point point = spatial.createPoint(x, y, z, wkid); Point point = new Point(x, y, z); SpatialReference sref = SpatialReference.create(wkid); MapGeometry mapGeo = new MapGeometry(point, sref); //int geometryID = geoEvent.getGeoEventDefinition().getGeometryId(); geoEvent.setGeometry(mapGeo); break; } List<FieldDefinition> fdefs = geoEvent.getGeoEventDefinition().getFieldDefinitions(); Boolean hasStartTime = false; for (FieldDefinition fd : fdefs) { List<String> tags = fd.getTags(); if (!tags.isEmpty()) { if (tags.contains("TIME_START")) { hasStartTime = true; break; } } } if (hasStartTime) { if (geoEvent.getField("TIME_START") == null) { long currentTime = System.currentTimeMillis(); Date time = new Date(currentTime); geoEvent.setField("TIME_START", time); } } } catch (Exception ex) { LOG.warn("Error wile trying to parse the GeoEvent field " + fieldName + ":" + fieldValue, ex); } } } queue.add(geoEvent); } }
From source file:edu.cornell.mannlib.vitro.webapp.search.externallookup.impl.SolrLookup.java
public void initializeLookup(HashMap<String, String> inputParameters) throws Exception { //Check for solrAPI if (inputParameters.containsKey(solrAPIKey)) { this.solrAPI = inputParameters.get(solrAPIKey); } else {/* w ww . j a v a 2 s . c o m*/ log.error("Solr lookup cannot be initialized as no Solr API has been passed"); throw new Exception("Solr lookup cannot be initialized as no Solr API has been passed"); } if (inputParameters.containsKey(endpointURLKey)) { this.endpointURL = inputParameters.get(endpointURLKey); log.debug("Endpoint URL is " + this.endpointURL); } if (inputParameters.containsKey(endpointLabelKey)) { this.endpointLabel = inputParameters.get(endpointLabelKey); log.debug("Endpoint Label is " + this.endpointLabel); } if (inputParameters.containsKey(serviceURIKey)) { this.serviceURI = inputParameters.get(serviceURIKey); log.debug("Service URI is " + this.serviceURI); } if (inputParameters.containsKey(serviceLabelKey)) { this.serviceLabel = inputParameters.get(serviceLabelKey); log.debug("Service Label is " + this.serviceLabel); } }
From source file:eionet.gdem.conversion.odf.OpenDocument.java
/** * Finds schema-url attributes from content file (stored in xsl) table:table attribute and transforms the values into meta.xml * file user defined properties/*w w w. j a va2s . co m*/ * @throws Exception If an error occurs. */ private void convertMetaFile() throws Exception { String schemaUrl = null; FileOutputStream os = null; FileInputStream in = null; StringBuffer tableSchemaUrls = new StringBuffer(); try { IXmlCtx ctx = new XmlContext(); ctx.checkFromFile(strContentFile); IXQuery xQuery = ctx.getQueryManager(); List elements = xQuery.getElements("table:table"); for (int i = 0; i < elements.size(); i++) { HashMap attr_map = (HashMap) elements.get(i); if (attr_map.containsKey(OdsReader.SCHEMA_ATTR_NAME) && Utils.isNullStr(schemaUrl)) { schemaUrl = (String) attr_map.get(OdsReader.SCHEMA_ATTR_NAME); } if (attr_map.containsKey(OdsReader.TBL_SCHEMAS_ATTR_NAME)) { if (attr_map.containsKey("table:name")) { String schema_url = (String) attr_map.get(OdsReader.TBL_SCHEMAS_ATTR_NAME); String name = (String) attr_map.get("table:name"); if (!Utils.isNullStr(schema_url) && !Utils.isNullStr(name)) { tableSchemaUrls.append(OdsReader.TABLE_NAME); tableSchemaUrls.append(name); tableSchemaUrls.append(";"); tableSchemaUrls.append(OdsReader.TABLE_SCHEMA_URL); tableSchemaUrls.append(schema_url); tableSchemaUrls.append(";"); } } } } if (!Utils.isNullStr(schemaUrl)) { os = new FileOutputStream(strWorkingFolder + File.separator + META_FILE_NAME); in = new FileInputStream(strMetaFile); Map<String, String> parameters = new HashMap<String, String>(); parameters.put(OdsReader.SCHEMA_ATTR_NAME, schemaUrl); parameters.put(OdsReader.TBL_SCHEMAS_ATTR_NAME, tableSchemaUrls.toString()); ConvertContext conversionContext = new ConvertContext(in, strMetaXslFile, os, "xml"); ConvertStrategy cs = new XMLConverter(); cs.setXslParams(parameters); conversionContext.executeConversion(cs); // XSLTransformer transform = new XSLTransformer(); // transform.transform(strMetaXslFile, new InputSource(in), os, parameters); } } catch (Exception ex) { LOGGER.error("Error converting meta.xml"); throw ex; } finally { IOUtils.closeQuietly(os); IOUtils.closeQuietly(in); } }
From source file:com.thoughtworks.go.server.service.RulesService.java
private void addError(HashMap<CaseInsensitiveString, StringBuilder> pipelinesWithErrors, CaseInsensitiveString pipelineName, String message) { if (pipelinesWithErrors == null) { pipelinesWithErrors = new HashMap<>(); }//from w w w . j a v a 2s. c o m if (!pipelinesWithErrors.containsKey(pipelineName)) { pipelinesWithErrors.put(pipelineName, new StringBuilder()); } StringBuilder stringBuilder = pipelinesWithErrors.get(pipelineName).append(message); pipelinesWithErrors.put(pipelineName, stringBuilder); }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.onlineTests.ReadDistributedTestMarks.java
protected InfoSiteStudentsTestMarks run(String executionCourseId, String distributedTestId) throws FenixServiceException { InfoSiteStudentsTestMarks infoSiteStudentsTestMarks = new InfoSiteStudentsTestMarks(); DistributedTest distributedTest = FenixFramework.getDomainObject(distributedTestId); if (distributedTest == null) { throw new InvalidArgumentsServiceException(); }// w ww. ja va 2 s . com List<StudentTestQuestion> studentTestQuestionList = distributedTest .getStudentTestQuestionsSortedByStudentNumberAndTestQuestionOrder(); HashMap<String, InfoStudentTestQuestionMark> infoStudentTestQuestionMarkList = new HashMap<String, InfoStudentTestQuestionMark>(); for (StudentTestQuestion studentTestQuestion : studentTestQuestionList) { if (infoStudentTestQuestionMarkList.containsKey(studentTestQuestion.getStudent().getExternalId())) { InfoStudentTestQuestionMark infoStudentTestQuestionMark = infoStudentTestQuestionMarkList .get(studentTestQuestion.getStudent().getExternalId()); ParseSubQuestion parse = new ParseSubQuestion(); Question question = studentTestQuestion.getQuestion(); try { question = parse.parseSubQuestion(studentTestQuestion.getQuestion()); } catch (Exception e) { throw new FenixServiceException(e); } if (studentTestQuestion.getItemId() != null && !studentTestQuestion.getItemId() .equals(question.getSubQuestions().iterator().next().getItemId())) { infoStudentTestQuestionMark.addTestQuestionMark( infoStudentTestQuestionMark.getTestQuestionMarks().size() - 1, studentTestQuestion.getTestQuestionMark()); } else { infoStudentTestQuestionMark.addTestQuestionMark(studentTestQuestion.getTestQuestionMark()); } infoStudentTestQuestionMark.addToMaximumMark(studentTestQuestion.getTestQuestionValue()); } else { infoStudentTestQuestionMarkList.put(studentTestQuestion.getStudent().getExternalId(), InfoStudentTestQuestionMark.newInfoFromDomain(studentTestQuestion)); } } List<InfoStudentTestQuestionMark> infoStudentTestQuestionList = new ArrayList<InfoStudentTestQuestionMark>( infoStudentTestQuestionMarkList.values()); Collections.sort(infoStudentTestQuestionList, new BeanComparator("studentNumber")); infoSiteStudentsTestMarks.setInfoStudentTestQuestionList(infoStudentTestQuestionList); infoSiteStudentsTestMarks.setExecutionCourse( InfoExecutionCourse.newInfoFromDomain(distributedTest.getTestScope().getExecutionCourse())); infoSiteStudentsTestMarks.setInfoDistributedTest(InfoDistributedTest.newInfoFromDomain(distributedTest)); return infoSiteStudentsTestMarks; }
From source file:com.predic8.membrane.core.interceptor.oauth2.GoogleAuthorizationService.java
@Override public boolean handleRequest(Exchange exc, String state, String publicURL, Session session) throws Exception { String path = uriFactory.create(exc.getDestinations().get(0)).getPath(); if ("/oauth2callback".equals(path)) { try {//from ww w .j a v a 2s . co m Map<String, String> params = URLParamUtil.getParams(uriFactory, exc); String state2 = params.get("state"); if (state2 == null) throw new RuntimeException("No CSRF token."); Map<String, String> param = URLParamUtil.parseQueryString(state2); if (param == null || !param.containsKey("security_token")) throw new RuntimeException("No CSRF token."); if (!param.get("security_token").equals(state)) throw new RuntimeException("CSRF token mismatch."); String url = param.get("url"); if (url == null) url = "/"; if (log.isDebugEnabled()) log.debug("CSRF token match."); String code = params.get("code"); if (code == null) throw new RuntimeException("No code received."); Exchange e = new Request.Builder().post("https://accounts.google.com/o/oauth2/token") .header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded") .body("code=" + code + "&client_id=" + clientId + ".apps.googleusercontent.com&client_secret=" + clientSecret + "&" + "redirect_uri=" + publicURL + "oauth2callback&grant_type=authorization_code") .buildExchange(); e.setRule(new NullRule() { @Override public SSLContext getSslOutboundContext() { return new SSLContext(new SSLParser(), null, null); } }); LogInterceptor logi = null; if (log.isDebugEnabled()) { logi = new LogInterceptor(); logi.setHeaderOnly(false); logi.handleRequest(e); } Response response = httpClient.call(e).getResponse(); if (response.getStatusCode() != 200) { response.getBody().read(); throw new RuntimeException( "Google Authentication server returned " + response.getStatusCode() + "."); } if (log.isDebugEnabled()) logi.handleResponse(e); HashMap<String, String> json = Util.parseSimpleJSONResponse(response); if (!json.containsKey("id_token")) throw new RuntimeException("No id_token received."); GoogleIdToken idToken = GoogleIdToken.parse(factory, json.get("id_token")); if (idToken == null) throw new RuntimeException("Token cannot be parsed"); if (!verifier.verify(idToken) || !idToken .verifyAudience(Collections.singletonList(clientId + ".apps.googleusercontent.com"))) throw new RuntimeException("Invalid token"); Map<String, String> userAttributes = session.getUserAttributes(); synchronized (userAttributes) { userAttributes.put("headerX-Authenticated-Email", idToken.getPayload().getEmail()); } session.authorize(); exc.setResponse(Response.redirect(url, false).build()); return true; } catch (Exception e) { exc.setResponse(Response.badRequest().body(e.getMessage()).build()); } } return false; }
From source file:com.krawler.spring.companyDetails.companyDetailsDAOImpl.java
@Override public void deleteCompany(HashMap<String, Object> requestParams) throws ServiceException { String companyid = ""; try {/*from ww w . j a v a 2s . c o m*/ if (requestParams.containsKey("companyid") && requestParams.get("companyid") != null) { companyid = requestParams.get("companyid").toString(); } Company company = (Company) get(Company.class, companyid); company.setDeleted(1); saveOrUpdate(company); } catch (Exception e) { throw ServiceException.FAILURE("companyDetailsDAOImpl.deleteCompany", e); } }
From source file:biomine.bmvis2.pipeline.sources.StreamGraphSource.java
@Override public void doOperation(VisualGraph g) throws GraphOperationException { Logging.debug("expand", "StreamGraphSource.doOperation()"); BMGraph bmg = this.getBMGraph(); Collection<VisualNode> oldNodes = g.getNodes(); HashMap<String, String> positions = new HashMap<String, String>(); for (VisualNode node : oldNodes) positions.put(node.getId(), node.getBMPos()); g.addBMGraph(bmg);/*from w ww.j a v a 2 s . c om*/ for (VisualNode node : g.getNodes()) if (positions.containsKey(node.getId())) node.getBMNode().put(BMGraphAttributes.POS_KEY, positions.get(node.getId())); }
From source file:org.owasp.jbrofuzz.graph.canvas.StatusCodeChart.java
/** * <p>/*from w ww . j av a2s . c o m*/ * Method for creating the final Chart. * </p> * * * @see #StatusCodeChart(int) * @author subere@uncon.org * @version 1.5 * @since 1.2 */ public void createFinalPlotCanvas() { final HashMap<String, Integer> map = new HashMap<String, Integer>(); for (final String n : yData) { if (map.containsKey(n)) { map.put(n, map.get(n) + 1); } else { map.put(n, 1); } // if (n > 0) { // // final String value = "" + n; // // if (map.containsKey(value)) // map.put(value, map.get(value) + 1); // else // map.put(value, 1); // // } // // Got response but no number identified // else if ((n == 0)) { // if (map.containsKey(ZERO)) // map.put(ZERO, map.get(ZERO) + 1); // else // map.put(ZERO, 1); // // } // // Directory, IOException, String out of bounds // else { // if (map.containsKey(ERROR)) // map.put(ERROR, map.get(ERROR) + 1); // else // map.put(ERROR, 1); // // } } dataset = new DefaultPieDataset(); final Iterator<Entry<String, Integer>> iter = map.entrySet().iterator(); while (iter.hasNext()) { final Map.Entry<String, Integer> entry = iter.next(); dataset.setValue(entry.getKey(), (double) entry.getValue() / (double) yData.length); } }