I have two lists of custom objects both are List<LogEntry>. The properties inside one are typeOfException, date and stackTrace and the other just contains typeOfException and stackTrace. What I would like to do is to remove duplicate Log entries based on their typeOfException and the stackTrace. The way I've defined a unique stack trace is to be if the first 'at line' is the same i.e
[25/05/21 10:28:41:481 BST] - IllegalStateException some text here
at com.google MyClass(Line 50)
[28/05/21 10:28:41:481 BST] - IllegalStateException some more text here
at com.google MyClass(Line 50)
are seen as duplicates but
[25/05/21 10:28:41:481 BST] - IllegalStateException some text here
at com.google MyClass(Line 50)
[28/05/21 10:28:41:481 BST] - IllegalStateException some more text here
at com.google MyClass(Line 50000)
would be seen as unique.
I have a List<LogEntry> called logEntries which contains the date, typeOfException and stackTrace. I have another List<LogEntry> called logEntriesToCheckForDupes which is a LogEntry object but this time just containing typeOfException and the top at line of the stackTrace (Note all the properties are Strings).
The code I have so far is
HashSet<Object> uniqueStackTraces =new HashSet<>();
logEntryObjectsToCheckForDupes.removeIf(c -> !uniqueStackTraces.add(Arrays.asList(c.getTypeOfexception(), c.getStackTrace())));
which I think works (not entirely convinced as I go from 887 exceptions to only 14). Is there some method/logic to find the index of each unique entry. That way rather than creating a new HashSet I could just store a list of unique indexes and create a List<LogEntry> from logEntries of every object with a unique index?
I'm quite perplexed and not sure my code is actually working as intended so any suggestions/input is much appreciated. The question is similar to (Removing duplicates from the list of objects based on more than one property in java 8)and I used some logic from here.