I'm doing some work on a block of code that current uses the structure.
HashMap(Text, HashMap(Text, ArrayList(Ints)))
HashMapWritable<Text, ArrayListOfIntsWritable> fileMap =
new HashMapWritable<Text, ArrayListOfIntsWritable>();
HashMapWritable<Text, HashMapWritable<Text, ArrayListOfIntsWritable>> wordMap =
new HashMapWritable<Text, HashMapWritable<Text, ArrayListOfIntsWritable>>();
And I'm getting weird results but having trouble pinpointing why.
if (!wordMap.containsKey(newText)) {
ArrayListOfIntsWritable wordPosition = new ArrayListOfIntsWritable();
wordPosition.add(c);
fileMap.put(INPUTFILE, wordPosition);
wordMap.put(newText, fileMap);
} else {
HashMapWritable<Text, ArrayListOfIntsWritable> updatePosStep1 =
wordMap.get(newText);
ArrayListOfIntsWritable updatePosStep2 = updatePosStep1.get(INPUTFILE);
updatePosStep2.add(c);
}
I've also tried updating doing:
wordMap.get(newText).get(INPUTFILE).add(c);
but that gave the same results.
This is all done in a loop and whats happening is this (the example shows the case where 'newText' = 'episod' where the numbers are the position in the loop they are (basic for loop incrementing c) and the [int,int,...] are the values of C that have been stored
Word: episod curPos 14 positions: [14]
Word: episod curPos 120 positions: [116, 118, 120]
Word: episod curPos 191 positions: [186, 190, 191]
Word: episod curPos 199 positions: [198, 199]
As you can see (hopefully it shows what I'm trying to get across), the values for the key episod
get reset at some point prior. This is the same with all words so when its finished running, all words have the same few sets of integers..
Is it something obvious I'm doing wrong?