List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:com.liteoc.domain.rule.RuleSetRuleBean.java
@Transient public HashMap<String, ArrayList<String>> getActionsAsKeyPair(String actionEvaluatesTo) { HashMap<String, ArrayList<String>> h = new HashMap<String, ArrayList<String>>(); for (RuleActionBean action : actions) { String key = action.getExpressionEvaluatesTo().toString(); if (actionEvaluatesTo.equals(key)) { if (h.containsKey(key)) { h.get(key).add(action.getSummary()); } else { ArrayList<String> a = new ArrayList<String>(); a.add(action.getSummary()); h.put(key, a);/*ww w .j a va 2s . c om*/ } } } return h; }
From source file:org.xbib.elasticsearch.index.analysis.langdetect.LangdetectService.java
/** * Set prior information about language probabilities. * * @param priorMap the priorMap to set// ww w . j a v a 2 s .c om * @throws LanguageDetectionException */ public void setPriorMap(HashMap<String, Double> priorMap) throws LanguageDetectionException { this.priorMap = new double[langlist.size()]; double sump = 0; for (int i = 0; i < this.priorMap.length; ++i) { String lang = langlist.get(i); if (priorMap.containsKey(lang)) { double p = priorMap.get(lang); if (p < 0) { throw new LanguageDetectionException("Prior probability must be non-negative"); } this.priorMap[i] = p; sump += p; } } if (sump <= 0) { throw new LanguageDetectionException("More one of prior probability must be non-zero"); } for (int i = 0; i < this.priorMap.length; ++i) { this.priorMap[i] /= sump; } }
From source file:annis.gui.flatquerybuilder.SearchBox.java
@Override public void textChange(TextChangeEvent event) { if ("specific".equals(sq.getFilterMechanism())) { ConcurrentSkipListSet<String> notInYet = new ConcurrentSkipListSet<String>(); reducingStringComparator esc = new reducingStringComparator(); String txt = event.getText(); if (!txt.equals("")) { cb.removeAllItems();//from w ww . ja va2 s .c o m for (Iterator<String> it = annonames.iterator(); it.hasNext();) { String s = it.next(); if (esc.compare(s, txt) == 0) { cb.addItem(s); } else { notInYet.add(s); } } //startsWith for (String s : notInYet) { if (esc.startsWith(s, txt)) { cb.addItem(s); notInYet.remove(s); } } //contains for (String s : notInYet) { if (esc.contains(s, txt)) { cb.addItem(s); } } } else { //have a look and speed it up SpanBox.buildBoxValues(cb, ebene, sq); } } if ("levenshtein".equals(sq.getFilterMechanism())) { String txt = event.getText(); HashMap<Integer, Collection> levdistvals = new HashMap<Integer, Collection>(); if (txt.length() > 1) { cb.removeAllItems(); for (String s : annonames) { Integer d = StringUtils.getLevenshteinDistance(removeAccents(txt), removeAccents(s)); if (levdistvals.containsKey(d)) { levdistvals.get(d).add(s); } if (!levdistvals.containsKey(d)) { Set<String> newc = new TreeSet<String>(); newc.add(s); levdistvals.put(d, newc); } } SortedSet<Integer> keys = new TreeSet<Integer>(levdistvals.keySet()); for (Integer k : keys.subSet(0, 5)) { List<String> values = new ArrayList(levdistvals.get(k)); Collections.sort(values, String.CASE_INSENSITIVE_ORDER); for (String v : values) { cb.addItem(v); } } } } }
From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.DockerMounts.java
private static Map<String, String> lineToMap(String line) { final HashMap<String, String> map = new HashMap<>(); final String[] properties = line.split(","); for (String property : properties) { if (stripToEmpty(property).toLowerCase().equals("readonly")) { map.put("readOnly", "true"); } else if (property.contains("=")) { final String[] parts = property.split("=", 2); switch (stripToEmpty(parts[0]).toLowerCase()) { case "type": map.put("type", stripToEmpty(parts[1])); break; case "source": case "src": map.put("source", stripToEmpty(parts[1])); break; case "target": case "destination": case "dst": map.put("target", stripToEmpty(parts[1])); break; default: throw new RuntimeException(format( "Invalid mount specification `{0}`. Option `{1}` not implemented.", line, parts[0])); }//from ww w . j ava2s. c o m } else { throw new RuntimeException( format("Invalid mount specification `{0}`. Option `{1}` not implemented.", line, property)); } } final List<String> mountTypes = Arrays.asList("bind", "volume"); if (map.containsKey("type") && mountTypes.stream().noneMatch(map.get("type")::contains)) { throw new RuntimeException(format( "Invalid mount type specification `{0}`. Available options are `{1}`.", line, mountTypes)); } if (map.containsKey("type") && map.get("type").equals("bind") && isBlank(map.get("source"))) { throw new RuntimeException(format( "Invalid mount source specification `{0}`. Bind mounts have to specify `source`.", line)); } if (isBlank(map.get("target"))) { throw new RuntimeException( format("Invalid mount target specification `{0}`. `target` has to be specified.", line)); } return map; }
From source file:org.dataconservancy.ui.services.EZIDServiceIT.java
/** * Tests that an ID can be saved without exception. Tests that the status is changed from pending to reserved. * @throws IOException /*from w w w .j a v a2s . c o m*/ * @throws ClientProtocolException */ @Test public void testSave() throws ClientProtocolException, IOException { boolean caughtException = false; String id = ""; HttpGet getID = null; String target = ""; try { id = ezidService.createID(ezidMetadata); 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")); assertTrue(metadata.containsKey("_target")); target = metadata.get("_target"); ezidService.saveID(id); } catch (EZIDServiceException e) { caughtException = true; } assertFalse(caughtException); 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("public", metadata.get("_status")); //Make sure other metadata hasn't changed assertTrue(metadata.containsKey("_target")); assertEquals(target, metadata.get("_target")); }
From source file:com.compomics.util.experiment.identification.psm_scoring.psm_scores.HyperScore.java
/** * Returns the interpolation of a list of hyperscores using a linear * interpolation of the form result = a * log(score) + b. If the score is * null, returns the number of hyperscores. The value at every score is * returned in a map./*from www . j a v a 2 s . c o m*/ * * @param hyperScores a list of hyperscores * @param a the slope of the interpolation * @param b the offset of the interpolation * * @return the interpolation for every score in a map. */ public HashMap<Double, Double> getInterpolation(ArrayList<Double> hyperScores, Double a, Double b) { HashMap<Double, Double> result = new HashMap<Double, Double>(); for (Double hyperScore : hyperScores) { if (!result.containsKey(hyperScore)) { if (hyperScore > 0) { double logScore = FastMath.log10(hyperScore); double eValue = getInterpolation(logScore, a, b); result.put(hyperScore, eValue); } else { Double eValue = new Double(hyperScores.size()); result.put(hyperScore, eValue); } } } return result; }
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. *///from w ww . j ava 2 s. c o m 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:net.certiv.authmgr.task.section.core.classifier.BayesPartitionClassifier.java
/** * Gets the training count for single partition within a given category. * /*ww w . ja va 2 s. c om*/ * @param category * @param partition * @return */ @SuppressWarnings("rawtypes") private int getTrainingCount(String category, String partition) { if (categoryCounter.containsKey(category)) { HashMap partitionCounter = categoryCounter.get(category); if (partitionCounter.containsKey(partition)) { return ((Integer) partitionCounter.get(partition)).intValue(); } } return 0; }
From source file:com.unister.semweb.drums.bucket.hashfunction.RangeHashFunction.java
/** * generates the correct index structure, namely the bucketIds to the already initialized filenames and * maxRangeValues/* w w w.j a va 2s. co m*/ */ private void generateBucketIds() { // generate indexes for buckets, needed if two different ranges belong to the same file this.buckets = 0; bucketIds = new int[filenames.length]; HashMap<String, Integer> tmpSeenFilenames = new HashMap<String, Integer>(); for (int i = 0; i < filenames.length; i++) { if (!tmpSeenFilenames.containsKey(filenames[i])) { tmpSeenFilenames.put(filenames[i], this.buckets++); } bucketIds[i] = tmpSeenFilenames.get(filenames[i]); } this.buckets = bucketIds.length; }
From source file:it.iit.genomics.cru.simsearch.bundle.utils.AnnotationsFromTrack.java
private void increase(HashMap<String, Integer> annotationsCount1, String annotation) { if (annotationsCount1.containsKey(annotation)) { annotationsCount1.put(annotation, annotationsCount1.get(annotation) + 1); } else {//from w w w .j a v a2s . c o m annotationsCount1.put(annotation, 1); } }