Sha256: be344cc580ee32e94656d72635735dcce47ddbc1a26bf1a6a4b61fef5a028da4
Contents?: true
Size: 1.03 KB
Versions: 4
Compression:
Stored size: 1.03 KB
Contents
package bae; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Document { private Map<String, Long> frequencyMap; public Document(String text) { createFrequencyMap(text); } public Document(Map<String, Long> frequencyMap) { this.frequencyMap = frequencyMap; } public Map<String, Long> getFrequencyMap() { return frequencyMap; } public void addZeroCount(String key) { this.frequencyMap.put(key, 0L); } private void createFrequencyMap(String text) { this.frequencyMap = new HashMap<>(); Scanner parser = new Scanner(text); while(parser.hasNext()) { String wordToken = parser.next(); // Set initial count if it doesn't have one yet // Use zero because we'll add counts in the next line. this.frequencyMap.putIfAbsent(wordToken, 0L); // Update count this.frequencyMap.put(wordToken, this.frequencyMap.get(wordToken) + 1); } } }
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
bae-0.0.4-java | src/main/java/bae/Document.java |
bae-0.0.3-java | src/main/java/bae/Document.java |
bae-0.0.2-java | src/main/java/bae/Document.java |
bae-0.0.1 | src/main/java/bae/Document.java |