List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:com.pari.nm.modules.jobs.CompareDeviceConfigJob.java
private void populateGlobalDefinition() throws Exception { List<String> ostypeList = null; try {//w ww . java 2 s . c om ostypeList = GoldenConfigDBHelper.getDefinedOSTypes(); golbalDefinitionPerOS = new HashMap<String, JSONObject>(); for (String osType : ostypeList) { Map<String, HashMap<String, String>> golbalDefinition = new HashMap<String, HashMap<String, String>>(); GoldenConfigGlobalDefinitionInfo definitionInfo = GoldenConfigDBHelper .getGlobalDefinitionForOSType(osType); if (definitionInfo == null) { continue; } else { List<GlobalDefinitionInfo> globadefInfoList = definitionInfo.getGlobalDefinitions(); HashMap<String, String> definition = new HashMap<String, String>(); for (GlobalDefinitionInfo globadefInfo : globadefInfoList) { StringBuffer sb = null; if (definition.containsKey(globadefInfo.getDefnitionType().getType())) { sb = new StringBuffer(definition.get(globadefInfo.getDefnitionType().getType())); sb.append("|").append(globadefInfo.getPattern()); } else { sb = new StringBuffer(globadefInfo.getPattern()); } definition.put(globadefInfo.getDefnitionType().getType(), sb.toString()); } golbalDefinition.put(osType, definition); } golbalDefinitionPerOS.put(osType, populateGlobalDefsPerOs(golbalDefinition, osType)); } } catch (Exception e) { logger.error("Unable to load global definitions" + e); throw new Exception("Unable to load global definitions"); } }
From source file:Logic.mongoC.java
public void masInter(String usuario) { HashMap<String, String> conteo = new HashMap(); Document soloN = this.coll.find(eq("ScreenName", usuario)).first(); usuario regreso = this.gson.fromJson(soloN.getString("todo"), usuario.class); for (twitt t : regreso.getTimeline()) { Date d = t.getFecha();/* w ww .j a va 2 s . c o m*/ System.out.println(d.getDay()); for (String men : t.getPersonas()) { if (conteo.containsKey(men)) { int cl = Integer.valueOf(conteo.get(men)); cl++; conteo.put(men, String.valueOf(cl)); } else { conteo.put(men, "1"); } } } JFreeChart Grafica; DefaultCategoryDataset Datos = new DefaultCategoryDataset(); for (Map.Entry<String, String> entry : conteo.entrySet()) { String key = entry.getKey().toString(); Integer value = Integer.valueOf(entry.getValue()); Datos.addValue(value, usuario, key); System.out.println("KEY " + key + " vaue " + value); } Grafica = ChartFactory.createBarChart("Interacciones con usuarios", "Usuarios", "Numero de interacciones", Datos, PlotOrientation.VERTICAL, true, true, false); ChartPanel Panel = new ChartPanel(Grafica); JFrame Ventana = new JFrame("JFreeChart"); Ventana.getContentPane().add(Panel); Ventana.pack(); Ventana.setVisible(true); Ventana.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListPropertyWebappsController.java
@Override protected ResponseValues processRequest(VitroRequest vreq) { Map<String, Object> body = new HashMap<String, Object>(); try {//from www .ja v a 2s . co m body.put("displayOption", "all"); body.put("pageTitle", "All Object Properties"); body.put("propertyType", "object"); String noResultsMsgStr = "No object properties found"; String ontologyUri = vreq.getParameter("ontologyUri"); ObjectPropertyDao dao = vreq.getUnfilteredWebappDaoFactory().getObjectPropertyDao(); ObjectPropertyDao opDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getObjectPropertyDao(); PropertyInstanceDao piDao = vreq.getLanguageNeutralWebappDaoFactory().getPropertyInstanceDao(); VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao(); VClassDao vcDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao(); PropertyGroupDao pgDao = vreq.getUnfilteredWebappDaoFactory().getPropertyGroupDao(); String vclassURI = vreq.getParameter("vclassUri"); List<ObjectProperty> props = new ArrayList<ObjectProperty>(); if (vreq.getParameter("propsForClass") != null) { noResultsMsgStr = "There are no object properties that apply to this class."; // incomplete list of classes to check, but better than before List<String> superclassURIs = vcDao.getAllSuperClassURIs(vclassURI); superclassURIs.add(vclassURI); superclassURIs.addAll(vcDao.getEquivalentClassURIs(vclassURI)); Map<String, PropertyInstance> propInstMap = new HashMap<String, PropertyInstance>(); for (String classURI : superclassURIs) { Collection<PropertyInstance> propInsts = piDao.getAllPropInstByVClass(classURI); for (PropertyInstance propInst : propInsts) { propInstMap.put(propInst.getPropertyURI(), propInst); } } List<PropertyInstance> propInsts = new ArrayList<PropertyInstance>(); propInsts.addAll(propInstMap.values()); Collections.sort(propInsts); Iterator<PropertyInstance> propInstIt = propInsts.iterator(); HashSet<String> propURIs = new HashSet<String>(); while (propInstIt.hasNext()) { PropertyInstance pi = (PropertyInstance) propInstIt.next(); if (!(propURIs.contains(pi.getPropertyURI()))) { propURIs.add(pi.getPropertyURI()); ObjectProperty prop = (ObjectProperty) dao.getObjectPropertyByURI(pi.getPropertyURI()); if (prop != null) { props.add(prop); } } } } else { props = (vreq.getParameter("iffRoot") != null) ? dao.getRootObjectProperties() : dao.getAllObjectProperties(); } OntologyDao oDao = vreq.getUnfilteredWebappDaoFactory().getOntologyDao(); HashMap<String, String> ontologyHash = new HashMap<String, String>(); Iterator<ObjectProperty> propIt = props.iterator(); List<ObjectProperty> scratch = new ArrayList<ObjectProperty>(); while (propIt.hasNext()) { ObjectProperty p = propIt.next(); if (p.getNamespace() != null) { if (!ontologyHash.containsKey(p.getNamespace())) { Ontology o = oDao.getOntologyByURI(p.getNamespace()); if (o == null) { if (!VitroVocabulary.vitroURI.equals(p.getNamespace())) { log.debug( "doGet(): no ontology object found for the namespace " + p.getNamespace()); } } else { ontologyHash.put(p.getNamespace(), o.getName() == null ? p.getNamespace() : o.getName()); } } if (ontologyUri != null && p.getNamespace().equals(ontologyUri)) { scratch.add(p); } } } if (ontologyUri != null) { props = scratch; } if (props != null) { sortForPickList(props, vreq); } String json = new String(); int counter = 0; if (props != null) { if (props.size() == 0) { json = "{ \"name\": \"" + noResultsMsgStr + "\" }"; } else { Iterator<ObjectProperty> propsIt = props.iterator(); while (propsIt.hasNext()) { if (counter > 0) { json += ", "; } ObjectProperty prop = propsIt.next(); String propNameStr = ShowObjectPropertyHierarchyController.getDisplayLabel(prop); try { json += "{ \"name\": " + JSONUtils.quote("<a href='./propertyEdit?uri=" + URLEncoder.encode(prop.getURI()) + "'>" + propNameStr + "</a>") + ", "; } catch (Exception e) { json += "{ \"name\": \"" + propNameStr + "\", "; } json += "\"data\": { \"internalName\": " + JSONUtils.quote(prop.getLocalNameWithPrefix()) + ", "; ObjectProperty opLangNeut = opDaoLangNeut.getObjectPropertyByURI(prop.getURI()); if (opLangNeut == null) { opLangNeut = prop; } String domainStr = getVClassNameFromURI(opLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut); json += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", "; String rangeStr = getVClassNameFromURI(opLangNeut.getRangeVClassURI(), vcDao, vcDaoLangNeut); json += "\"rangeVClass\": " + JSONUtils.quote(rangeStr) + ", "; if (prop.getGroupURI() != null) { PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI()); json += "\"group\": " + JSONUtils.quote((pGroup == null) ? "unknown group" : pGroup.getName()) + " } } "; } else { json += "\"group\": \"unspecified\" } }"; } counter += 1; } } body.put("jsonTree", json); } } catch (Throwable t) { t.printStackTrace(); } return new TemplateResponseValues(TEMPLATE_NAME, body); }
From source file:com.krawler.spring.crm.common.ImportRecordAdvisor.java
private boolean BeforeSaveRecord(MethodInvocation mi) throws DataInvalidateException { boolean proceed = true; //public Object saveRecord(HttpServletRequest request, HashMap<String, Object> dataMap, CsvReader csvReader, String modeName, String classPath, String primaryKey) Object arguments[] = mi.getArguments(); String mode = (String) arguments[3]; try {//from w w w .j a va 2 s . c o m HashMap<String, Object> dataMap = (HashMap<String, Object>) arguments[1]; HashMap<String, Object> requestParams = (HashMap<String, Object>) arguments[0]; dataMap.put(Constants.Validflag, 2); if (!dataMap.containsKey("Createdon") || dataMap.get("Createdon") == null) { dataMap.put("Createdon", new Date()); } else if (StringUtil.isNullOrEmpty(dataMap.get("Createdon").toString())) { dataMap.put("Createdon", new Date()); } if (mode.equalsIgnoreCase("contact") && !StringUtil.isNullOrEmpty(requestParams.get("mapid").toString())) { if (!StringUtil.isNullOrEmpty(requestParams.get("relatedName").toString())) { if (requestParams.get("relatedName").toString().equals("Lead")) dataMap.put("Lead", requestParams.get("mapid").toString()); else dataMap.put("CrmAccount", requestParams.get("mapid").toString()); } } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); throw new DataInvalidateException("Failed to create account for " + mode + ": " + ex.getMessage()); } return proceed; }
From source file:info.staticfree.android.units.UnitUsageDBHelper.java
@SuppressWarnings("unchecked") private void addAll(JSONObject unitWeights, HashMap<String, Integer> allWeights) { for (final Iterator i = unitWeights.keys(); i.hasNext();) { final String key = (String) i.next(); if (allWeights.containsKey(key)) { allWeights.put(key, allWeights.get(key) + unitWeights.optInt(key)); } else {/*from www .j av a 2 s . co m*/ allWeights.put(key, unitWeights.optInt(key)); } } }
From source file:io.nats.connector.plugins.redis.RedisPubSubPlugin.java
private void addToMap(HashMap<String, List<String>> map, String key, String value) { List<String> l = null; if (map == null) return;/*from w ww . j a v a 2s . c o m*/ if (map.containsKey(key) == false) { l = new ArrayList<String>(); l.add(value); map.put(key, l); } else { l = map.get(key); // just silenly ignore duplicates. if (listContains(l, value)) return; l.add(value); } }
From source file:com.geometrycloud.happydonut.ui.ChartFilterPanel.java
/** * Carga la informacion para generar la grafica con el top de ventas. * * @param from desde donde buscar.//from w w w . j ava 2 s . com * @param to hasta donde buscar. * @return informacion de la grafica. */ private PieDataset chartDataset(LocalDate from, LocalDate to) { DefaultPieDataset dataset = new DefaultPieDataset(); RowList sales = DATABASE.table(SALES_TABLE_NAME).where(SALES_SALE_DATE, ">=", from.toString()) .where(SALES_SALE_DATE, "<=", to.toString()).get(SALES_PRIMARY_KEY, SALES_SALE_DATE); HashMap<String, Long> top = new HashMap<>(); for (Row sale : sales) { RowList details = DATABASE.table(SALE_DETAILS_TABLE_NAME) .where(SALE_DETAILS_SALE, "=", sale.value(SALES_PRIMARY_KEY)) .get(SALE_DETAILS_NAME, SALE_DETAILS_QUANTITY); String name; Long quantity; for (Row detail : details) { name = detail.string(SALE_DETAILS_NAME); quantity = detail.number(SALE_DETAILS_QUANTITY); if (top.containsKey(name)) { quantity += top.get(name); } top.put(name, quantity); } } top.forEach((k, v) -> dataset.setValue(k, v)); return dataset; }
From source file:com.gisgraphy.test.GisgraphyTestHelper.java
/** * Note : if there is more than one parameter with the same name, The last * one will be put in the map/*w w w. j av a2s . com*/ * * @param completeURL * the URL to split * @param andSign * the string representing and sign ('&' or '&') * @return an hashmap<paramName, paramValue> for the URL parameter */ public static HashMap<String, List<String>> splitURLParams(String completeURL, String andSign) { int i; HashMap<String, List<String>> searchparms = new HashMap<String, List<String>>(); ; logger.debug("Complete URL: " + completeURL); i = completeURL.indexOf("?"); if (i > -1) { String searchURL = completeURL.substring(completeURL.indexOf("?") + 1); logger.debug("Search URL: " + searchURL); String[] paramArray = searchURL.split(andSign); for (int c = 0; c < paramArray.length; c++) { String[] paramSplited = paramArray[c].split("="); try { if (!searchparms.containsKey(paramSplited[0])) { searchparms.put(paramSplited[0], new ArrayList<String>()); } searchparms.get(paramSplited[0]) .add(java.net.URLDecoder.decode(paramSplited[1], Constants.CHARSET)); } catch (UnsupportedEncodingException e) { return new HashMap<String, List<String>>(); } } // dumpHashtable; java.util.Iterator<String> keys = searchparms.keySet().iterator(); logger.debug("--------"); while (keys.hasNext()) { String s = (String) keys.next(); logger.debug(s + " : " + searchparms.get(s)); } logger.debug("--------"); } return searchparms; }
From source file:com.sonicle.webtop.contacts.io.input.ContactTextFileReader.java
protected void readRow(HashMap<String, Integer> columnIndexes, BeanHandler beanHandler, int row, List<String> rowValues) throws Exception { final LogEntries log = new LogEntries(); Contact contact = null;// w w w. ja v a 2 s. c o m try { final LogEntries ilog = new LogEntries(); contact = new Contact(); for (FileRowsReader.FieldMapping mapping : mappings) { if (StringUtils.isBlank(mapping.source)) continue; if (!columnIndexes.containsKey(mapping.source)) throw new Exception("Index not found"); Integer index = columnIndexes.get(mapping.source); fillContactByMapping(contact, mapping.target, rowValues.get(index)); } if (contact.trimFieldLengths()) { ilog.add(new MessageLogEntry(LogEntry.Level.WARN, "Some fields were truncated due to max-length")); } if (!ilog.isEmpty()) { log.addMaster(new MessageLogEntry(LogEntry.Level.WARN, "ROW [{0}]", row + 1)); log.addAll(ilog); } } catch (Throwable t) { log.addMaster( new MessageLogEntry(LogEntry.Level.ERROR, "ROW [{0}]. Reason: {1}", row + 1, t.getMessage())); } finally { beanHandler.handle(new ContactInput(contact), log); } }
From source file:eu.optimis.mi.monitoring_manager.resources.MonitorManagerQueryResource.java
@GET @Path("group/complete/service/{serviceId}") @Produces({ MediaType.APPLICATION_XML }) public MonitoringResourceDatasets getLatestCompleteServiceResource(@PathParam("serviceId") String serviceId) { MonitoringResourceDatasets smrs = getGroupTypeLevelResource("service", serviceId); HashMap<String, String> hmap = new HashMap<String, String>(); for (int i = 0; i < smrs.getMonitoring_resource().size(); i++) { String virtualId = smrs.getMonitoring_resource().get(i).getVirtual_resource_id(); String physicalId = smrs.getMonitoring_resource().get(i).getPhysical_resource_id(); if (!hmap.containsKey(virtualId)) hmap.put(virtualId, physicalId); }/*from w w w. j a v a2 s . com*/ MonitoringResourceDatasets virtualSets = new MonitoringResourceDatasets(); MonitoringResourceDatasets physicalSets = new MonitoringResourceDatasets(); MonitoringResourceDatasets energySets = new MonitoringResourceDatasets(); for (String key : hmap.keySet()) { String value = hmap.get(key); MonitoringResourceDatasets vmrs = getGroupTypeLevelResource("virtual", key); if (vmrs.getMonitoring_resource().size() > 0) { virtualSets.getMonitoring_resource().addAll(vmrs.getMonitoring_resource()); MonitoringResourceDatasets pmrs = getGroupTypeLevelResource("physical", value); physicalSets.getMonitoring_resource().addAll(pmrs.getMonitoring_resource()); MonitoringResourceDatasets emrs = getGroupTypeLevelResource("energy", value); energySets.getMonitoring_resource().addAll(emrs.getMonitoring_resource()); } } MonitoringResourceDatasets returnedDataSet = new MonitoringResourceDatasets(); List<MonitoringResourceDataset> mrList = new ArrayList<MonitoringResourceDataset>(); mrList.addAll(smrs.getMonitoring_resource()); mrList.addAll(physicalSets.getMonitoring_resource()); mrList.addAll(energySets.getMonitoring_resource()); mrList.addAll(virtualSets.getMonitoring_resource()); returnedDataSet.setMonitoring_resource(mrList); return returnedDataSet; }