List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:com.thoughtworks.go.domain.scm.SCMs.java
private void validateNameUniqueness() { HashMap<String, SCMs> map = new HashMap<>(); for (SCM scm : this) { String name = scm.getName().toLowerCase(); if (!map.containsKey(name)) { map.put(name, new SCMs()); }/*from www . ja va2s .c o m*/ map.get(name).add(scm); } for (String name : map.keySet()) { SCMs scmsWithSameName = map.get(name); if (scmsWithSameName.size() > 1) { for (SCM scm : scmsWithSameName) { scm.addError(SCM.NAME, String.format( "Cannot save SCM, found multiple SCMs called '%s'. SCM names are case-insensitive and must be unique.", scm.getName())); } } } }
From source file:com.thoughtworks.go.domain.scm.SCMs.java
private void validateFingerprintUniqueness() { HashMap<String, SCMs> map = new HashMap<>(); for (SCM scm : this) { String fingerprint = scm.getFingerprint(); if (!map.containsKey(fingerprint)) { map.put(fingerprint, new SCMs()); }/*from w w w. ja v a2 s . com*/ map.get(fingerprint).add(scm); } for (String fingerprint : map.keySet()) { SCMs scmsWithSameFingerprint = map.get(fingerprint); if (scmsWithSameFingerprint.size() > 1) { List<String> scmNames = new ArrayList<>(); for (SCM scm : scmsWithSameFingerprint) { scmNames.add(scm.getName()); } for (SCM scm : scmsWithSameFingerprint) { scm.addError(SCM.SCM_ID, String.format("Cannot save SCM, found duplicate SCMs. %s", StringUtils.join(scmNames, ", "))); } } } }
From source file:org.craftercms.social.repositories.system.impl.ContextPreferencesRepositoryImpl.java
@Override public Map<String, String> findEmailPreference(final String contextId) throws SocialException { try {//from ww w . jav a 2s.co m String query = getQueryFor("social.system.preferences.emailPreferencesByContextId"); final HashMap tmp = getCollection().findOne(query, contextId).projection("{email:1,_id:0}") .as(HashMap.class); if (tmp == null || !tmp.containsKey("email")) { throw new SocialException("Current context " + contextId + "is missing email configuration"); } return (Map) tmp.get("email"); } catch (MongoException ex) { throw new SocialException("Unable to read email preferences for " + contextId); } }
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
public static double FindWeightedAlignments(double probability, List<Production> productions, String word1, String word2, int maxSubstringLength1, int maxSubstringLength2, HashMap<Production, Double> probs, HashMap<Production, Double> weights, HashMap<Production, Pair<Double, Double>> memoizationTable) { if (word1.length() == 0 && word2.length() == 0) //record probabilities {//from w ww . jav a2 s . c om for (Production production : productions) { if (weights.containsKey(production) && weights.get(production) > probability) { continue; } else { weights.put(production, probability); } } return 1; } //Check memoization table to see if we can return early Pair<Double, Double> probPair; if (memoizationTable.containsKey(new Production(word1, word2))) { probPair = memoizationTable.get(new Production(word1, word2)); if (probPair.getFirst() >= probability) //we ran against these words with a higher probability before; { probability *= probPair.getSecond(); //get entire production sequence probability for (Production production : productions) { if (weights.containsKey(production) && weights.get(production) > probability) { continue; } else { weights.put(production, probability); } } return probPair.getSecond(); } } int maxSubstringLength1f = Math.min(word1.length(), maxSubstringLength1); int maxSubstringLength2f = Math.min(word2.length(), maxSubstringLength2); double bestProb = 0; for (int i = 1; i <= maxSubstringLength1f; i++) //for each possible substring in the first word... { String substring1 = word1.substring(0, i); for (int j = 1; j <= maxSubstringLength2f; j++) //for possible substring in the second { if ((word1.length() - i) * maxSubstringLength2 >= word2.length() - j && (word2.length() - j) * maxSubstringLength1 >= word1.length() - i) //if we get rid of these characters, can we still cover the remainder of word2? { String substring2 = word2.substring(0, j); Production production = new Production(substring1, substring2); double prob = probs.get(production); productions.add(production); double thisProb = prob * FindWeightedAlignments(probability * prob, productions, word1.substring(i), word2.substring(j), maxSubstringLength1, maxSubstringLength2, probs, weights, memoizationTable); productions.remove(productions.size() - 1); if (thisProb > bestProb) bestProb = thisProb; } } } memoizationTable.put(new Production(word1, word2), new Pair<>(probability, bestProb)); return bestProb; }
From source file:com.arsdigita.util.parameter.MapParameter.java
protected void doWrite(final ParameterWriter writer, final Object value) { final HashMap map = (HashMap) value; final Iterator params = m_params.iterator(); while (params.hasNext()) { final Parameter param = (Parameter) params.next(); if (map.containsKey(param)) { param.write(writer, map.get(param)); }//from w w w . jav a2s .co m } }
From source file:com.arsdigita.util.parameter.MapParameter.java
protected void doValidate(final Object value, final ErrorList errors) { final HashMap map = (HashMap) value; final Iterator params = m_params.iterator(); while (params.hasNext()) { final Parameter param = (Parameter) params.next(); if (map.containsKey(param)) { param.validate(map.get(param), errors); } else {//from w w w. j av a 2 s . co m param.validate(param.getDefaultValue(), errors); } } }
From source file:it.cnr.icar.eric.server.interfaces.common.SessionManager.java
@SuppressWarnings("static-access") private boolean createHttpSession(Object message) throws RegistryException { boolean createSession = false; try {//from www .ja v a 2s.c o m if (message instanceof RegistryRequestType) { RegistryRequestType req = (RegistryRequestType) message; HashMap<String, Object> slotsMap = bu.getSlotsFromRequest(req); if (slotsMap.containsKey(bu.IMPL_SLOT_CREATE_HTTP_SESSION)) { String val = (String) slotsMap.get(bu.IMPL_SLOT_CREATE_HTTP_SESSION); if (val.trim().equalsIgnoreCase("true")) { createSession = true; } } } } catch (JAXBException e) { throw new RegistryException(e); } return createSession; }
From source file:edu.stanford.slac.archiverappliance.PBOverHTTP.PBOverHTTPStoragePlugin.java
@Override public void initialize(String configURL, ConfigService configService) throws IOException { try {// w w w. j a va 2 s .com URI srcURI = new URI(configURL); HashMap<String, String> queryNVPairs = URIUtils.parseQueryString(srcURI); if (queryNVPairs.containsKey("rawURL")) { this.setAccessURL(queryNVPairs.get("rawURL")); } else { throw new IOException( "Cannot initialize the pbraw plugin; this needs the URL to the engine/Raw over HTTP to be specified " + configURL); } if (queryNVPairs.containsKey("name")) { name = queryNVPairs.get("name"); } else { name = new URL(this.getAccessURL()).getHost(); logger.debug("Using the default name of " + name + " for this plain pb engine"); } if (queryNVPairs.containsKey("skipExternalServers")) { logger.debug( "Telling the remote server to skip all data from external (potentially ChannelArchiver) servers"); this.skipExternalServers = Boolean.parseBoolean(queryNVPairs.get("skipExternalServers")); } } catch (URISyntaxException ex) { throw new IOException(ex); } }
From source file:com.esri.ges.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 www . jav a 2 s . 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); int geometryID = geoEvent.getGeoEventDefinition().getGeometryId(); geoEvent.setField(geometryID, point.toJson()); break; } } catch (Exception ex) { LOG.warn("Error wile trying to parse the GeoEvent field " + fieldName + ":" + fieldValue, ex); } } } queue.add(geoEvent); } }
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
/** * Helper function.//from ww w . j a v a2 s. co m * @param word1 * @param maxSubstringLength * @param probMap * @param probs * @param memoizationTable * @param pruneToSize * @return */ public static HashMap<String, Double> Predict2(String word1, int maxSubstringLength, Map<String, HashSet<String>> probMap, HashMap<Production, Double> probs, HashMap<String, HashMap<String, Double>> memoizationTable, int pruneToSize) { HashMap<String, Double> result; if (word1.length() == 0) { result = new HashMap<>(1); result.put("", 1.0); return result; } if (memoizationTable.containsKey(word1)) { return memoizationTable.get(word1); } result = new HashMap<>(); int maxSubstringLength1 = Math.min(word1.length(), maxSubstringLength); for (int i = 1; i <= maxSubstringLength1; i++) { String substring1 = word1.substring(0, i); if (probMap.containsKey(substring1)) { // recursion right here. HashMap<String, Double> appends = Predict2(word1.substring(i), maxSubstringLength, probMap, probs, memoizationTable, pruneToSize); //int segmentations = Segmentations( word1.Length - i ); for (String tgt : probMap.get(substring1)) { Production alignment = new Production(substring1, tgt); double alignmentProb = probs.get(alignment); for (String key : appends.keySet()) { Double value = appends.get(key); String word = alignment.getSecond() + key; //double combinedProb = (pair.Value/segmentations) * alignmentProb; double combinedProb = (value) * alignmentProb; // I hope this is an accurate translation... Dictionaries.IncrementOrSet(result, word, combinedProb, combinedProb); } } } } if (result.size() > pruneToSize) { Double[] valuesArray = result.values().toArray(new Double[result.values().size()]); String[] data = result.keySet().toArray(new String[result.size()]); //Array.Sort<Double, String> (valuesArray, data); TreeMap<Double, String> sorted = new TreeMap<>(); for (int i = 0; i < valuesArray.length; i++) { sorted.put(valuesArray[i], data[i]); } // FIXME: is this sorted in the correct order??? //double sum = 0; //for (int i = data.Length - pruneToSize; i < data.Length; i++) // sum += valuesArray[i]; result = new HashMap<>(pruneToSize); // for (int i = data.length - pruneToSize; i < data.length; i++) // result.put(data[i], valuesArray[i]); int i = 0; for (Double d : sorted.descendingKeySet()) { result.put(sorted.get(d), d); if (i++ > pruneToSize) { break; } } } memoizationTable.put(word1, result); return result; }