List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:epsi.i5.datamining.Treatment.java
/** * Main treatment//from ww w .j av a 2s . c om * * @param file * @throws IOException * @throws MalformedURLException * @throws RepustateException * @throws ParseException */ public void treatment(File file) throws IOException, MalformedURLException, RepustateException, ParseException { boolean bStopWord; for (DataEntity entity : builder.getFullCommentaires(file)) { fillCatMap(entity); entity.setCommentaireTrie(sortComment(entity)); dataEnter.add(entity); } //Recherche de la valeur max de chaque mots for (String word : words) { Integer max = 0; for (Entry entry : mapCategorie.entrySet()) { HashMap mapDonnee = (HashMap) entry.getValue(); if (mapDonnee.containsKey(word)) { if (max < (Integer) mapDonnee.get(word)) { max = (Integer) mapDonnee.get(word); } } } //Suppression des mots si ce n'est pas la valeur max for (Entry entry : mapCategorie.entrySet()) { HashMap mapDonnee = (HashMap) entry.getValue(); if (mapDonnee.get(word) != max) { mapDonnee.remove(word); } entry.setValue(mapDonnee); } } List<DataEntity> commentairesFinaux = builder.getSimpleCommentaires(file); for (DataEntity commentaire : commentairesFinaux) { List<String> categorie; for (String word : commentaire.getCommentaires().split(" ")) { //System.out.println(stopword.getRegEx()); word = useStopWords(word); bStopWord = checkStopWords(word); if (bStopWord == false) { for (Entry entry : mapCategorie.entrySet()) { HashMap mapDonnee = (HashMap) entry.getValue(); if (mapDonnee.containsKey(word) && !"".equals(word)) { categorie = commentaire.getListeCategorie(); if (!categorie.contains((String) entry.getKey())) { categorie.add((String) entry.getKey()); } commentaire.setListeCategorie(categorie); } } } } dataExit.add(commentaire); } calculAllpolarite(); for (int i = 0; i < dataExit.size(); i++) { System.out.println("Expected : " + dataEnter.get(i).getListeCategorie()); System.out.println("Found : " + dataExit.get(i).getListeCategorie()); if (dataEnter.get(i).getListeCategorie().containsAll(dataExit.get(i).getListeCategorie())) { System.out.println("Consistency : " + true); fiabilite++; } else { System.out.println("Consistency : " + false); } System.out.println("Raiting : " + polarites.get(i)); System.out.println("****************************"); } System.out.println("****************************"); fiabilite = (fiabilite * 100) / dataExit.size(); if (fiabilite != 100) { System.err.println("Success rate : " + fiabilite + "%"); } else { System.out.println("Success rate : " + fiabilite + "%"); } }
From source file:org.sakaiproject.tool.assessment.ui.listener.author.SaveAssessmentSettings.java
public void updateAttachment(List oldList, List newList, AssessmentIfc assessment, boolean isAuthorSettings) { if ((oldList == null || oldList.size() == 0) && (newList == null || newList.size() == 0)) return;/*from ww w . java2 s . c om*/ List list = new ArrayList(); HashMap map = getAttachmentIdHash(oldList); for (int i = 0; i < newList.size(); i++) { AssessmentAttachmentIfc a = (AssessmentAttachmentIfc) newList.get(i); if (map.get(a.getAttachmentId()) != null) { // exist already, remove it from map map.remove(a.getAttachmentId()); } else { // new attachments a.setAssessment(assessment); list.add(a); } } // save new ones AssessmentService assessmentService = null; if (isAuthorSettings) { assessmentService = new AssessmentService(); } else { assessmentService = new PublishedAssessmentService(); } assessmentService.saveOrUpdateAttachments(list); // remove old ones Set set = map.keySet(); Iterator iter = set.iterator(); while (iter.hasNext()) { Long attachmentId = (Long) iter.next(); assessmentService.removeAssessmentAttachment(attachmentId.toString()); } }
From source file:cr.ac.siua.tec.utils.impl.ConstancyPDFGenerator.java
/** * Fills the PDF file (constancia.pdf) with the ticket values and returns base64 encoded string. *///w w w . j av a 2 s. c o m @Override public String generate(HashMap<String, String> formValues) { String originalPdf = PDFGenerator.RESOURCES_PATH + "constancia.pdf"; try { PDDocument _pdfDocument = PDDocument.load(originalPdf); PDDocumentCatalog docCatalog = _pdfDocument.getDocumentCatalog(); PDAcroForm acroForm = docCatalog.getAcroForm(); //Set some fields manually. Calendar cal = Calendar.getInstance(); int day = cal.get(Calendar.DAY_OF_MONTH); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); String date = String.valueOf(day) + " de " + monthsMap.get(month) + " del ao " + String.valueOf(year) + "."; acroForm.getField("Fecha").setValue(date); formValues.remove("Queue"); formValues.remove("Motivo"); formValues.remove("Requestors"); //Iterates through remaining custom fields. for (Map.Entry<String, String> entry : formValues.entrySet()) { acroForm.getField(entry.getKey()).setValue(entry.getValue()); } return encodePDF(_pdfDocument); } catch (IOException e) { e.printStackTrace(); System.out.println("Excepcin al llenar el PDF."); return null; } }
From source file:org.openspaces.maven.plugin.CreatePUProjectMojo.java
/** * Returns an array of available project templates names. *//*from www . jav a 2s .co m*/ private HashMap getAvailableTemplates() throws Exception { HashMap templates = new HashMap(); Enumeration urls = Thread.currentThread().getContextClassLoader().getResources(DIR_TEMPLATES); while (urls.hasMoreElements()) { URL url = (URL) urls.nextElement(); PluginLog.getLog().debug("retrieving all templates from url: " + url); HashMap jarTemplates = getJarTemplates(getJarURLFromURL(url, "")); templates.putAll(jarTemplates); } LinkedHashMap sortedTemplates = new LinkedHashMap(); String desc = (String) templates.remove("event-processing"); if (desc != null) { sortedTemplates.put("event-processing", desc); } desc = (String) templates.remove("persistent-event-processing"); if (desc != null) { sortedTemplates.put("persistent-event-processing", desc); } sortedTemplates.putAll(templates); return sortedTemplates; }
From source file:org.dbpedia.spotlight.lucene.index.external.SSEResidualKnowledgeBaseBuilder.java
public LinkedHashMap sortHashMap(HashMap passedMap) { List mapKeys = new ArrayList(passedMap.keySet()); List mapValues = new ArrayList(passedMap.values()); Collections.sort(mapValues);/*from w ww. j a va 2s. c om*/ Collections.reverse(mapValues); Collections.sort(mapKeys); LinkedHashMap sortedMap = new LinkedHashMap(); Iterator valueIt = mapValues.iterator(); while (valueIt.hasNext()) { Object val = valueIt.next(); Iterator keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { Object key = keyIt.next(); String comp1 = passedMap.get(key).toString(); String comp2 = val.toString(); if (comp1.equals(comp2)) { passedMap.remove(key); mapKeys.remove(key); sortedMap.put((String) key, (Integer) val); break; } } } return sortedMap; }
From source file:nz.co.fortytwo.freeboard.server.NMEAProcessor.java
public HashMap<String, Object> handle(HashMap<String, Object> map) { // so we have a string String bodyStr = (String) map.get(Constants.NMEA); if (StringUtils.isNotBlank(bodyStr)) { try {/* w w w . j a va 2 s . co m*/ if (logger.isDebugEnabled()) { logger.debug("Processing NMEA:" + bodyStr); } // dont need the NMEA now map.remove(Constants.NMEA); Sentence sentence = SentenceFactory.getInstance().createParser(bodyStr); fireSentenceEvent(map, sentence); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } logger.error(e.getMessage() + " : " + bodyStr); } } return map; }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java
/** * Loads the remote tasks from the database and merges the two lists. If the * remote list contains all items, then this method only adds local db-ids * to the items. If it does not contain all of them, this loads whatever * extra items are known in the db to the list also. *//* ww w. j a va 2 s. c om*/ public static void mergeTasksWithLocalDB(final Context context, final String account, final List<GoogleTask> remoteTasks, long listDbId) { final HashMap<String, GoogleTask> localVersions = new HashMap<String, GoogleTask>(); final Cursor c = context.getContentResolver().query(GoogleTask.URI, GoogleTask.Columns.FIELDS, GoogleTask.Columns.LISTDBID + " IS ? AND " + GoogleTask.Columns.ACCOUNT + " IS ? AND " + GoogleTask.Columns.SERVICE + " IS ?", new String[] { Long.toString(listDbId), account, GoogleTaskList.SERVICENAME }, null); try { while (c.moveToNext()) { GoogleTask task = new GoogleTask(c); localVersions.put(task.remoteId, task); } } finally { if (c != null) c.close(); } for (final GoogleTask task : remoteTasks) { // Set list on remote objects task.listdbid = listDbId; // Merge with hashmap if (localVersions.containsKey(task.remoteId)) { task.dbid = localVersions.get(task.remoteId).dbid; task.setDeleted(localVersions.get(task.remoteId).isDeleted()); if (task.isDeleted()) { Log.d(TAG, "merge1: deleting " + task.title); } localVersions.remove(task.remoteId); } } // Remaining ones for (final GoogleTask task : localVersions.values()) { remoteTasks.add(task); if (task.isDeleted()) { Log.d(TAG, "merge2: was deleted " + task.title); } } }
From source file:org.akita.proxy.ProxyInvocationHandler.java
/** * Replace all the {} block in url to the actual params, * clear the params used in {block}, return cleared params HashMap and replaced url. * @param url such as http://server/{namespace}/1/do * @param params such as hashmap include (namespace->'mobile') * @return the parsed param will be removed in HashMap (params) *//* www.j a va2 s . c om*/ private String parseUrlbyParams(String url, HashMap<String, String> params) throws AkInvokeException { StringBuffer sbUrl = new StringBuffer(); Pattern pattern = Pattern.compile("\\{(.+?)\\}"); Matcher matcher = pattern.matcher(url); while (matcher.find()) { String paramValue = params.get(matcher.group(1)); if (paramValue != null) { matcher.appendReplacement(sbUrl, paramValue); } else { // {name}? throw new AkInvokeException(AkInvokeException.CODE_PARAM_IN_URL_NOT_FOUND, "Parameter {" + matcher.group(1) + "}'s value not found of url " + url + "."); } params.remove(matcher.group(1)); } matcher.appendTail(sbUrl); return sbUrl.toString(); }
From source file:com.app.server.util.ClassLoaderUtil.java
public static boolean cleanupJarFileFactory(CopyOnWriteArrayList setJarFileNames2Close) { boolean res = false; Class classJarURLConnection = null; try {/* ww w .jav a2s . c o m*/ classJarURLConnection = Class.forName("sun.net.www.protocol.jar.JarURLConnection"); } catch (ClassNotFoundException e) { e.printStackTrace(); } if (classJarURLConnection == null) { return res; } Field f = null; try { f = classJarURLConnection.getDeclaredField("factory"); } catch (NoSuchFieldException e) { e.printStackTrace(); } if (f == null) { return res; } f.setAccessible(true); Object obj = null; try { obj = f.get(null); } catch (IllegalAccessException e) { // ignore } if (obj == null) { return res; } Class classJarFileFactory = obj.getClass(); // HashMap fileCache = null; try { f = classJarFileFactory.getDeclaredField("fileCache"); f.setAccessible(true); obj = f.get(null); if (obj instanceof HashMap) { fileCache = (HashMap) obj; } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } HashMap urlCache = null; try { f = classJarFileFactory.getDeclaredField("urlCache"); f.setAccessible(true); obj = f.get(null); if (obj instanceof HashMap) { urlCache = (HashMap) obj; } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } if (urlCache != null) { HashMap urlCacheTmp = (HashMap) urlCache.clone(); Iterator it = urlCacheTmp.keySet().iterator(); while (it.hasNext()) { obj = it.next(); if (!(obj instanceof JarFile)) { continue; } JarFile jarFile = (JarFile) obj; if (setJarFileNames2Close.contains(jarFile.getName().trim().toUpperCase())) { try { jarFile.close(); } catch (IOException e) { e.printStackTrace(); } if (fileCache != null) { fileCache.remove(jarFile); } urlCache.remove(jarFile); } } res = true; } else if (fileCache != null) { // urlCache := null HashMap fileCacheTmp = (HashMap) fileCache.clone(); Iterator it = fileCacheTmp.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); obj = fileCache.get(key); if (!(obj instanceof JarFile)) { continue; } JarFile jarFile = (JarFile) obj; try { jarFile.close(); } catch (IOException e) { // ignore } fileCache.remove(key); } res = true; } setJarFileNames2Close.clear(); return res; }
From source file:org.apache.nutch.admin.scheduling.FileJobStore.java
public boolean removeJob(SchedulingContext ctxt, String jobName, String groupName) throws JobPersistenceException { JobDetail job = (JobDetail) this.fJobsByName.get(getFullName(groupName, jobName)); if (job == null) { return false; }/*from w w w . j a va2 s.c om*/ Trigger[] triggers = getTriggersForJob(ctxt, jobName, groupName); for (int i = 0; i < triggers.length; i++) { removeTrigger(ctxt, triggers[i].getName(), triggers[i].getGroup()); } synchronized (this.fJobsByName) { HashMap groupMap = (HashMap) this.fJobsByGroup.get(groupName); if (groupMap != null) { groupMap.remove(jobName); if (groupMap.size() == 0) { this.fJobsByGroup.remove(groupName); } } this.fJobsByName.remove(job.getFullName()); this.fBlockedJobs.remove(job); this.fSerializer.saveJobs(this.fJobsByName); } return true; }