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.119 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.118 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.117 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.116 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.115 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.114 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.113 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.111 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.110 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.109 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.108 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.107 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.106 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.105 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.104 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.103 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.102 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.101 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.100 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.99 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java