-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guarantee initial order for decorators to sort #1154
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compareTo seems awkward so it either needs to change or some comments explaining why.
The TreeSet part is also not clear to me.
@@ -32,7 +33,8 @@ private TopologicalSort() { | |||
*/ | |||
public static List<Decorator> sortDecorators(Collection<Decorator> items) { | |||
Collection<Node> nodes = adaptToNodes(items); | |||
return sortNodes(nodes); | |||
// Order the nodes by the decorator class to guarantee the initial order. | |||
return sortNodes(new TreeSet<>(nodes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me what you mean by initial order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to get a determinist order if we always get the same input. For example, if our input is a set of three decorators with no dependencies on each other, the final result order of these three decorators might vary in different executions.
The idea I had to address this situation is to introduce an initial order based on the decorator class name instead of the decorator order insertion. Therefore, and following the above example, the three decorators will be ordered by the decorator name and hence the final result order will now always be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to get a determinist order if we always get the same input. For example, if our input is a set of three decorators with no dependencies on each other, the final result order of these three decorators might vary in different executions.
The order of decorators should not be important to us as long as they are topologically sorted. Even if it's possible the get different results that both satisfy the constraints, the end result (the generated json/yaml files) should be deterministic. If the end result is not deterministic, then we probably have not properly expressed those constraints and we should focus on that.
TDLR: I don't mind having the decorators in a predictable order however, we shouldn't have to, are we sure we are dealing with the issue at the right level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as long as we fix the toString thingy.
Plus, add some test coverage with basic scenarios.
Kudos, SonarCloud Quality Gate passed! |
Plus, add some test coverage with basic scenarios.