HTML ファイルの単語インデクサーの実装を書いています。コンストラクターに問題があります。
コンストラクターでは、HTML ファイル内の各単語をスキャンし、それを TreeMap に追加します)。ここで、リンクされたリストは、キー (単語) がファイル内に現れるインデックスのコレクションです。テスト中、連結リストが 1 より大きくなることはありません。誰かが私のコードを見て、物事が混乱している正しい方向に私を向けることができるかどうか疑問に思っています.
while(scanner.hasNext()) {
String temp = scanner.next().toLowerCase();
if(this.wordMap.containsKey(temp)) {
LinkedList<Integer> tempList = this.wordMap.get(temp);
tempList.add(currentIndex);
wordMap.put(temp, tempList);
wordCount++;
currentIndex++;
}
else {
LinkedList<Integer> tempList = new LinkedList<Integer>();
tempList.add(currentIndex);
wordMap.put(temp, tempList);
wordCount++;
currentIndex++;
}
}