List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:bammerbom.ultimatecore.spongeapi.UltimateConverter.java
public static void convert() { if (r.getCnfg().contains("Tp.TpaCancelDelay")) { try {/* ww w.j a va 2 s .com*/ r.log(TextColors.DARK_RED + "-----------------------------------------------"); r.log("WARNING!!!"); r.log("UltimateCore is converting to 2.x ..."); r.log("Everything except HOMES and WARPS is lost!"); r.log("UltimateCore will make a backup for you: "); r.log(TextColors.DARK_RED + "-----------------------------------------------"); Thread.sleep(10000L); r.log("Creating backup..."); FileUtil.copy(r.getUC().getDataFolder(), new File(r.getUC().getDataFolder().getParentFile(), "UltimateCore (Backup from 1.x)")); r.log("Converting..."); HashMap<UUID, HashMap<String, RLocation>> homes = new HashMap<>(); for (User pl : r.getOfflinePlayers()) { Config conf = UC.getPlayer(pl).getPlayerConfig(); HashMap<String, RLocation> hom = new HashMap<>(); if (conf.contains("homes")) { for (String str : conf.getConfigurationSection("homes").getKeys(false)) { hom.put(str, LocationUtil.convertStringToLocation(conf.getString("homes." + str))); } homes.put(pl.getUniqueId(), hom); } } Config conf = new Config(UltimateFileLoader.DFwarps); HashMap<String, RLocation> warps = new HashMap<>(); if (conf.contains("warps")) { for (String str : conf.getConfigurationSection("warps").getKeys(false)) { warps.put(str, LocationUtil.convertStringToLocation(conf.getString("warps." + str))); } } FileUtils.deleteDirectory(r.getUC().getDataFolder()); UltimateFileLoader.Enable(); UC.getServer().setWarps(warps); for (UUID u : homes.keySet()) { UC.getPlayer(u).setHomes(homes.get(u)); } r.log("Converting complete!"); r.log(TextColors.DARK_RED + "-----------------------------------------------"); } catch (InterruptedException | IOException ex) { ErrorLogger.log(ex, "Failed to convert from 1.x"); } } }
From source file:edu.illinois.cs.cogcomp.utils.Utils.java
/** * This measures the WAVE score of a set of productions. WAVE score comes from (Kumaran et al 2010) * It is a measure of transliterability. * @param fname the file name of a set of learned productions. * @return WAVE score/*from w ww . ja va 2s .c o m*/ */ public static double WAVE(String fname) throws FileNotFoundException { List<String> lines = LineIO.read(fname); HashMap<String, Integer> srcFreq = new HashMap<>(); HashMap<String, Integer> tgtFreq = new HashMap<>(); HashMap<String, Double> entropy = new HashMap<>(); for (String line : lines) { if (line.trim().length() == 0 || line.startsWith("#")) { continue; } String[] sline = line.split("\t"); String src = sline[0]; String tgt = sline[1]; double prob = Double.parseDouble(sline[2]); Dictionaries.IncrementOrSet(srcFreq, src, 1, 1); Dictionaries.IncrementOrSet(tgtFreq, tgt, 1, 1); double v = prob * Math.log(prob); Dictionaries.IncrementOrSet(entropy, src, v, v); } double total = 0; for (int v : srcFreq.values()) { total += v; } double WAVE = 0; for (String i : srcFreq.keySet()) { // -= because entropy should be negative, but I never do it. WAVE -= srcFreq.get(i) / total * entropy.get(i); } return WAVE; }
From source file:gr.cti.android.experimentation.controller.ui.RestRankingController.java
@ResponseBody @RequestMapping(value = { "/results/{experimentId}/csv" }, method = RequestMethod.GET, produces = "text/csv") public String getResultsCsv(@PathVariable("experimentId") final int experimentId) { final Set<Result> results = resultRepository.findByExperimentId(experimentId); final StringBuilder resResponse = new StringBuilder(); final Set<String> headers = new HashSet<>(); for (final Result result : results) { try {//w ww. j av a 2 s. c o m final HashMap<String, Object> dataMap = new ObjectMapper().readValue(result.getMessage(), new HashMap<String, Object>().getClass()); headers.addAll(dataMap.keySet()); } catch (IOException ignore) { } } headers.remove(LONGITUDE); headers.remove(LATITUDE); resResponse.append("timestamp,longitude,latitude,"); resResponse.append(String.join(",", headers)).append("\n"); for (final Result result : results) { final List<String> values = new ArrayList<>(); values.add(String.valueOf(result.getTimestamp())); try { final HashMap<String, Object> dataMap = new ObjectMapper().readValue(result.getMessage(), new HashMap<String, Object>().getClass()); values.add(String.valueOf(dataMap.get(LONGITUDE))); values.add(String.valueOf(dataMap.get(LATITUDE))); for (final String key : headers) { if (dataMap.containsKey(key)) { values.add(String.valueOf(dataMap.get(key))); } else { values.add(null); } } resResponse.append(String.join(",", values)).append("\n"); } catch (IOException e) { LOGGER.warn(e, e); } } return resResponse.toString(); }
From source file:bammerbom.ultimatecore.bukkit.UltimateConverter.java
public static void convert() { if (r.getCnfg().contains("Tp.TpaCancelDelay")) { try {//from w w w . java 2 s . c o m r.log(ChatColor.DARK_RED + "-----------------------------------------------"); r.log("WARNING!!!"); r.log("UltimateCore is converting to 2.x ..."); r.log("Everything except HOMES and WARPS is lost!"); r.log("UltimateCore will make a backup for you: "); r.log(ChatColor.DARK_RED + "-----------------------------------------------"); Thread.sleep(10000L); r.log("Creating backup..."); FileUtil.copy(r.getUC().getDataFolder(), new File(r.getUC().getDataFolder().getParentFile(), "UltimateCore (Backup from 1.x)")); r.log("Converting..."); HashMap<UUID, HashMap<String, Location>> homes = new HashMap<>(); for (OfflinePlayer pl : r.getOfflinePlayers()) { Config conf = UC.getPlayer(pl).getPlayerConfig(); HashMap<String, Location> hom = new HashMap<>(); if (conf.contains("homes")) { for (String str : conf.getConfigurationSection("homes").getKeys(false)) { hom.put(str, LocationUtil.convertStringToLocation(conf.getString("homes." + str))); } homes.put(pl.getUniqueId(), hom); } } Config conf = new Config(UltimateFileLoader.DFwarps); HashMap<String, Location> warps = new HashMap<>(); if (conf.contains("warps")) { for (String str : conf.getConfigurationSection("warps").getKeys(false)) { warps.put(str, LocationUtil.convertStringToLocation(conf.getString("warps." + str))); } } FileUtils.deleteDirectory(r.getUC().getDataFolder()); UltimateFileLoader.Enable(); UC.getServer().setWarps(warps); for (UUID u : homes.keySet()) { UC.getPlayer(u).setHomes(homes.get(u)); } r.log("Converting complete!"); r.log(ChatColor.DARK_RED + "-----------------------------------------------"); } catch (InterruptedException | IOException ex) { ErrorLogger.log(ex, "Failed to convert from 1.x"); } } }
From source file:com.github.haixing_hu.bean.DefaultProperty.java
@Override public final Set<String> getKeySet() { final HashMap<String, Object> map = getMappedValue(); return map.keySet(); }
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
public static HashMap<Production, Double> FindWeightedAlignments(String word1, String word2, int maxSubstringLength1, int maxSubstringLength2, HashMap<Production, Double> probs, InternDictionary<String> internTable, NormalizationMode normalization) { HashMap<Production, Double> weights = new HashMap<>(); FindWeightedAlignments(1, new ArrayList<Production>(), word1, word2, maxSubstringLength1, maxSubstringLength2, probs, weights, new HashMap<Production, Pair<Double, Double>>()); //CheckDictionary(weights); HashMap<Production, Double> weights2 = new HashMap<>(weights.size()); for (Production wkey : weights.keySet()) { weights2.put(wkey, weights.get(wkey) == 0 ? 0 : weights.get(wkey) / probs.get(wkey)); }/*w w w. j av a2s. c o m*/ //weights2[wPair.Key] = weights[wPair.Key] == 0 ? 0 : Math.Pow(weights[wPair.Key], 1d / word1.Length); weights = weights2; return Normalize(word1, word2, weights, internTable, normalization); }
From source file:org.socraticgrid.codeconversion.matchers.DescMatch.java
@Override protected boolean match_TA_CA_DL(CodeSearch matchCd, List<CodeReference> outList) { Iterator<String> itr = tsMap.keySet().iterator(); while (itr.hasNext()) { TargetSystemCodeMap map = tsMap.get(itr.next()); if (map != null) { if (map.SrchMap.containsKey(matchCd.getDisplay())) { HashMap<String, SourceCoding> sysMap = map.SrchMap.get(matchCd.getDisplay()); Iterator<String> sysItr = sysMap.keySet().iterator(); while (sysItr.hasNext()) { SourceCoding sc = sysMap.get(sysItr.next()); outList.add(new CodeReference(matchCd.getTargetSystem(), sc.getTargetCode(), sc.getSourceName(), sc.getSourceNote())); }//from w w w . j av a2 s.c o m } } } return true; }
From source file:morphy.service.ServerListManagerService.java
private ServerListManagerService() { HashMap<ServerList, List<String>> map = loadFromDatabase(); if (map == null || map.isEmpty()) { // load defaults initialize();/*w w w.j a v a2 s.c o m*/ } else { ServerList[] listArr = map.keySet().toArray(new ServerList[map.keySet().size()]); lists = new ArrayList<ServerList>(listArr.length); for (int i = 0; i < listArr.length; i++) { ServerList list = listArr[i]; lists.add(list); } elements = map; } if (LOG.isInfoEnabled()) { LOG.info("Initialized ServerListManagerService."); } }
From source file:net.certiv.authmgr.task.section.model.AnalyzeModel.java
private void analyzePartitions(PersistantWordsDataSource pds, String category, HashMap<String, HashMap<String, WordProbabilityPT>> partsMap) { PartitionKeyComparator keyComp = new PartitionKeyComparator(partsMap); TreeSet<String> partKeys = new TreeSet<String>(keyComp); partKeys.addAll(partsMap.keySet()); String partitions = ""; for (Iterator<String> it = partKeys.iterator(); it.hasNext();) { partitions = partitions + it.next() + " "; }//from w w w. jav a2 s. c om Log.info(this, "Partition collection: " + partKeys.size() + " = " + partitions); // for each partition for (Iterator<String> it = partKeys.iterator(); it.hasNext();) { String partition = it.next(); HashMap<String, WordProbabilityPT> wordsMap = partsMap.get(partition); analyzeWords(category, partition, wordsMap); } }
From source file:com.sonicle.webtop.core.versioning.Whatsnew.java
public Whatsnew(String resourceName, HashMap<String, String> variables) { this.resourceName = resourceName; // Converts variables into regex patterns for (String key : variables.keySet()) { patterns.put(Pattern.compile("\\{" + key + "\\}"), StringUtils.defaultString(variables.get(key))); }/*from w w w . j av a 2s.com*/ }