Simple Java objects to count items and accumulate associated values
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.settings
src/com/pwnetics/helper
test/com/pwnetics/helper
.classpath
.gitignore
.project
LICENSE.txt
README.md
overview.html

README.md

Overview

ItemCounter is a Java class that stores a count for each appearance
of an item. ItemDoubleAccumulator stores the accumulated value
associated with each appearance of an item. They both support basic
summary statistics, serialization, and pretty-printing capabilities.

An example use of ItemCounter is to count the number of times
different words appear in a set of documents. One could then output
all words used, sorted by their frequency of occurrence.

Similar functionality is available in the Bag data structures in
the Apache Commons collections library and Google Guava library.
ItemCounter classes are designed with a single-purpose API, no
external dependencies, and sane default behavior. They also take
advantage of Java generics.

Javadoc is available online. Feedback and bugfixes are welcomed.

Brian Romanowski
romanows@gmail.com

Details

This code is licensed under one of the BSD variants, please see
LICENSE.txt for full details.

Example

// Print the number of lower-case tokens observed in a string.
	
String words = "foo bar bat baz foo foo baz";
ItemCounter<String> wordCount = new ItemCounter<String>();
for(String word : words.split("\\s+")) {
   wordCount.increment(word.toLowerCase());
}
System.out.println(wordCount.toCSV());