public void reversePairs() { String firstWord; String secondWord; for (int i = 0; i < arrayOfLines.length; i++) { String line = arrayOfLines[i]; String[] localWordsOnLineArray = stringToElements(line, i); for (int j = 0; j < localWordsOnLineArray.length - 1; j++) { firstWord = localWordsOnLineArray[j]; secondWord = localWordsOnLineArray[j + 1]; // if both words are in the dictionary then swap them if (checker.checkWord(firstWord) && checker.checkWord(secondWord)) { localWordsOnLineArray[j + 1] = firstWord; localWordsOnLineArray[j] = secondWord; j++; // increment to prevent accidental swapping of pairs } } arrayOfLines[i] = elementsToString(localWordsOnLineArray); } // for i } // reverse pairs()
public void countWordsFunc() { for (int i = 0; i < arrayOfLines.length; i++) { String line = arrayOfLines[i]; String[] localWordsOnLineArray = stringToElements(line, i); for (String word : localWordsOnLineArray) { if (checker.checkWord(word)) { // increase the count of the word found in the wordCountMap Integer count = wordCountMap.get(word); // if it's the first time the word is found make it 1, else count++ wordCountMap.put(word, (count == null) ? 1 : count + 1); } } // for words on the line } // for amount of lines } // countWordsFunc()