-
Notifications
You must be signed in to change notification settings - Fork 3
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
Collection util rework #53
Conversation
How about defining ascending/descending via a bool? This way, no JavaFx class would be used in this model class. Or can there be other sort orders, hypothetically? |
The enum values (or their text representations) should then also be used in the GUI classes that define the cell value properties, right? Are these displayed and hence language-specific? |
Done
No, they are not |
Thank you, looks much better now!
And the TableColumn.SortType enum appears to only have the two values ascending and descending anyway. |
Unfortunately I overlooked that. |
It wouldn't be that complicated, would it? I'd name the boolean parameter "ascending" and the method call would be like "tmpSortType.equals(ASCENDING)". If false, the used order is descending. Am I missing something? |
If it makes you happy |
It does 🤗 |
@@ -48,78 +48,69 @@ private CollectionUtil() { | |||
//</editor-fold> | |||
// | |||
//<editor-fold desc="public static methods" defaultstate="collapsed"> | |||
//TODO: check parameters, change params to enum values (and bools?), throw exceptions! | |||
/** | |||
* Sorts given list by property and sort type. | |||
* | |||
* @param aList List | |||
* @param aProperty String |
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.
more detailed doc needed
*/ | ||
public static void sortGivenFragmentListByPropertyAndSortType(List<? extends MoleculeDataModel> aList, String aProperty, String aSortType) { | ||
Collections.sort(aList, (m1, m2) -> { | ||
public static void sortGivenFragmentListByPropertyAndSortType(List<? extends MoleculeDataModel> aList, String aProperty, boolean ascending) { |
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.
I have a problem with the parameter type. It must be objects extending MoleculeDataModel but except for the name and the unique SMILES, most of the sorting properties refer to FragmentDataModel. The given objects in the list are just implicitly cast to FragmentDataModel without any checks. Should we throw exceptions here if e.g. someone tries to sort MoleculeDataModels (or any other future class extending it) by some frequency, for example?
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 could be surrounded by a try-catch-block to catch the ClassCastExcpetion but what should happen then?
The class could be checked before parsing and if it does not match 0 can be returned to not sort the list.
What do you expect here?
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.
Returning 0 in that case would be fine, I guess. Consistent with the issue below.
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.
Or throw IllegalArgumentException since you also do that below if the property cannot be parsed into an enum constant?
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.
Then I will throw an IllegalArgumentExcpetion because returning 0 could be confusing.
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.
Alright, thank you 👍
if (ascending) | ||
return f1.getParentMoleculeName().compareTo(f2.getParentMoleculeName()); | ||
else | ||
return f2.getParentMoleculeName().compareTo(f1.getParentMoleculeName()); |
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.
add default case or throw exception if the given sort type is not known? I can see that you return 0 in this case currently but does it make sense?
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.
If Property or SortType (which should no longer be possible) are not known, 0 is returned to the sort method, which means that no sorting should be performed. Therefore this is fine.
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.
I didn't know about this convention of returning 0 when sorting is not possible. Ok then, leave it this way, but please define it in the doc.
* @param aProperty String | ||
* @param aSortType String | ||
* @param aList List of Molecule-/FragmentDataModel objects to be sorted. | ||
* @param aProperty String property of Molecule-/FragmentDataModel by which to sort the list. |
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.
Define that the given string must correspond to the text property of a DataModelPropertiesForTableView enum constant.
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 does not have to, only if, the list is sorted
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.
You are throwing an IllegalArgumentException if it does not, or am I getting this wrong?
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.
You are right, but this is described in the @throw tag
* @param aList List of Molecule-/FragmentDataModel objects to be sorted. | ||
* @param aProperty String property of Molecule-/FragmentDataModel by which to sort the list. Property must be part | ||
* of {@link SimpleEnumConstantNameProperty}. If the property is part of | ||
* {@link SimpleEnumConstantNameProperty} but not handled in this method the list will not be sorted. |
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.
I think you mean DataModelPropertiesForTableView, not SimpleEnumConstantNameProperty, right?
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.
definitely, meetig-work :)
Quality Gate passedIssues Measures |
Do you want to merge this or should I? |
No description provided.