где и что я потерял((( понять не могу(((
package com.javarush.task.task22.task2207;
import java.io.*;
import java.util.*;
/*
Обращенные слова
*/
public class Solution {
public static List<Pair> result = new LinkedList<>();
public static void main(String[] args) {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
List<StringBuilder> SB = new ArrayList<>();
try {
SB = listSB(bf.readLine());
} catch (IOException e) {
System.out.println("IOException in {main}");
e.printStackTrace();
}
Set<Pair> set = new HashSet<>();
for (int i = 0; i < SB.size(); i++){
Pair pair = new Pair();
pair.first = SB.get(i).toString();
for (int j = i+1; j < SB.size(); j++){
if (pair.first.equals(SB.get(j).reverse().toString())) {
pair.second = SB.get(i).toString();
set.add(pair);
}
}
}
for (Pair pair: set){
result.add(pair);
System.out.println(pair.toString());
}
System.out.println(result);
}
private static List<StringBuilder> listSB (String fileName){
List<String> listStr = new ArrayList<>();
List<StringBuilder> listSB = new ArrayList<>();
try(FileInputStream fis = new FileInputStream(fileName)) {
BufferedReader bf = new BufferedReader(new InputStreamReader(fis));
while (bf.ready()) {
listStr.add(bf.readLine());
}
} catch (FileNotFoundException e) {
System.out.println("No File");
e.printStackTrace();
} catch (IOException e) {
System.out.println("IOException in {listSB}");
e.printStackTrace();
}
for (int i = 0; i < listStr.size(); i++){
String[] arr = listStr.get(i).split(" ");
for (int j = 0; j < arr.length; j++){
listSB.add(new StringBuilder(arr[j]));
}
}
return listSB;
}
public static class Pair{
String first;
String second;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
return second != null ? second.equals(pair.second) : pair.second == null;
}
@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (second != null ? second.hashCode() : 0);
return result;
}
@Override
public String toString() {
return first == null && second == null ? "" :
first == null && second != null ? second :
second == null && first != null ? first :
first.compareTo(second) < 0 ? first + " " + second : second + " " + first;
}
}
}