package kldtz.github.com.hmmt.counts;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import kldtz.github.com.hmmt.container.SctTriple;
import kldtz.github.com.hmmt.corpus.Capitalization;
import kldtz.github.com.hmmt.utils.Utils;

public class HashedSuffixCounts implements SuffixCounts, Serializable {	
	private static final long serialVersionUID = 1L;
	private Map<SctTriple, Integer> suffixCounts;
	private int maxSuffixLength;
	private Set<String> tagset;
	
	public HashedSuffixCounts(Set<String> tagset, int maxSuffixLength) {
		suffixCounts = new HashMap<>();
		this.maxSuffixLength = maxSuffixLength;
		this.tagset = tagset;
	}

	@Override
	public void incrementCounts(String word, String tag, int frequency) {
		Capitalization c = Utils.extractCapitalization(word);
		String paddedWord = Utils.padWord(word, maxSuffixLength);
		for (int i = 0; i <= maxSuffixLength; i++) {
			SctTriple sct = new SctTriple(paddedWord.substring(paddedWord.length() - i), c, tag);
			if (!suffixCounts.containsKey(sct)) {
				suffixCounts.put(sct, 0);
			}
			suffixCounts.put(sct, suffixCounts.get(sct) + frequency);
		}		
	}

	@Override
	public List<Integer> collectSuffixTagCounts(String word, String tag) {
		List<Integer> counts = new ArrayList<>();
		Capitalization c = Utils.extractCapitalization(word);
		String paddedWord = Utils.padWord(word, maxSuffixLength);
		for (int i = 0; i <= maxSuffixLength; i++) {
			SctTriple sct = new SctTriple(paddedWord.substring(paddedWord.length() - i), c, tag);
			Integer count = suffixCounts.get(sct);
			if (count == null) {
				count = 0;
			}
			counts.add(count);
		}
		return counts;
	}

	@Override
	public Set<String> collectPossibleStates(Capitalization capitalization) {
		Set<String> possibleStates = new HashSet<>();
		for (String tag : tagset) {
			SctTriple sct = new SctTriple("", capitalization, tag);
			Integer sctCount = suffixCounts.get(sct);
			if (sctCount != null && sctCount > 0) {
				possibleStates.add(tag);
			}
		}
		return possibleStates;
	}

}

@@ -93,34 +93,8 @@
 st;%0A
-import java.util.HashMap;%0A
 impo
@@ -115,16 +115,16 @@
 ashSet;%0A
+
 import j
@@ -142,30 +142,8 @@
 st;%0A
-import java.util.Map;%0A
 impo
@@ -161,16 +161,97 @@
 l.Set;%0A%0A
+import gnu.trove.map.TObjectIntMap;%0Aimport gnu.trove.map.hash.TObjectIntHashMap;%0A
 import k
@@ -519,16 +519,26 @@
 private 
+TObjectInt
 Map%3CSctT
@@ -546,17 +546,8 @@
 iple
-, Integer
 %3E su
@@ -714,18 +714,41 @@
 new 
-HashMap%3C%3E(
+TObjectIntHashMap%3C%3E(1000, 0.5f, 0
 );%0A%09
@@ -1157,13 +1157,8 @@
 %0A%09%09%09
-if (!
 suff
@@ -1170,111 +1170,40 @@
 nts.
-containsKey(sct)) %7B%0A%09%09%09%09suffixCounts.put(sct, 0);%0A%09%09%09%7D%0A%09%09%09suffixCounts.put(sct, suffixCounts.get(sct) +
+adjustOrPutValue(sct, frequency,
  fre
@@ -1607,24 +1607,19 @@
 %0A%09%09%09
-Integer count = 
+counts.add(
 suff
@@ -1639,73 +1639,8 @@
 sct)
-;%0A%09%09%09if (count == null) %7B%0A%09%09%09%09count = 0;%0A%09%09%09%7D%0A%09%09%09counts.add(count
 );%0A%09

Use TObjectIntHashMap with no-entry value instead of HashMap