I'm basically taking a big block of chars and using each suffix as a key, each key pointing an an ArrayList that contains the index where each of these suffixes can be found.
When I do a HashMap.get(suffix) it gives me the index of the key it added last, rather then the one I'm trying to pull (this occurs on the duplicates...
Here it is,
protected HashMap<String, ArrayList<Integer>> makeMap(char[] textStored)
{
HashMap<String, ArrayList<Integer>> phraseMap =
new HashMap<String, ArrayList<Integer>>();
ArrayList<Integer> indexList = new ArrayList<Integer>();
Boolean word = true;
String suffix;
int wordEndIndex = 0;
for (int i = 0; i < textStored.length; i++) {
word &= Character.isLetter(textStored[i]);
if (word) {
for (int h = i + 1;h < textStored.length;h++) {
if (!Character.isLetter(textStored[h])) {
wordEndIndex = h;
break;
}
}//PULLING THE NEXT SUFFIX vvv
//This finds the next word/suffix:
suffix = new String(textStored).substring(i,wordEndIndex + 1);
//if my hashmap already contains this key:
if (phraseMap.containsKey(suffix)) {
System.out.println(suffix);
indexList = phraseMap.get(suffix);
System.out.println(indexList);// This is printing
// the wrong info,
// telling me my phraseMap.get(suffix) is
// using the wrong key, yet
// I'm printing out the suffix
// directly before that line,
// and I'm definitatly inputting
// the correct suffix...
indexList.add(i);
phraseMap.put(suffix,indexList);
System.out.println(indexList);
} else {
// System.out.println(suffix);
indexList.clear();
indexList.add(i);
phraseMap.put(suffix, indexList);
// System.out.println(phraseMap.get(suffix));
}
}
word = !Character.isLetter(textStored[i]);
}
return phraseMap;
}