package com.androiddom.wordtoolbox.analytics;

import java.util.HashMap;
import java.util.Map;

import com.androiddom.wordtoolbox.Dictionary;

/**
 * A collection of functions to analyze a full dictionary.
 *
 */
public class DictionaryAnalytics {

	/**
	 * Returns lengths mapped to the count of words with that length.
	 * 
	 * @param dictionary
	 *            The dictionary to analyze.
	 * @return A map of lengths mapped to a count of words with that length.
	 */
	public static Map<Integer, Integer> lengthCountDict(Dictionary dictionary) {
		Map<Integer, Integer> lengthMap = new HashMap<Integer, Integer>();

		for (String word : dictionary.getWords()) {
			int length = word.length();
			int count = 0;

			if (lengthMap.containsKey(length))
				count = lengthMap.get(length);
			count++;
			lengthMap.put(length, count);
		}

		return lengthMap;
	}

	/**
	 * Returns word complexity mapped to the count of words with that
	 * complexity.
	 * 
	 * @param dictionary
	 *            The dictionary to analyze.
	 * @return A map of word complexity mapped to a count of words with that
	 *         complexity.
	 */
	public static Map<Integer, Integer> wordComplexityCount(Dictionary dictionary) {
		Map<Integer, Integer> complexityMap = new HashMap<Integer, Integer>();

		for (String word : dictionary.getWords()) {
			int complexity = WordComplexity.getWordComplexity(word);
			int count = 0;

			if (complexityMap.containsKey(complexity))
				count = complexityMap.get(complexity);
			count++;
			complexityMap.put(complexity, count);
		}

		return complexityMap;
	}

}

@@ -61,84 +61,212 @@
 til.
-HashMap;%0Aimport java.util.Map;%0A%0Aimport com.androiddom.wordtoolbox.Dictionary
+ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Locale;%0Aimport java.util.Map;%0A%0Aimport com.androiddom.wordtoolbox.Dictionary;%0Aimport com.androiddom.wordtoolbox.util.StringUtils
 ;%0A%0A/
@@ -1697,10 +1697,557 @@
 ap;%0A%09%7D%0A%0A
+%09/**%0A%09 * A function to find palindromes in a dictionary.%0A%09 * %0A%09 * @param dictionary%0A%09 *            The dictionary to check.%0A%09 * @return A list of palindromes.%0A%09 */%0A%09public static List%3CString%3E findPalindromes(Dictionary dictionary) %7B%0A%09%09List%3CString%3E palindromeList = new ArrayList%3CString%3E();%0A%09%09for (String word : dictionary.getWords()) %7B%0A%09%09%09String lowerCase = word.toLowerCase(Locale.US);%0A%09%09%09if (lowerCase.length() %3E 1 && lowerCase.equals(StringUtils.reverseString(lowerCase))) %7B%0A%09%09%09%09palindromeList.add(word);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return palindromeList;%0A%09%7D%0A%0A
 %7D%0A

Adding a function to find words that are palindromes.