Sha256: f0abd6c9ae11d958f8943371454a15c25cb565d6b07d657b2f56247662aa689a

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 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.
            if(!this.frequencyMap.containsKey(wordToken)) {
                this.frequencyMap.put(wordToken, 0L);
            }

            // Update count
            this.frequencyMap.put(wordToken, this.frequencyMap.get(wordToken) + 1);
        }
    }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bae-0.2.0 src/main/java/bae/Document.java
bae-0.1.0 src/main/java/bae/Document.java
bae-0.0.9 src/main/java/bae/Document.java
bae-0.0.8-java src/main/java/bae/Document.java
bae-0.0.7-java src/main/java/bae/Document.java
bae-0.0.6-java src/main/java/bae/Document.java
bae-0.0.5-java src/main/java/bae/Document.java