package tsp.application; public class Document { private String content; HashMap frequencies; public Document(String text){ this.content = text; this.frequencies = new HashMap<>(); this.addFrequencies(); } private void addFrequencies(){ String[] words = this.preprocess(); for (String word: words){ if (!frequencies.containsKey(word)){ frequencies.put(word, 0.0); } frequencies.put(word, frequencies.get(word) + 1.0 / words.length); } } public double getFrequency(String word){ if (!this.frequencies.containsKey(word)) return 0; return this.frequencies.get(word); } //... }