ANDROID-16874 New comparator where order is not important#14
ANDROID-16874 New comparator where order is not important#14nimeacuerdo merged 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new log comparator that compares lists without considering order, addressing Android ticket ANDROID-16874. The implementation provides an alternative to the existing DefaultLogComparator for scenarios where log entry sequence is not important.
- Adds AnyOrderLogComparator class that compares log lists ignoring order
- Implements difference detection to identify missing and extra entries
- Provides detailed error messages showing which entries are missing or extra
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
|
|
||
| private fun findDifference(first: List<LogType>, second: List<LogType>): List<LogType> { | ||
| return first.toMutableList().apply { removeAll(second) } |
There was a problem hiding this comment.
The current implementation has O(n²) complexity due to removeAll() operation. For better performance with large lists, consider using a frequency-based approach or converting to sets if duplicates should be ignored.
| return first.toMutableList().apply { removeAll(second) } | |
| val freqMap = mutableMapOf<LogType, Int>() | |
| for (item in first) { | |
| freqMap[item] = freqMap.getOrDefault(item, 0) + 1 | |
| } | |
| for (item in second) { | |
| val count = freqMap[item] | |
| if (count != null && count > 0) { | |
| freqMap[item] = count - 1 | |
| } | |
| } | |
| val result = mutableListOf<LogType>() | |
| for ((item, count) in freqMap) { | |
| repeat(count) { | |
| result.add(item) | |
| } | |
| } | |
| return result |
There was a problem hiding this comment.
new set-based approach pushed
| } No newline at end of file | ||
| } | ||
|
|
||
| @Suppress("unused") |
We will -> https://github.com/Telefonica/android-messenger/pull/3150 |
🎟️ Jira ticket
ANDROID-16874
🥅 What's the goal?
Provide a new comparator where order does not matter
🚧 How do we do it?
Just provide a new public comparator
📘 Documentation changes?
🧪 How can I test this?