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

19 unit conversion #20

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

19 unit conversion #20

wants to merge 8 commits into from

Conversation

patrick-austin
Copy link

Adds support for unit conversion, to be used in icat.server and icat.lucene as part of search improvements.

@patrick-austin patrick-austin requested a review from VKTB September 13, 2022 14:26
@patrick-austin patrick-austin requested a review from VKTB October 21, 2022 15:02
Copy link
Contributor

@ajkyffin ajkyffin left a comment

Choose a reason for hiding this comment

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

The way that IcatUnits works is counter-intuitive. You have a constructor that modifies a static variable and therefore changes the behaviour of all other instances. Either have a separate non-static instance of SimpleUnitFormat for each instance of IcatUnits, or only have static methods and no instances.

It's not clear from the name of either class that the purpose of this is to convert quantities to SI units, so provide a method with a name such as convertToSiUnits(...).

@patrick-austin
Copy link
Author

You have a constructor that modifies a static variable and therefore changes the behaviour of all other instances. Either have a separate non-static instance of SimpleUnitFormat for each instance of IcatUnits, or only have static methods and no instances.

I'm not totally confident on how singletons work, but since we're calling SimpleUnitFormat.getInstance() won't this be shared across all instances of IcatUnits even if we didn't declare it as static? Or would we also want to change this to SimpleUnitFormat.getNewInstance()? I suppose with e.g. the EntityInfoHandler change we want to remove uses of singletons in our codebase? Happy to go with whatever's most consistent with our design patterns elsewhere - just not 100% sure what they are...

In terms of making everything static, since we're passing configuration settings in icat.server/icat.lucene I don't see a way the "converter" could be made properly static other than maybe doing SimpleUnitFormat.getNewInstance() and passing the alias settings everytime we do a conversion, but that would be needless repitition.

It's not clear from the name of either class that the purpose of this is to convert quantities to SI units, so provide a method with a name such as convertToSiUnits(...).

Yeah looking at it I think I was trying to persist the terminology of the underlying library (i.e. SystemUnit) but probably better to be explicit that "System" is short for Système international and that the main class is for conversion.

@ajkyffin
Copy link
Contributor

As you say, since this needs runtime configuration of aliases, it would be best to have it be non-static and use SimpleUnitFormat.getNewInstance().

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.

3 participants