List of usage examples for org.apache.commons.collections4.map DefaultedMap DefaultedMap
public DefaultedMap(final Transformer<? super K, ? extends V> defaultValueTransformer)
DefaultedMap
that decorates a HashMap
. From source file:cz.letalvoj.fbgc.compositor.ForceDirectedDynamics.java
public ForceDirectedDynamics(Graph<V, E> graph, Vector2D viewSize) { this.graph = graph; this.viewSize = viewSize; this.lockedNodes = new HashSet<V>(); this.positions = new DefaultedMap<V, Vector2D>(Vector2D.zero()); this.velocities = new DefaultedMap<V, Vector2D>(Vector2D.zero()); }
From source file:io.fluo.quickstart.DocumentObserver.java
@Override public void process(TypedTransactionBase tx, Bytes row, Column column) { // This method is called by Fluo whenever another transaction modifies the // 'doc':'content' column. This method will extract the words from the // document at the specified row, and update the global counts for those // words./*w ww. j a v a2 s . c om*/ // This code does not handle high cardinality words well. The fluo // phrasecount example has handling for this case. String docContent = tx.get().row(row).col(column).toString(); // compute how many times each word occurs in document Map<String, Integer> docCounts = new DefaultedMap<>(Integer.valueOf(0)); for (String word : docContent.split("[ ]+")) { String wordRow = "word: " + word; docCounts.put(wordRow, docCounts.get(wordRow) + 1); } Map<String, Map<Column, Value>> globalCounts = tx.get().rowsString(docCounts.keySet()).columns(COUNT_COL) .toStringMap(); // update global word counts for (String wordRow : docCounts.keySet()) { // Fluo TypeLayer returns defaulted maps, so no need to check if row exist // then check if column exist. int count = globalCounts.get(wordRow).get(COUNT_COL).toInteger(0); tx.mutate().row(wordRow).col(COUNT_COL).set(count + docCounts.get(wordRow)); } }