List of usage examples for java.util HashMap merge
@Override public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)
This method will, on a best-effort basis, throw a ConcurrentModificationException if it is detected that the remapping function modifies this map during computation.
From source file:com.adobe.acs.commons.wcm.impl.PropertyMergePostProcessor.java
private void trackMergeParameters(final HashMap<String, Set<String>> mapping, final String source, String destination) {/*from w ww . j av a 2 s . c o m*/ mapping.merge(destination, new HashSet<>(), (a, b) -> a).add(source); }
From source file:org.briljantframework.data.Collectors.java
public static <T> Collector<T, ?, Vector> valueCounts() { return Collector.of(HashMap::new, (map, t) -> map.compute(t, (v, c) -> c == null ? 1 : c + 1), new BinaryOperator<HashMap<T, Integer>>() { @Override/*from w ww . j av a 2 s . c om*/ public HashMap<T, Integer> apply(HashMap<T, Integer> left, HashMap<T, Integer> right) { right.forEach((k, v) -> left.merge(k, v, (Integer o, Integer n) -> o == null ? n : o + n)); return left; } }, (map) -> { Vector.Builder b = new TypeInferenceVectorBuilder(); for (Map.Entry<T, Integer> e : map.entrySet()) { b.set(e.getKey(), e.getValue()); } return b.build(); }, Collector.Characteristics.UNORDERED); }
From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventNodeBase.java
/** * defer tooltip content creation till needed, this had a surprisingly large * impact on speed of loading the chart/*from w w w . jav a 2 s . com*/ */ @NbBundle.Messages({ "# {0} - counts", "# {1} - event type", "# {2} - description", "# {3} - start date/time", "# {4} - end date/time", "EventNodeBase.tooltip.text={0} {1} events\n{2}\nbetween\t{3}\nand \t{4}", "EventNodeBase.toolTip.loading2=loading tooltip", "# {0} - hash set count string", "EventNodeBase.toolTip.hashSetHits=\n\nHash Set Hits\n{0}", "# {0} - tag count string", "EventNodeBase.toolTip.tags=\n\nTags\n{0}" }) @ThreadConfined(type = ThreadConfined.ThreadType.JFX) void installTooltip() { if (tooltip.getText().equalsIgnoreCase(Bundle.EventBundleNodeBase_toolTip_loading())) { final Task<String> tooltTipTask = new Task<String>() { { updateTitle(Bundle.EventNodeBase_toolTip_loading2()); } @Override protected String call() throws Exception { HashMap<String, Long> hashSetCounts = new HashMap<>(); if (tlEvent.getEventIDsWithHashHits().isEmpty() == false) { try { //TODO:push this to DB for (SingleEvent tle : eventsModel.getEventsById(tlEvent.getEventIDsWithHashHits())) { Set<String> hashSetNames = sleuthkitCase.getAbstractFileById(tle.getFileID()) .getHashSetNames(); for (String hashSetName : hashSetNames) { hashSetCounts.merge(hashSetName, 1L, Long::sum); } } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Error getting hashset hit info for event.", ex); //NON-NLS } } String hashSetCountsString = hashSetCounts.entrySet().stream() .map((Map.Entry<String, Long> t) -> t.getKey() + " : " + t.getValue()) .collect(Collectors.joining("\n")); Map<String, Long> tagCounts = new HashMap<>(); if (tlEvent.getEventIDsWithTags().isEmpty() == false) { tagCounts.putAll(eventsModel.getTagCountsByTagName(tlEvent.getEventIDsWithTags())); } String tagCountsString = tagCounts.entrySet().stream() .map((Map.Entry<String, Long> t) -> t.getKey() + " : " + t.getValue()) .collect(Collectors.joining("\n")); return Bundle.EventNodeBase_tooltip_text(getEventIDs().size(), getEventType(), getDescription(), TimeLineController.getZonedFormatter().print(getStartMillis()), TimeLineController.getZonedFormatter().print(getEndMillis() + 1000)) + (hashSetCountsString.isEmpty() ? "" : Bundle.EventNodeBase_toolTip_hashSetHits(hashSetCountsString)) + (tagCountsString.isEmpty() ? "" : Bundle.EventNodeBase_toolTip_tags(tagCountsString)); } @Override protected void succeeded() { super.succeeded(); try { tooltip.setText(get()); tooltip.setGraphic(null); } catch (InterruptedException | ExecutionException ex) { LOGGER.log(Level.SEVERE, "Tooltip generation failed.", ex); //NON-NLS } } }; new Thread(tooltTipTask).start(); chartLane.getController().monitorTask(tooltTipTask); } }