List of usage examples for java.util HashMap getOrDefault
@Override
public V getOrDefault(Object key, V defaultValue)
From source file:com.twosigma.beakerx.mimetype.MIMEContainer.java
private static MIMEContainer IFrame(String srcTemplate, String id, HashMap params) { Object width = params.getOrDefault("width", DEFAULT_IFRAME_WIDTH); Integer height = Integer.parseInt(params.getOrDefault("height", DEFAULT_IFRAME_HEIGHT).toString()); String src = String.format(srcTemplate, id, parseParams(params)); return IFrame(src, width, height); }
From source file:hudson.logging.LogRecorder.java
@Restricted(NoExternalUse.class) @VisibleForTesting//from w ww . j a va2 s . co m public static Set<String> getAutoCompletionCandidates(List<String> loggerNamesList) { Set<String> loggerNames = new HashSet<>(loggerNamesList); // now look for package prefixes that make sense to offer for autocompletion: // Only prefixes that match multiple loggers will be shown. // Example: 'org' will show 'org', because there's org.apache, org.jenkinsci, etc. // 'io' might only show 'io.jenkins.plugins' rather than 'io' if all loggers starting with 'io' start with 'io.jenkins.plugins'. HashMap<String, Integer> seenPrefixes = new HashMap<>(); SortedSet<String> relevantPrefixes = new TreeSet<>(); for (String loggerName : loggerNames) { String[] loggerNameParts = loggerName.split("[.]"); String longerPrefix = null; for (int i = loggerNameParts.length; i > 0; i--) { String loggerNamePrefix = StringUtils.join(Arrays.copyOf(loggerNameParts, i), "."); seenPrefixes.put(loggerNamePrefix, seenPrefixes.getOrDefault(loggerNamePrefix, 0) + 1); if (longerPrefix == null) { relevantPrefixes.add(loggerNamePrefix); // actual logger name longerPrefix = loggerNamePrefix; continue; } if (seenPrefixes.get(loggerNamePrefix) > seenPrefixes.get(longerPrefix)) { relevantPrefixes.add(loggerNamePrefix); } longerPrefix = loggerNamePrefix; } } return relevantPrefixes; }
From source file:com.cotrino.langnet.GenerateVisualization.java
private void generateLanguages(String summaryFile, String languagesFile) throws IOException { HashMap<String, Integer> list = new HashMap<String, Integer>(); Reader reader = new FileReader(summaryFile); CSVParser parser = new CSVParser(reader, csvFormat); for (CSVRecord record : parser) { String languageA = record.get("LanguageA"); String languageB = record.get("LanguageB"); int words = Integer.parseInt(record.get("ExecutedComparisons")); list.put(languageA, Math.max(words, list.getOrDefault(languageA, 0))); list.put(languageB, Math.max(words, list.getOrDefault(languageB, 0))); }//w w w. ja v a2 s . co m parser.close(); reader.close(); String content = "Language;Words;Family;\n"; for (String language : list.keySet()) { content += language + ";" + list.get(language) + ";Romance;\n"; } IOUtil.write(languagesFile, content); }