Text.java index and createWordlist methode cleanup

This commit is contained in:
Andrin Fassbind 2021-11-05 18:36:05 +01:00
parent caec2257e1
commit c565fffbff
1 changed files with 12 additions and 12 deletions

View File

@ -158,13 +158,13 @@ public class Text {
}
/**
* This method counts all Words in text and adds them together with the paragraph where the word is been used to a Hashmap.
* This method counts all Words in text and adds the count together with the paragraph where the word is been used to a Hashmap.
*
* @return HashMap<String, ArrayList < Integer>>
*/
private HashMap<String, ArrayList<Integer>> createWordlist() {
int counter;
ArrayList<Integer> zahlenListe;
ArrayList<Integer> numbersList;
String firstLetter;
String restLetters;
for (int i = 0; i < text.size(); i++) {
@ -175,20 +175,20 @@ public class Text {
restLetters = word.substring(1);
word = firstLetter.toUpperCase() + restLetters;
if (wordbook.containsKey(word)) {
zahlenListe = wordbook.get(word);
counter = zahlenListe.get(0);
zahlenListe.remove(0);
zahlenListe.add(0, counter + 1);
numbersList = wordbook.get(word);
counter = numbersList.get(0);
numbersList.remove(0);
numbersList.add(0, counter + 1);
if (zahlenListe.get(zahlenListe.size() - 1) < i + 1) {
zahlenListe.add(i + 1);
if (numbersList.get(numbersList.size() - 1) < i + 1) {
numbersList.add(i + 1);
}
} else {
zahlenListe = new ArrayList<>();
zahlenListe.add(counter);
zahlenListe.add(i + 1);
numbersList = new ArrayList<>();
numbersList.add(counter);
numbersList.add(i + 1);
}
wordbook.put(word, zahlenListe);
wordbook.put(word, numbersList);
}
}
return wordbook;