Skip to content
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

Merged
merged 12 commits into from
Mar 8, 2024
Merged

Collection util rework #53

merged 12 commits into from
Mar 8, 2024

Conversation

FelixBaensch
Copy link
Owner

No description provided.

@JonasSchaub
Copy link
Collaborator

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?

@JonasSchaub
Copy link
Collaborator

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?

@FelixBaensch
Copy link
Owner Author

FelixBaensch commented Mar 7, 2024

The enum values (or their text representations) should then also be used in the GUI classes that define the cell value properties, right?

Done

Are these displayed and hence language-specific?

No, they are not

@JonasSchaub
Copy link
Collaborator

Thank you, looks much better now!
I'm just still hung up on this:

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?

And the TableColumn.SortType enum appears to only have the two values ascending and descending anyway.

@FelixBaensch
Copy link
Owner Author

FelixBaensch commented Mar 7, 2024

Thank you, looks much better now! I'm just still hung up on this:

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?

And the TableColumn.SortType enum appears to only have the two values ascending and descending anyway.

Unfortunately I overlooked that.
That would require a method to parse the TableColumn.SortType into a Boolean. I would rather argue in favor of moving the CollectionUtils to a controller package if you want to avoid the fx class in the model area.

@JonasSchaub
Copy link
Collaborator

That would require a method to parse the TableColumn.SortType into a Boolean.

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?

@FelixBaensch
Copy link
Owner Author

If it makes you happy

@JonasSchaub
Copy link
Collaborator

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
Copy link
Collaborator

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) {
Copy link
Collaborator

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?

Copy link
Owner Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Owner Author

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.

Copy link
Collaborator

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());
Copy link
Collaborator

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?

Copy link
Owner Author

@FelixBaensch FelixBaensch Mar 7, 2024

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.

Copy link
Collaborator

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.
Copy link
Collaborator

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.

Copy link
Owner Author

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

Copy link
Collaborator

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?

Copy link
Owner Author

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.
Copy link
Collaborator

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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely, meetig-work :)

Copy link

sonarqubecloud bot commented Mar 8, 2024

Quality Gate Passed Quality Gate passed

Issues
2 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@JonasSchaub
Copy link
Collaborator

Do you want to merge this or should I?

@FelixBaensch FelixBaensch merged commit 8180e29 into production Mar 8, 2024
2 checks passed
@FelixBaensch FelixBaensch deleted the CollectionUtil_rework branch March 8, 2024 18:31
@FelixBaensch FelixBaensch restored the CollectionUtil_rework branch April 2, 2024 09:39
@FelixBaensch FelixBaensch deleted the CollectionUtil_rework branch April 2, 2024 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants