Sha256: 6f8052defedfb9cf9008affee71c8a7285d7818d17e724a6dbf178c68ea6d62b

Contents?: true

Size: 595 Bytes

Versions: 87

Compression:

Stored size: 595 Bytes

Contents

import java.lang.Integer;
import java.lang.String;
import java.util.HashMap;
import java.util.Map;

public class WordCount {

    public Map<String, Integer> phrase( String input ) {
        Map<String, Integer> countMap = new HashMap<>();
        input = input.trim().toLowerCase().replaceAll("([^A-Za-z0-9']|\\B'|'\\B)", " ");
        final String[] tokenizedInput = input.split("\\s+");
        for( String aWord : tokenizedInput ) {
            Integer count = countMap.get(aWord);
            countMap.put(aWord, count == null ? 1 : count + 1 );
        }
        return countMap;
    }

}

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.138 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.137 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.136 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.135 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.134 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.133 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.132 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.131 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.130 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.129 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.128 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.127 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.126 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.125 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.124 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.123 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.122 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.121 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.120 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java