List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:android.databinding.tool.store.SetterStore.java
private static <K, V> void merge(HashMap<K, HashMap<V, MethodDescription>> first, HashMap<K, HashMap<V, MethodDescription>> second) { for (K key : second.keySet()) { HashMap<V, MethodDescription> firstVals = first.get(key); HashMap<V, MethodDescription> secondVals = second.get(key); if (firstVals == null) { first.put(key, secondVals);/*from w ww .ja v a 2 s .c o m*/ } else { for (V key2 : secondVals.keySet()) { if (!firstVals.containsKey(key2)) { firstVals.put(key2, secondVals.get(key2)); } } } } }
From source file:LoginUI.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) throws ParseException { HashMap<String, String> userpw = getUserInfo(); String inputuser = jTextField1.getText(); char[] inputpw = jTextField2.getPassword(); String pw = new String(inputpw); //wrong username if (!userpw.containsKey(inputuser)) { JOptionPane.showMessageDialog(null, "Username does not exist!", "Failed", JOptionPane.ERROR_MESSAGE); }/*from w w w . ja v a 2 s. co m*/ // wrong password else if (!userpw.get(inputuser).equals(pw)) { JOptionPane.showMessageDialog(null, "Incorrect Password", "Failed", JOptionPane.ERROR_MESSAGE); } else { MainGUI main = new MainGUI(inputuser); JOptionPane.showMessageDialog(null, "Login Successful!", "Success!", JOptionPane.INFORMATION_MESSAGE); WindowEvent winClosingEvent = new WindowEvent(this, WindowEvent.WINDOW_CLOSING); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent); main.setVisible(true); } }
From source file:epsi.i5.datamining.Traitement.java
public void traitement() throws IOException, MalformedURLException, RepustateException, ParseException { StopWords stopword = new StopWords(); boolean bStopWord = false; for (DataEntity entity : builder.getFullCommentaires()) { if (entity.getListeCategorie() == null) { jsonSimpleCat.add(entity.getSimpleCategorie()); jsonListCat = null;/*from ww w . j av a2 s .com*/ } else { jsonListCat.add(entity.getListeCategorie()); jsonSimpleCat = null; } String lTrie = ""; if (entity.getSimpleCategorie() == null) { for (String cat : entity.getListeCategorie()) { if (!mapCategorie.containsKey(cat)) { mapCategorie.put(cat, new HashMap<String, Integer>()); } } } else { if (!mapCategorie.containsKey(entity.getSimpleCategorie())) { mapCategorie.put(entity.getSimpleCategorie(), new HashMap<String, Integer>()); } } for (String word : entity.getCommentaires().split(" ")) { //System.out.println(stopword.getRegEx()); for (String stopApo : stopword.getRegExApos().replace("|", " ").split(" ")) { word = word.replaceAll(stopApo, ""); // System.out.println(stopApo); } word = word.replace(".", " ").replace(",", " ").replace("!", " ").replace("(", "").replace(")", "") .replace("'", "").replace(":", "").trim(); for (String stop : stopword.getRegEx().replace("|", " ").split(" ")) { //System.out.println(stop); if ((word.equalsIgnoreCase(stop)) && !word.equalsIgnoreCase("")) { bStopWord = true; } } if (bStopWord == false && !"".equals(word)) { lTrie = lTrie + " " + word; if (entity.getSimpleCategorie() == null) { //Remplissage de la map for (String cat : entity.getListeCategorie()) { if (mapCategorie.get(cat).containsKey(word)) { Integer occurs = mapCategorie.get(cat).get(word); occurs++; mapCategorie.get(cat).remove(word); mapCategorie.get(cat).put(word, occurs); } else { mapCategorie.get(cat).put(word, 1); } } } else { // if (mapCategorie.get(entity.getSimpleCategorie()).containsKey(word)) { // Integer occurs = mapCategorie.get(entity.getSimpleCategorie()).get(word); // occurs++; // mapCategorie.get(entity.getSimpleCategorie()).remove(word); // mapCategorie.get(entity.getSimpleCategorie()).put(word, occurs); // } else { // mapCategorie.get(entity.getSimpleCategorie()).put(word, 1); // } } if (!words.contains(word)) { words.add(word); } } bStopWord = false; } entity.setCommentaireTrie(lTrie); ListDE.add(entity); // System.out.println(entity.getCommentaires()); // System.out.println(entity.getCommentaireTrie()); } arff.chargementData(ListDE); // for (Map.Entry entry : mapCategorie.entrySet()) { // System.out.println(entry); // } //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); } } } // System.out.println(max); //Suppression des mots si ce n'est pas al valuer max for (Entry entry : mapCategorie.entrySet()) { HashMap mapDonnee = (HashMap) entry.getValue(); if (mapDonnee.get(word) != max) { mapDonnee.remove(word); } entry.setValue(mapDonnee); } } // for (Entry entry : mapCategorie.entrySet()) { // System.out.println(entry); // } List<DataEntity> commentairesFinaux = builder.getSimpleCommentaires(); for (DataEntity commentaire : commentairesFinaux) { List<String> categorie; for (String word : commentaire.getCommentaires().split(" ")) { //System.out.println(stopword.getRegEx()); for (String stopApo : stopword.getRegExApos().replace("|", " ").split(" ")) { word = word.replaceAll(stopApo, ""); // System.out.println(stopApo); } word = word.replace(".", " ").replace(",", " ").replace("!", " ").replace("(", "").replace(")", "") .replace("'", "").replace(":", "").trim(); for (String stop : stopword.getRegEx().replace("|", " ").split(" ")) { //System.out.println(stop); if ((word.equalsIgnoreCase(stop)) && !word.equalsIgnoreCase("")) { bStopWord = true; } } 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); } } } bStopWord = false; } findCom.add(commentaire.getListeCategorie()); } calculAllpolarite(); for (int i = 0; i < findCom.size(); i++) { if (jsonListCat == null) { System.out.println("Expected : " + jsonSimpleCat.get(i)); } else { System.out.println("Expected : " + jsonListCat.get(i)); } System.out.println("Found : " + findCom.get(i)); if (jsonListCat == null) { if (findCom.get(i).contains(jsonSimpleCat.get(i))) { System.out.println(true); fiabilite++; } else { System.out.println(false); } } else { if (jsonListCat.get(i).containsAll(findCom.get(i))) { System.out.println(true); fiabilite++; } else { System.out.println(false); } } //System.out.println("Raiting : " + polarites.get(i)); //System.out.println("****************************"); } fiabilite = (fiabilite * 100) / findCom.size(); //System.out.println(fiabilite + "%"); arff.generationArff("Step_One"); }
From source file:uniko.west.topology.bolts.InteractionGraphBolt.java
private void countMentions(Map<Object, Object> message, HashMap<String, ArrayList<Interaction>> authorActions) { List<Object> userMentions = (List<Object>) ((Map<Object, Object>) message.get("entities")) .get("user_mentions"); if (userMentions != null) { if (!authorActions.containsKey("mentioned")) { authorActions.put("mentioned", new ArrayList<Interaction>()); }//from w ww . j ava2 s . c o m for (Object o : userMentions) { String mentionedUser = (String) ((Map<Object, Object>) o).get("id_str"); authorActions.get("mentioned") .add(new Interaction(mentionedUser, (String) message.get("created_at"))); } } }
From source file:com.krawler.spring.companyDetails.companyDetailsDAOImpl.java
@Override public KwlReturnObject getCompanyHolidays(HashMap<String, Object> requestParams, ArrayList filter_names, ArrayList filter_params) throws ServiceException { List ll = null;//from w w w. j a v a 2s.c o m int dl = 0; String companyid = ""; try { if (requestParams.containsKey("companyid") && requestParams.get("companyid") != null) { companyid = requestParams.get("companyid").toString(); } String query = "from CompanyHoliday c "; String filterQuery = StringUtil.filterQuery(filter_names, "where"); query += filterQuery; ll = executeQuery(query, new Object[] { companyid }); dl = ll.size(); } catch (Exception e) { throw ServiceException.FAILURE("companyDetailsDAOImpl.getCompanyInformation", e); } return new KwlReturnObject(true, KWLErrorMsgs.S01, "", ll, dl); }
From source file:in.flipbrain.controllers.Trail.java
private ArrayList<CommentDto> getChildren(Long root, HashMap<Long, ArrayList<CommentDto>> tree) { ArrayList<CommentDto> children = new ArrayList<CommentDto>(); if (tree.containsKey(root)) { children.addAll(tree.get(root)); for (CommentDto n : tree.get(root)) { children.addAll(getChildren(n.commentId, tree)); }//w ww . j ava 2 s . com } return children; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ViewLabelsServlet.java
public HashMap<String, String> getFullCodeToLanguageNameMap(List<HashMap<String, String>> localesList) { HashMap<String, String> codeToLanguageMap = new HashMap<String, String>(); for (Map<String, String> locale : localesList) { String code = (String) locale.get("code"); String label = (String) locale.get("label"); if (!codeToLanguageMap.containsKey(code)) { codeToLanguageMap.put(code, label); } else {/*from w w w . j av a 2s. co m*/ log.warn("Language code " + code + " for " + label + " was not associated in map becayse label already exists"); } } return codeToLanguageMap; }
From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java
public PieDataset createDataSetForDonorReports() { DefaultPieDataset dataset = new DefaultPieDataset(); HashMap<String, Integer> organDonorMap = new HashMap<>(); for (Donor donor : donorList) { for (Organ organ : donor.getOrganDonateList()) { if (organDonorMap.containsKey(organ.getOrganName())) { Integer count = organDonorMap.get(organ.getOrganName()); count++;//from w w w . ja v a 2 s .co m organDonorMap.put(organ.getOrganName(), count); } else { organDonorMap.put(organ.getOrganName(), 1); } } } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { Integer noOfDonors = entry.getValue(); noOfDonors = noOfDonors * 100 / donorList.size(); organDonorMap.put(entry.getKey(), noOfDonors); } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { dataset.setValue(entry.getKey() + " = " + entry.getValue(), entry.getValue()); } return dataset; }
From source file:com.ibm.bi.dml.hops.OptimizerUtils.java
/** * //w w w. j ava2s .com * @param root * @param valMemo * @return * @throws HopsException */ public static double rEvalSimpleDoubleExpression(Hop root, HashMap<Long, Double> valMemo) throws HopsException { //memoization (prevent redundant computation of common subexpr) if (valMemo.containsKey(root.getHopID())) return valMemo.get(root.getHopID()); double ret = Double.MAX_VALUE; //always use constants if (root instanceof LiteralOp) ret = HopRewriteUtils.getDoubleValue((LiteralOp) root); //advanced size expression evaluation if (OptimizerUtils.ALLOW_SIZE_EXPRESSION_EVALUATION) { if (root instanceof UnaryOp) ret = rEvalSimpleUnaryDoubleExpression(root, valMemo); else if (root instanceof BinaryOp) ret = rEvalSimpleBinaryDoubleExpression(root, valMemo); } valMemo.put(root.getHopID(), ret); return ret; }
From source file:com.evolveum.midpoint.common.policy.ValuePolicyGenerator.java
public static String generate(StringPolicyType policy, int defaultLength, boolean generateMinimalSize, OperationResult inputResult) {//from www . ja v a2 s . c o m if (null == policy) { throw new IllegalArgumentException("Provided password policy can not be null."); } if (null == inputResult) { throw new IllegalArgumentException("Provided operation result cannot be null"); } // Define result from generator OperationResult generatorResult = new OperationResult( "Password generator running policy :" + policy.getDescription()); inputResult.addSubresult(generatorResult); // if (policy.getLimitations() != null && // policy.getLimitations().getMinLength() != null){ // generateMinimalSize = true; // } // setup default values where missing // PasswordPolicyUtils.normalize(pp); // Optimize usage of limits ass hashmap of limitas and key is set of // valid chars for each limitation HashMap<StringLimitType, ArrayList<String>> lims = new HashMap<StringLimitType, ArrayList<String>>(); for (StringLimitType l : policy.getLimitations().getLimit()) { if (null != l.getCharacterClass().getValue()) { lims.put(l, StringPolicyUtils.stringTokenizer(l.getCharacterClass().getValue())); } else { lims.put(l, StringPolicyUtils.stringTokenizer(StringPolicyUtils .collectCharacterClass(policy.getCharacterClass(), l.getCharacterClass().getRef()))); } } // Get global limitations int minLen = policy.getLimitations().getMinLength() == null ? 0 : policy.getLimitations().getMinLength().intValue(); if (minLen != 0 && minLen > defaultLength) { defaultLength = minLen; } int maxLen = (policy.getLimitations().getMaxLength() == null ? 0 : policy.getLimitations().getMaxLength().intValue()); int unique = policy.getLimitations().getMinUniqueChars() == null ? minLen : policy.getLimitations().getMinUniqueChars().intValue(); // test correctness of definition if (unique > minLen) { minLen = unique; OperationResult reportBug = new OperationResult("Global limitation check"); reportBug.recordWarning( "There is more required uniq characters then definied minimum. Raise minimum to number of required uniq chars."); } if (minLen == 0 && maxLen == 0) { minLen = defaultLength; maxLen = defaultLength; generateMinimalSize = true; } if (maxLen == 0) { if (minLen > defaultLength) { maxLen = minLen; } else { maxLen = defaultLength; } } // Initialize generator StringBuilder password = new StringBuilder(); /* ********************************** * Try to find best characters to be first in password */ HashMap<StringLimitType, ArrayList<String>> mustBeFirst = new HashMap<StringLimitType, ArrayList<String>>(); for (StringLimitType l : lims.keySet()) { if (l.isMustBeFirst() != null && l.isMustBeFirst()) { mustBeFirst.put(l, lims.get(l)); } } // If any limitation was found to be first if (!mustBeFirst.isEmpty()) { HashMap<Integer, ArrayList<String>> posibleFirstChars = cardinalityCounter(mustBeFirst, null, false, false, generatorResult); int intersectionCardinality = mustBeFirst.keySet().size(); ArrayList<String> intersectionCharacters = posibleFirstChars.get(intersectionCardinality); // If no intersection was found then raise error if (null == intersectionCharacters || intersectionCharacters.size() == 0) { generatorResult .recordFatalError("No intersection for required first character sets in password policy:" + policy.getDescription()); // Log error if (LOGGER.isErrorEnabled()) { LOGGER.error( "Unable to generate password: No intersection for required first character sets in password policy: [" + policy.getDescription() + "] following character limitation and sets are used:"); for (StringLimitType l : mustBeFirst.keySet()) { StrBuilder tmp = new StrBuilder(); tmp.appendSeparator(", "); tmp.appendAll(mustBeFirst.get(l)); LOGGER.error("L:" + l.getDescription() + " -> [" + tmp + "]"); } } // No more processing unrecoverable conflict return null; // EXIT } else { if (LOGGER.isDebugEnabled()) { StrBuilder tmp = new StrBuilder(); tmp.appendSeparator(", "); tmp.appendAll(intersectionCharacters); LOGGER.trace("Generate first character intersection items [" + tmp + "] into password."); } // Generate random char into password from intersection password.append(intersectionCharacters.get(rand.nextInt(intersectionCharacters.size()))); } } /* ************************************** * Generate rest to fulfill minimal criteria */ boolean uniquenessReached = false; // Count cardinality of elements HashMap<Integer, ArrayList<String>> chars; for (int i = 0; i < minLen; i++) { // Check if still unique chars are needed if (password.length() >= unique) { uniquenessReached = true; } // Find all usable characters chars = cardinalityCounter(lims, StringPolicyUtils.stringTokenizer(password.toString()), false, uniquenessReached, generatorResult); // If something goes badly then go out if (null == chars) { return null; } if (chars.isEmpty()) { LOGGER.trace("Minimal criterias was met. No more characters"); break; } // Find lowest possible cardinality and then generate char for (int card = 1; card < lims.keySet().size(); card++) { if (chars.containsKey(card)) { ArrayList<String> validChars = chars.get(card); password.append(validChars.get(rand.nextInt(validChars.size()))); // LOGGER.trace(password.toString()); break; } } } // test if maximum is not exceeded if (password.length() > maxLen) { generatorResult .recordFatalError("Unable to meet minimal criteria and not exceed maximxal size of password."); return null; } /* *************************************** * Generate chars to not exceed maximal */ for (int i = 0; i < minLen; i++) { // test if max is reached if (password.length() == maxLen) { // no more characters maximal size is reached break; } if (password.length() >= minLen && generateMinimalSize) { // no more characters are needed break; } // Check if still unique chars are needed if (password.length() >= unique) { uniquenessReached = true; } // find all usable characters chars = cardinalityCounter(lims, StringPolicyUtils.stringTokenizer(password.toString()), true, uniquenessReached, generatorResult); // If something goes badly then go out if (null == chars) { // we hope this never happend. generatorResult .recordFatalError("No valid characters to generate, but no all limitation are reached"); return null; } // if selection is empty then no more characters and we can close // our work if (chars.isEmpty()) { if (i == 0) { password.append(RandomStringUtils.randomAlphanumeric(minLen)); } break; // if (!StringUtils.isBlank(password.toString()) && password.length() >= minLen) { // break; // } // check uf this is a firs cycle and if we need to user some // default (alphanum) character class. } // Find lowest possible cardinality and then generate char for (int card = 1; card <= lims.keySet().size(); card++) { if (chars.containsKey(card)) { ArrayList<String> validChars = chars.get(card); password.append(validChars.get(rand.nextInt(validChars.size()))); // LOGGER.trace(password.toString()); break; } } } if (password.length() < minLen) { generatorResult.recordFatalError( "Unable to generate password and meet minimal size of password. Password lenght: " + password.length() + ", required: " + minLen); LOGGER.trace( "Unable to generate password and meet minimal size of password. Password lenght: {}, required: {}", password.length(), minLen); return null; } generatorResult.recordSuccess(); // Shuffle output to solve pattern like output StrBuilder sb = new StrBuilder(password.substring(0, 1)); ArrayList<String> shuffleBuffer = StringPolicyUtils.stringTokenizer(password.substring(1)); Collections.shuffle(shuffleBuffer); sb.appendAll(shuffleBuffer); return sb.toString(); }